import { SecurityContext } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; private sanitizer: DomSanitizer; downloadCSV() { let blob = new Blob([yourdata], { type: 'text/csv' }); let urlPath = this.sanitizer.sanitize(SecurityContext.URL, this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob))); let tempLink = document.createElement('a'); tempLink.href = urlPath; tempLink.setAttribute('download', 'download.csv'); tempLink.click(); }
UI
How To Find Valid Email Address in JavaScript Regex
How To Find Validate Email Address format in JavaScript Regex:
const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; let email = "m.e@my.email"; alert( EMAIL_REGEX.test(email));
How to Enable Preflight CORS in PHP for Angular HTTP requests
When testing Ionic or Angular app you might need to set CORS policy to access a service on a different domain. One way to do this in PHP for testing is to send OK responses for all OPTIONS requests. (If you are testing POST and GET requests)
In your php file set:
// change to your app origin header('Access-Control-Allow-Origin: http://localhost:8100'); header ("Access-Control-Expose-Headers: Content-Length, X-JSON"); header ("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS"); header ("Access-Control-Allow-Headers: Content-Type, Authorization, Accept, Accept-Language, X-Authorization"); header('Access-Control-Max-Age: 86400'); if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { // The request is using the POST method header("HTTP/1.1 200 OK"); return; }
Don’t ship this test code, this is just for your internal testing of http requests.
JS Infinite Alert Prank Code gets Japanese Girl in Serious Trouble
Explaining her actions, the girl said that she’d run into such pranks herself and thought it would be funny if someone clicked the link.
The Twitter user referenced in the message, 0_Infinity_, has a protected account, but the user left a message in their bio field suggesting that they don’t understand why there’s so much fuss about the script today, as it was written in 2014.
To protest the actions of the Japanese police and the absurdity of calling this act a crime, Tokyo developer Kimikazu Kato has published on GitHub a project called Let’s Get Arrested. Forking the project and then creating a branch named gh-pages will create a simple GitHub-hosted website that contains nothing but the infinitely looped alert, putting criminality at our fingertips.
for ( ; ; ) { window.alert(" ∧_∧ ババババ\n( ・ω・)=つ≡つ\n(っ ≡つ=つ\n`/ )\n(ノΠU\n何回閉じても無駄ですよ~ww\nm9(^Д^)プギャー!!\n byソル (@0_Infinity_)") }
Calling her a criminal is totally absurd.
Samsung Galaxy Foldable Smartphone Review
New York Magazine, Intelligencer:
It’s not just a matter of how smoothly the physical hinges work as the phone unfurls into tablet mode, but whether the underlying software is equally smooth. If I’m writing an email and want to expand out my workspace so I can drop in a link, how well does a folding phone handle that task? Smartphone UX still orbits entirely around the assumption that I, the user, focus on only one app at a time; there have been many attempts by various phone makers to make it easier to work in a split-screen mode, but none that I’ve tried that are satisfying to use.
Another make-or-break for folding phones: glass. As detailed by Brian Barrett in Wired, the folks at Corning, who supply the Gorilla Glass found in iPhones and a huge number of other smartphones, are working on creating scratch-resistant glass tensile enough to be used in a folding phone.
But there are two reasons why virtually every non-bendy smartphone on the market uses glass: it withstands scratches much better than plastic, and glass feels much better to the touch than plastic.
In 2017, Motorola tried to attack one of the biggest pain points for smartphone users with its Moto Z2 Force, featuring a “shatterproof” plastic screen. The phone was a dud — it picked up scratches remarkably fast, looked cloudy even before it got scratched up, and just felt cheap to the touch.
Seems more gimmicky than useful. With larger screens there is more battery consumption, which is not what anyone wants. What would be more useful is a way to use your phone as a desktop by plugging in a keyboard and monitor at your desk. Something like using your iPhone as an iMac at home.
How To Open $ionicPopover Popup from Controller
How To Open $ionicPopover from Controller programmatically without a mouse click event:
var self = this; // store reference to 'this' controller object this.openCustomPopover = function ($event) { $event = document.getElementsById('myElementID'); // html element ID $ionicPopover.fromTemplateUrl('popovers/myhtmlpopover.html', { scope: $scope }).then(function (popover) { console.log('in the popover then function'); self.popover = popover; self.popover.show($event); }); }
You can call this function from your controller without a true click event, by faking the $event object.
How to Display and Format Code Snippets on WordPress
How to Display and Format Code Snippets on WordPress ?
What I use is Pretty print, and it’s very simple to setup.
1. Include this script in your header run_prettify.js
2. Start your code with the pre tag
<pre class="prettyprint"> class Voila { public: // Voila static const string VOILA = "Voila"; // will not interfere with embedded tags. } </pre>
More information at https://github.com/google/code-prettify
How to Dynamically Load Dark Mode CSS with JavaScript
How to Dynamically Load Dark Mode CSS in your Website or WebApp (Ionic, React, or Angular):
1. Create the two separete css files, one for dark colors and one for bright
2. Upload those to your server to css folder
3. Use the script example below to load the appropriate css file based on the hours in the day.
function loadcssfile(filename, filetype){ if (filetype=="css"){ //check filename is an external CSS file var fileref=document.createElement("link"); fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", filename); } if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref); } var date = new Date(); if (date.getHours() >= 19 || date.getHours() <= 7) // after 7pm before 7am loadcssfile("../css/darkmode.css", "css"); else loadcssfile("../css/lightmode.css", "css");
Don't blind your readers at night -_-
If you want to incorporate sunset and sunrise you can look into Suncal library, but you will have to request user's location which is always rude and not recommended.