Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@timruffles
timruffles / ideal-docs.js
Last active August 29, 2015 14:06
ideal javascript documentation
/* somethingJson :: { id : String, name : String || null } */
function something(opts /* { params: {}, method: String, json: somethingJson || true } */,
cb /* (err : String) => null */) {
}
@timruffles
timruffles / git-data
Created September 8, 2014 09:17
quick tour of git data
# contents of a branch file
ƒ cat .git/refs/heads/dev
22f3d040b11ba75dcfd9ac15c9bcbad249cd0718
# contents of a commit (pointed at by dev)
ƒ git cat-file -p 22f3d040
tree b606a51e8dabb5ef8255468936cd61687e658dba
parent e11fcab56df0a700d1edc913271900034f559413
author Tim Ruffles <oi@truffles.me.uk> 1409675554 +0100
committer Tim Ruffles <oi@truffles.me.uk> 1409675554 +0100
@timruffles
timruffles / handled elses
Created August 27, 2014 17:07
return early
def something(x,y):
if !x:
raise "argh!"
else:
if !y:
raise "oh noes!"
else:
return "Happy"
@timruffles
timruffles / article.md
Created August 26, 2014 17:20
event-source-article

Real-time the easy way

When people think real-time their thoughts immediately leap to web-sockets. For many use-cases there exists a more productive approach, with good browser support hitting 100% via shims. Meet: EventSource AKA server-sent-events!

EventSource is a HTTP based protocol that allows one-way evented communication from the server to the client. It avoids the overhead of polling, provides seamless reconnection without any code on your part and has an incredibly simple API.

I'll take you through both the client and server-side of a chat application implemented via EventSource. We'll use AngularJS in the client and NodeJS in the server.

First - let's check out the EventSource API itself:

@timruffles
timruffles / erlang_debugger.ex
Last active August 29, 2015 14:05
erlang debugger (in elixir)
traceme = fn(msg, _x) ->
case msg do
{:trace, _, :call, {m, method, _}} ->
# ignoring arguments for concise tracing
IO.puts "#{m} #{method}"
_y -> :ok
end
end
# log all processes
@timruffles
timruffles / biojs-usage.js
Created August 4, 2014 15:51
bio.js usages
// generated via `grep -o -r "Biojs[\.a-zA-Z0-9]*" src/main/javascript/ | cut -f 2 -d : | sort | uniq -c | sort -r`
238 Biojs.console.enable
138 Biojs.console.log
88 Biojs.Event
81 Biojs
54 Biojs.extend
54 Biojs.Tooltip.ARROW
22 Biojs.Protein3D.COLOR
21 Biojs.Protein3D.STYLE
19 Biojs.InCHlib
@timruffles
timruffles / svtail.sh
Created July 24, 2014 07:45
tails a (runit) service by name, or tail all services on a machine
# tail a service by name
#
# svtail cad-server 50
#
# becomes
#
# tail -fn 50 /var/log/cad-server/current
#
svtail() {
local n=${2:-50}
@timruffles
timruffles / tcpflow.sh
Created July 23, 2014 16:11
quick way to look at HTTP (or TCP) traffic on linux with tcpflow
# -C - log output directly to STDOUT
# -i any port 5050 - listen on all interfaces for traffic to port 5050
tcpflow -C -i any port 5050
# install via `apt-get install tcpflow`
@timruffles
timruffles / single-gem.rb
Created July 18, 2014 14:46
install a single gem in bundler - via __END__
gem "https://rubygems.org"
gem "pg" # here's the target gem
__END__ # use the ever-useful __END__ to ignore the rest of our gems with no commenting required!
gem "rails"
@timruffles
timruffles / osx-pg-gem.sh
Created July 18, 2014 14:45
pg gem + bundler + osx , solving extconf issues
# grab install from http://www.enterprisedb.com/products-services-training/pgdownload#osx
# might need to replace version numbers
bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config