Skip to content

Instantly share code, notes, and snippets.

@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) {
@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 / 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 / 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 / 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 / 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) {