Skip to content

Instantly share code, notes, and snippets.

@andrejewski
andrejewski / controllerSample.js
Created March 27, 2013 01:31
Master and Slave style module handing in large Node.js applications. Depends on Underscore for its extends method, otherwise you can simply paste in your own independent extend code.
// controllerSample.js
module.exports = function($) {
return require('../slave.js')($, function($) {
/* If you need to add mixins or properties to the objects
that are given from master.js, you need to declare those
inside of this function. Otherwise, they will not work. */
_.mixin({
compactObject: function(to_clean) {
$._.map(to_clean, function(value, key, to_clean) {
@andrejewski
andrejewski / socket.coffee
Created July 17, 2013 03:13
Socket.io router extension. A little customization to help with combining Express/Connect and Socket.io. In both CoffeeScript and JavaScript, for your preference.
# socket.coffee
module.exports = (soc) ->
debug = true
# router
soc.routes = []
soc.mount = (action, next = ->) ->
soc.routes.push [action, next]
@andrejewski
andrejewski / seth-compare.js
Last active August 29, 2015 14:03
a collection of Seth.js examples
/*
This gist aims to demonstrate how sets can
be compared in Seth.
All set-to-set comparison methods begin with
`is` such as `#isSuperset()`. And these methods
return a Proof class instance with useful
assertion methods.
Comparisons must be proved through assertions
@andrejewski
andrejewski / emf-actor-generate-actions.js
Created December 20, 2014 16:11
Extended EMF Actor class with generateActions()
/*
Example: Extended EMF Actor Class
This is not in the core package because
(1) it is trivial to implement and everyone should
be using their own base classes, and
(2) it sets a couple bad presidences mainly that
(a) methods and actions are 1:1 and
(b) calls to Actor should only have one arg, and
(3) makes debugging and type-checking tough as functions
are created at runtime.
@andrejewski
andrejewski / happy-day.js
Last active February 4, 2016 20:03
Display "Happy {day of week}!" in any .x-happy-day tag
(function() {
var days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
@andrejewski
andrejewski / jquery-set-class.js
Created July 2, 2016 21:26
more functional jQuery
$.fn.extend({
setClass: function(name, add) {
if(typeof name === 'object') {
const classes = name;
Object.keys(classes).forEach(className => {
this.setClass(className, classes[className]);
});
} else {
this.each((index, elem) => {
if(add) {
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
# DeCoffeeScript script
if [[ -z "$1" ]] ; then
echo 'decaf error: pass a basename'
exit 1
fi
coffee_file=$1.coffee
js_file=$1.js
@andrejewski
andrejewski / defer.js
Created November 19, 2016 15:32
My quick deferred utility I seem to use everywhere
/*
Defer.js
Usage:
const myDefer = new Defer()
myDefer.then(x => assert.equal(x, 1))
myDefer.resolve(1)
*/
export default class Defer {
@andrejewski
andrejewski / himalaya-strip-whitespace.js
Last active October 27, 2018 08:53
Strip whitespace from Himalaya output
function removeEmptyNodes (nodes) {
return nodes.filter(node => {
if (node.type === 'element') {
node.children = removeEmptyNodes(node.children);
return true
}
return node.content.length
})
}