Skip to content

Instantly share code, notes, and snippets.

View yocontra's full-sized avatar

contra yocontra

View GitHub Profile
@yocontra
yocontra / example.js
Last active December 12, 2015 12:39
Backbone layout manager
FooterV = SomeViewInstance;
MainV = SomeViewInstace;
MyLayout = Backbone.Layout.extend({
template: function(){
// this can be any js function that returns html or a jquery el
return "<div id='sidebar'/><div id='main'/><div id='footer'/>";
},
// Define friendly names for regions
rivets.configure({
adapter: {
subscribe: function(obj, keypath, callback) {
if (obj instanceof Backbone.Collection) {
obj.on('add remove reset', function () {
callback(obj[keypath])
});
} else {
obj.on('change:' + keypath, function (m, v) { callback(v) });
};
@yocontra
yocontra / prox
Last active December 10, 2015 19:08
prox
sudo sh -c 'echo "proxyserver=\"chisproxy.amers.ibechtel.com\"
proxyport=\"8080\"
git config --global url.https://github.com/.insteadOf git://github.com/
function proxy(){
echo -n \"Bechtel Username: \"
read -e username
echo -n \"Bechtel Password: \"
read -es password
export http_proxy=\"http://\$username:\$password@\$proxyserver:\$proxyport\"
@yocontra
yocontra / pdf2htmlEX.rb
Created October 9, 2012 17:37
homebrew install for master
require 'formula'
class Pdf2htmlex < Formula
homepage 'http://coolwanglu.github.com/pdf2htmlEX/'
url 'https://github.com/coolwanglu/pdf2htmlEX/tarball/master'
version '0.3.2'
head 'https://github.com/coolwanglu/pdf2htmlEX.git'
depends_on 'cmake' => :build
depends_on 'fontforge'
require 'formula'
class Pdf2htmlex < Formula
homepage 'http://coolwanglu.github.com/pdf2htmlEX/'
url 'https://github.com/coolwanglu/pdf2htmlEX/tarball/master'
head 'https://github.com/coolwanglu/pdf2htmlEX.git'
depends_on 'cmake' => :build
depends_on 'fontforge'
# compile
rm -rf dist
mkdir dist
coffee -o dist -c lib/main.coffee lib/defaultClient.coffee lib/Client.coffee lib/Socket.coffee lib/util.coffee
# build
node_modules/.bin/browserbuild -m main -b dist/ node_modules/engine.io-client/lib dist > protosock.js
# minify
node_modules/.bin/uglifyjs -nc --unsafe -mt -o protosock.min.js protosock.js
@yocontra
yocontra / dstm.coffee
Created August 7, 2012 02:39
DSTM via warlock demo
###
Network workflow:
Client connects
Client creates transaction
Server sends 'sync' with root object
Client runs transaction
if .retry() called
Client listens for 'sync' message then runs transaction again
else
@yocontra
yocontra / ex.coffee
Created July 14, 2012 06:49
example code
server = new Pulsar port: 4001
schan = channel 'notify:operators'
schan.on 'newClient', ->
schan.emit 'updateUnanswered', 5
client = new Pulsar.Client port: 4001
cchan = client.channel 'notify:operators'
cchan.on 'updateUnanswered', (num) -> console.log 'unanswered:', num
@yocontra
yocontra / detectanimation.coffee
Created June 28, 2012 20:17 — forked from lakenen/detectanimation.js
JavaScript animated GIF detection!
isAnimatedGif = (src, cb) ->
request = new XMLHttpRequest()
request.open "GET", src, true
request.responseType = "arraybuffer"
request.addEventListener "load", ->
arr = new Uint8Array request.response
return cb false if arr[0..3] isnt [0x47,0x49,0x46,0x38]
request.send()
require 'should'
http = require 'http'
Vein = require 'vein'
port = Math.floor(Math.random() * 1000) + 8000
server = new Vein http.createServer().listen port
describe 'first test', (done)->
it 'should do stuff', (done)->
server.drop()
server.stack = []