Skip to content

Instantly share code, notes, and snippets.

View alexdiliberto's full-sized avatar

Alex DiLiberto alexdiliberto

View GitHub Profile
@alexdiliberto
alexdiliberto / curry-with-holes.js
Created May 4, 2014 15:57
Extends the previous curry.js to allow syntax with holes eg: fn("a", _, "c")("b")
function toArray(args) {
return [].slice.call(args);
}
function sub_curry(fn /*, variable number of args */) {
var args = [].slice.call(arguments, 1);
return function () {
return fn.apply(this, args.concat(toArray(arguments)));
};
}
@alexdiliberto
alexdiliberto / dry-css-with-sass.scss
Created May 4, 2014 20:43
DRY CSS output using Sass
/**
Placeholder - Contains all static mixin name value pairs for a particular mixin
*/
%box {
border: 1px solid;
padding: 1em;
margin: 1em;
}
/**
@alexdiliberto
alexdiliberto / jekyll-inline-code-block.rb
Last active August 29, 2015 14:02
Converts some custom Jekyll liquid tags into inline code blocks
# Convert the following liquid tags into output wrapped with <code class="inline-code"> ... </code>
# 1. {% i %} var foo="bar"; {% ei %}
# 2. {% inline %} var foo="bar"; {% endinline %}
module Jekyll
class SyntaxHighlightInlineTag < Liquid::Tag
def render(context)
'<code class="inline-code">'
end
end
@alexdiliberto
alexdiliberto / client-timezone.js
Created June 7, 2014 00:35
Get the user's timezone (client-side)
/**
Intl.DateTimeFormat().resolvedOptions()
Object {locale: "en-US", numberingSystem: "latn", calendar: "gregory", timeZone: "America/New_York", year: "numeric"…}
calendar: "gregory"
day: "numeric"
locale: "en-US"
month: "numeric"
numberingSystem: "latn"
timeZone: "America/New_York"
@alexdiliberto
alexdiliberto / ember-presentation-logic-location.md
Created July 7, 2014 18:47
Where to put your presentation logic for Ember

controller: page-specific

model: if the business object as a canonical representation

helpers, components: generic configurable elements

@alexdiliberto
alexdiliberto / simple-css-negater.js
Last active August 29, 2015 14:03
Simple CSS Negater. Reads input as a rawCSS file. Writes output as a minified and negated CSS file. This is great for quickly negating some third party CSS which you don't have full control over.
/**
Readme
1. Copy & paste the input file into third-party.css as raw CSS
2. $ node css-negator.js
3. When finished, the final copy will be in the file named: negated-output.css
*/
var css = require('css');
var fs = require('fs');
var colors = require('colors');
@alexdiliberto
alexdiliberto / rovarspraket.js
Created July 26, 2014 03:11
rövarspråket
/*
Double every consonant and place an occurrence of "o" in between.
For example, translate("this is fun") should return the string "tothohisos isos fofunon".
translate('this is fun')
=> "tothohisos isos fofunon"
*/
function translate(str) {
var arr = str.split(''),
out = "";
@alexdiliberto
alexdiliberto / copy_git_to_svn.txt
Created September 5, 2014 16:56
Copy existing Git reposity to SVN
//Simply make a temporary directory as a SVN sandbox
mkdir temp; cd temp;
//Checkout the latest Jefferson SVN
svn co <svn-url> .
//Wipe the current directory to a clean slate
svn delete *
//Manually copy all the files to the current SVN directory
@alexdiliberto
alexdiliberto / promise_race_timout.js
Last active August 29, 2015 14:15
How to timeout a long-running promise
/**
Credit: Kyle Simpson
https://github.com/getify/You-Dont-Know-JS/blob/master/async%20&%20performance/ch3.md#never-calling-the-callback
*/
// A utility for timing out a Promise
function timeoutPromise(delay) {
return new Promise( function(resolve,reject) {
setTimeout( function() {
reject( "Timeout!" );
@alexdiliberto
alexdiliberto / select_by_id.js
Created July 16, 2015 03:32
Ember QUnit Test Helper: selectById()
export function selectById(selectId, optionLabel) {
return function() {
const option = findWithAssert(`#${selectId} option:contains('${optionLabel}')`);
fillIn(`#${selectId}`, option.attr('value'));
return find(selectId).focusout();
};
}