Skip to content

Instantly share code, notes, and snippets.

@ariellephan
ariellephan / udacityframeworks.js
Created November 17, 2016 02:33
Udacity frameworks course notes
var numLetters = function(letter) {
return new Function("num", "return ('" + letter + "').repeat(num)");
}
@ariellephan
ariellephan / curry.js
Created November 4, 2016 01:22
Currying - functional js
var curryIt = function(uncurried) {
var parameters = Array.prototype.slice.call(arguments, 1);
return function() {
return uncurried.apply(this, parameters.concat(
Array.prototype.slice.call(arguments, 0)
));
};
};
@ariellephan
ariellephan / regex.js
Last active October 20, 2016 19:53
Useful js regex
//Search for a function
let r = /\((.*)\).*\{([\s\S]*)\}/m
function sayHello(msg) {
console.log(msg);
}
r.exec(sayHello.toString());
@ariellephan
ariellephan / scssbestpractice.scss
Last active September 28, 2016 18:06
SCSS best practice
%button {
// … button styles
+ %button {
margin-left: 1rem;
}
}
%modal {
// … modal styles
@ariellephan
ariellephan / gist:ecd42fd32e50a610b4da2db1c9d615ef
Last active September 13, 2016 00:07
jQuery best practice. patterns/anti patterns
//bad
$("#agree").bind("change", function() {
if ($("input[type=submit]").hasClass("disabled")) {
$("input[type=submit]").removeClass("disabled");
} else {
$("input[type=submit]").addClass("disabled");
}
});
//good
@ariellephan
ariellephan / ycombinator.js
Last active August 17, 2016 19:37
Y Combinator in js
// Credits: http://matt.might.net/articles/implementation-of-recursive-fixed-point-y-combinator-in-javascript-for-memoization/
// Ymem takes a functional and an (optional)
// cache of answers.
// It returns the fixed point of the functional
// that caches intermediate results.
function Ymem(F, cache) {
if (!cache)
cache = {} ; // Create a new cache.
@ariellephan
ariellephan / gist:0e869e20279c256928d73181ca5d71a7
Last active August 16, 2016 23:38
Front End Best Practices
1. Write semantic and accessible HTML5
Goals:
+ Avoid div soup/code bloat
+ Accessibiity
+ Improve SEO
a/ Semantic aka has meaning
http://html5doctor.com/downloads/h5d-sectioning-flowchart.pdf
b/ Content models:
https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#kinds-of-content
@ariellephan
ariellephan / gist:a1742faecc9fc47c86bced21d0b759d1
Created June 23, 2016 19:12
jsDoc improvement suggestions
1. search
2. auto list file/url that references current function/class/namespace
3. framework specific tags like Angular directive, controller, module
4. nested functions
1. When there's unreleased feature on active branch A and its not on trunk.
-> Bring the feature to trunk and comment out on branch A so future merge won't bring the feature on branch A to trunk.
@ariellephan
ariellephan / Swich tab in Sublime
Created August 3, 2013 05:18
switch tab in sublime
[
{ "keys": ["ctrl+pagedown"], "command": "prev_view" },
{ "keys": ["ctrl+pageup"], "command": "next_view" }
]