Skip to content

Instantly share code, notes, and snippets.

@ammmir
ammmir / modelfactory.js
Created November 27, 2010 09:31
Client model factory (node.js)
// generated user.js
function User() { // @extends Backbone.Model
return Backbone.Model.apply(this, arguments);
}
User.prototype = Backbone.Model.prototype;
User.EMAIL_REGEX = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
User.prototype.validate = function validate() {
var email = this.get('email');
@zdennis
zdennis / initialize.rb
Created July 4, 2012 15:16
coffee-script style constructor for ruby (for automatic instance variable setting)
class Class
def initialize(*vars)
keys = vars.map{ |k| k.to_s.sub(/^@/, '')}
define_method :initialize do |args|
args.each_pair do |k,v|
raise ArgumentError, "Unexpected argument #{k}" unless keys.include?(k.to_s)
instance_variable_set "@#{k}", v
end
end
end
@natew
natew / song.rb
Created September 8, 2012 23:22
Rails model for parsing artist information from a song
class Song
# Regular expressions
RE = {
:featured => /(featuring | ?ft\.? |feat\.? |f\. |w\/){1}/i,
:remixer => / remix| rmx| edit| bootleg| mix| remake| re-work| rework| extended remix| bootleg remix/i,
:mashup_split => / \+ | x | vs\.? /i,
:producer => /^(produced by|prod\.? by |prod\. )/i,
:cover => / cover/i,
:split => /([^,&]+)(& ?([^,&]+)|, ?([^,&]+))*/i, # Splits "one, two & three"
:open => /[\(\[\{]/,
// require our new directive
var resolveSprockets = require(__dirname + '/resolve-sprockets.js');
// set files to the array that we got back
var files = resolveSprockets('spec.js.coffee');
// Here goes the rest as usual
@Neurogami
Neurogami / glitch.rb
Created August 12, 2013 04:56
Simple script to rin perfectly good image files.
#!/usr/bin/env ruby
=begin
Simple script to smack your glitch up.
Call this program with the name of an image file, and two numbers
The first number is used to determine when to mess with a byte in the
image file. If you pass in, say 2000, then even 2000th byte gets tweaked.
@saschagehlich
saschagehlich / i18n.coffee
Created September 14, 2010 00:48
Simple i18n with node.js and express.js
exports.I18n =
en:
title: "Free YouTube video download"
navi:
home: "Home"
howto: "Tutorial"
blog: "Blog"
termsofuse: "Terms of Use"
support: "Support"
imprint: "Imprint"
@eikes
eikes / imgpreload.js
Created October 20, 2012 23:23
JavaScript image preloader with callback
/*
* Copyright (C) 2012 Eike Send
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@nwjsmith
nwjsmith / encode.sh
Created August 10, 2016 20:51
ffmpeg
ffmpeg -i source.mov -c:v libx264 -crf 18 -profile:v high -level 4.0 -pix_fmt yuv420p -preset veryslow -tune animation output.mp4
anonymous
anonymous / gist:1073922
Created July 9, 2011 20:18
donut.c
#include <math.h>
#include <stdio.h>
#include <string.h>
// buffer constraints
#define BUFFER_WIDTH 80
#define BUFFER_HEIGHT 22
#define BUFFER_SIZE (BUFFER_WIDTH*BUFFER_HEIGHT)
#define IMAGE_SCALE 15
@proudlygeek
proudlygeek / client_cors.js
Created July 17, 2012 20:48
JSONP Vs. CORS
// http://jsfiddle.net/suBPQ/
$.ajax({
url: "http://api_test_server.proudlygeek.c9.io/",
success: function(data) {
console.log(data);
}
});​