Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / tracking.js
Created October 28, 2014 11:01
tracking factory
var app = angular.module("exercise",[]);
function trackingFactory($http) {
var tracking = {};
var count = {};
tracking.event = function(event) {
if(!(event in count)) {
count[event] = 0;
@timruffles
timruffles / index.html
Last active August 29, 2015 14:08
modal-demo
<!DOCTYPE html>
<html ng-app=exercise>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Angular Exercise</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="../vendor/foundation/css/normalize.css" rel="stylesheet">
@timruffles
timruffles / 01_before.js
Created November 10, 2014 19:36
'inside out' refactoring with promises
function outer(db) {
var codeqs = loadCodeqsForComparison(db, project.id, paths, analyses);
}
function loadCodeqsForComparison(db, projectId, paths, analyses) {
var files = loadFiles(projectId, ref, paths)
var codeqs = loadCodeqs(db, analyses)
return Promise.all([codeqs, files]).spread(function(codeqList, files) {
return codeqList.map(function(codeq) {