Skip to content

Instantly share code, notes, and snippets.

@Convicted202
Convicted202 / gist:97df7103db6c6384a0c6
Last active August 29, 2015 14:10
Common usage of animation with callback called constantly
function animLoop( render, element ) {
var running, lastFrame = +new Date;
function loop( now ) {
// stop the loop if render returned false
if ( running !== false ) {
requestAnimationFrame( loop, element );
var deltaT = now - lastFrame;
// do not render frame when deltaT is too high
if ( deltaT < 160 ) {
running = render( deltaT );
@Convicted202
Convicted202 / gist:a2cafa2f6b7f7819feec
Created November 28, 2014 16:09
windows store links to review
http://msdn.microsoft.com/en-us/library/windows/apps/hh696636.aspx
@Convicted202
Convicted202 / Attaching localization
Last active August 29, 2015 14:10
Usefull files for MCSD
<h2><span data-win-res="{textContent: 'greeting'}"></span></h2>
and resource file with .resjson extension within strings folder:
eng
{
"greeting" : "Hello",
"_greeting.comment" : "A welcome greeting"
}
@Convicted202
Convicted202 / main.js
Created July 19, 2016 14:12 — forked from husa/xml2react.js
XML to React Component
const xml = `
<XMLText class="yeah-attributes">
regular text
<XMLBold>
bold text
</XMLBold>
another text
</XMLText>
`;
@Convicted202
Convicted202 / 0_reuse_code.js
Created July 28, 2016 12:51
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
@Convicted202
Convicted202 / function-web-worker.js
Created March 15, 2017 12:27 — forked from westonruter/function-web-worker.js
Spawning a web worker from a function object (bypassing need for separate JS file)
function fibonacci(){ /*...*/ }
var worker = new Worker(
"data:application/javascript;base64,"+
btoa('(' + fibonacci.toString().replace(/function\s+\w+/, 'function') + ')();')
);
// More: https://plus.google.com/113853198722136596993/posts/hAtcYGc5xcw
@Convicted202
Convicted202 / ImgDataPoly.js
Last active October 16, 2020 07:37
ImageData Polyfill IE11
(() => {
try {
new window.ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
} catch (e) {
function ImageDataPolyfill () {
let args = [...arguments], data;
if (args.length < 2) {
throw new TypeError(`
Failed to construct 'ImageData': 2 arguments required, but only ${args.length} present.
@Convicted202
Convicted202 / crypto-pbkdf2-example.js
Created April 23, 2017 20:58 — forked from skeggse/crypto-pbkdf2-example.js
Example of using crypto.pbkdf2 to hash and verify passwords asynchronously, while storing the hash and salt in a single combined buffer along with the original hash settings
var crypto = require('crypto');
// larger numbers mean better security, less
var config = {
// size of the generated hash
hashBytes: 32,
// larger salt means hashed passwords are more resistant to rainbow table, but
// you get diminishing returns pretty fast
saltBytes: 16,
// more iterations means an attacker has to take longer to brute force an
@Convicted202
Convicted202 / promise-retry.js
Created February 8, 2018 11:50
Promises retry maxTries
function waitFor (time, promiseFn = () => {}) {
const wait = new Promise(resolve => {
setTimeout(resolve, time);
});
return Promise.all([promiseFn, wait]).then(
args => args[0] && typeof args[0] === 'function' && args[0](),
() => Promise.reject('Error in waitFor')
);
}
@Convicted202
Convicted202 / conv.sh
Created March 24, 2018 09:29 — forked from blairanderson/conv.sh
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
#! /bin/bash
# The Purpose of this Script is to batch convert and compress any video file to mp4 format
#
# WARNING: LOSSY COMPRESSION !!!
# Variable used:
# sourcedir is the directory where to be converted videos are. Converted video will be saved in the same folder
# usage: