Skip to content

Instantly share code, notes, and snippets.

View amsul's full-sized avatar

amsul

View GitHub Profile
{
"arrowParens": "avoid",
"printWidth": 80,
"semi": false,
"singleQuote": true,
"trailingComma": "all"
}
@amsul
amsul / stringToBuffer.js
Created March 14, 2019 02:51
Convert a string to an array buffer with JavaScript
// Modified from https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder#Polyfill
function stringToBuffer(str) {
'use strict'
let Len = str.length,
resPos = -1
// The Uint8Array's length must be at least 3x the length of the string because an invalid UTF-16
// takes up the equivalent space of 3 UTF-8 characters to encode it properly.
let resArr = new Uint8Array(Len * 3)
for (let point = 0, nextcode = 0, i = 0; i !== Len; ) {
@amsul
amsul / gist:c73cadf4b2d4b2a047f3b1a0bc15b994
Last active June 1, 2018 03:35
Convert MOV files to MP4 using ffmpeg
# Simple
ffmpeg -i MY_FILE.mov -c copy NEW_FILE.mp4
# Compressed
ffmpeg -i MY_FILE.mov -c copy -crf 20 NEW_FILE.mp4
# Compressed (alternative)
ffmpeg -i MY_FILE.mp4 -acodec mp2 NEW_FILE.mp4
# Compressed (alternative with audio)
@amsul
amsul / gist:a5f5dc8f3ce80e160ed51741c41b91f9
Created February 13, 2018 02:21
Delete remote git tag
git tag --delete TAG_NAME
git push origin :refs/tags/TAG_NAME
@amsul
amsul / searchUtil.js
Last active November 7, 2019 19:26
A stupidly simple fuzzy search
// @flow
import * as _ from 'lodash'
///////////////////
// FILTER & SORT //
///////////////////
type FilterAndSortType = ({
data: Array<*>,
@amsul
amsul / picker.inline.css
Created October 21, 2014 16:04
A snippet to convert the "classic" picker to be an always-open, inline picker
.picker__holder,
.picker--opened .picker__holder {
max-height: 25em;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
-moz-opacity: 1;
opacity: 1;
border-top-width: 1px;
border-bottom-width: 1px;
-webkit-transform: translateY(0) perspective(600px) rotateX(0);
@amsul
amsul / ember.handlebars.pluralize.js
Last active December 18, 2015 16:39
Add the {{pluralize}} helper in Ember Handlebars templates.
// Register the pluralize helper.
Ember.Handlebars.registerBoundHelper( 'pluralize', function( number, options ) {
var phraseMatch = ( options.hash.phrase || '{|s}' ).match( /(.*?)\{(.*?)\|(.*?)\}/ )
Ember.assert( 'The optional "phrase" hash for {{pluralize}} should be formatted as <phrase to pluralize>{<singular ending>|<plural ending>}', phraseMatch )
var word = phraseMatch[ 1 ],
singular = word + phraseMatch[ 2 ],
plural = word + phraseMatch[ 3 ]
return number == 1 ? singular : plural
})
@amsul
amsul / rAF-polyfill
Created September 24, 2012 15:35
requestAnimationFrame polyfill
/*
* requestAnimationFrame polyfill
*/
(function() {
var
lastTime = 0,
vendors = ['ms', 'moz', 'webkit', 'o']
for ( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x ) {
@amsul
amsul / gist:3726529
Created September 15, 2012 06:06
Basic JS animation method
/**
* Taken from: http://codepen.io/hakimel/pen/hGwmg
*
* Animates the given set of properties on the specified
* element. Properties should include units where possible,
* px will not be added automatically. For example:
*
* animate( document.querySelector( 'body' ), {
* width: '200px'
* }, {
@amsul
amsul / requestAnimationFrame
Created September 10, 2012 15:57
Cross-browser requestAnimationFrame support
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();