Skip to content

Instantly share code, notes, and snippets.

// http://www.2ality.com/2013/09/javascript-unicode.html
function toUTF16(codePoint) {
var TEN_BITS = parseInt('1111111111', 2);
function u(codeUnit) {
return '\\u'+codeUnit.toString(16).toUpperCase();
}
if (codePoint <= 0xFFFF) {
return u(codePoint);
}
@namklabs
namklabs / console-to-alert.js
Created August 22, 2020 23:06
replace console warn/error with alert for devices where console is not easily accessible
console.oldwarn = console.warn;
console.warn = (...args) => {
alert([...args].join(' '));
console.oldwarn.call(null,...args);
}
console.olderror = console.error;
console.error = (...args) => {
alert([...args].join(' '));
console.olderror.call(null,...args);
}
@namklabs
namklabs / trello-night-mode.css
Last active October 13, 2019 17:08
Trello Night Mode
#trello-root { background: #000!important; }
.list {background-color: #333; }
.list textarea { color: #999; }
.list .list-card { background-color: #444; }
.list .list-card span {color: #000; }
.list .list-card .card-label { opacity: 0.25; }
.window { background-color: #333; }
.window span, .window h3, .window textarea, .window a { color: #999; }
.window .action-comment { background-color: #444; }
@namklabs
namklabs / load-googlefonts-before-phaser.html
Last active May 21, 2018 19:53
Load Google Fonts before Phaser
<head>
...
<link href="https://fonts.googleapis.com/css?family=VT323" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
<script>
WebFont.load( {
custom: {
families: [ 'VT323' ]
@namklabs
namklabs / observeDOM.js
Created February 21, 2018 16:59
observeDOM.js
// https://stackoverflow.com/a/14570614/448640
var observeDOM = (function(){
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
eventListenerSupported = window.addEventListener;
return function(obj, callback){
if( MutationObserver ){
// define a new observer
var obs = new MutationObserver(function(mutations, observer){
/*
By Osvaldas Valutis, www.osvaldas.info
https://osvaldas.info/image-lightbox-responsive-touch-friendly
Available for use under the MIT License
*/
;( function( $, window, document, undefined )
{
'use strict';
@namklabs
namklabs / 0_reuse_code.js
Created October 24, 2016 16:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@namklabs
namklabs / lorem-ipsum.sh
Last active October 31, 2018 19:22
bash lorem ipsum osx terminal
function lorem(){
# Copy lorem ipsum to your clipboard in OS X
# usage:
# $ lorem <int> <htmlflag>
# where <int> is how many paragraphs of lorem ipsum you want, each separated by 2 newlines
# and <htmlflag> is anything, indicating you want each paragraph surrounded by <p></p>. Omit if you don't want this.
@namklabs
namklabs / batchDownload.js
Last active July 28, 2016 21:27
This function will download all of the files on a page. Use in dev console. Just tweak the selector to filter what types of links will be downloaded. Eliminates duplicate downloads. Requires jQuery. http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
// requires jQuery
// tested only in Chrome console dev tools
// use jQuerify bookmarklet if your page doesn't have jQuery: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
function batchDownload( $jquery_collection_of_a_elements, buffer_ms, random_ms, timeonly_bool ){
if( $jquery_collection_of_a_elements.length < 1 ){
throw "Nothing to download! Empty jQuery collection.";
}
@namklabs
namklabs / rotateArrayRight.js
Created April 26, 2016 04:23
rotate a 2D (2 dimensional) array clockwise (right) by 90 degrees in JavaScript
function rotateArrayRight( arr ){
// rotates a 2D array 90 degrees to the right (clockwise)
var newarr = [];
for( var x = 0; x < arr[0].length; x++ ){
newarr[x] = [];
for( var y = arr.length - 1; y >= 0; y-- ){
newarr[x].push( arr[y][x] );
}