Skip to content

Instantly share code, notes, and snippets.

View bripkens's full-sized avatar
🙃

Ben Blackmore bripkens

🙃
View GitHub Profile
@bripkens
bripkens / vaadin-bookmarklets
Created June 11, 2012 12:45
Vaadin debug and restart bookmarklets.
// restart application
javascript:(function(){var location = window.location.href;window.location = location + (location.indexOf('?') == -1 ? '?' : '&') + 'restartApplication';})();
// debug application
javascript:(function(){var location = window.location.href;window.location = location + (location.indexOf('?') == -1 ? '?' : '&') + 'debug';})();
@bripkens
bripkens / observable.js
Created July 30, 2012 19:13
Observable changes for class-level events
(function(bui) {
var identifier = 'bui.Observable';
/**
* @class
* By inheriting from this class you can allow observers. Please note
* that you have to add types using the {@link bui.Observable#addType}
* function before listener can be added.
*
* @extends bui.Object
@bripkens
bripkens / gist:3769436
Created September 23, 2012 09:10
DOT file for finite state machine diagrams.
digraph finite_state_machine {
rankdir=LR;
node [shape = doublecircle]; 1;
node [shape = circle] 0;
node [shape = plaintext, label = ""]; start;
start -> 0 [ label = "start"];
0 -> 1 [ label = "[1-9]" ];
1 -> 1 [ label = "[0-9]" ];
@bripkens
bripkens / linux-commands.sh
Last active October 11, 2015 13:38
Commands that I always tend to forget about
sudo netstat -taupen
sudo tcpdump -i en0 -X -vvv host example.com
sudo /lib/ufw/ufw-init start
sudo ufw enable
jpegtran -copy none -optimize -outfile goal.jpg goal.jpg
# Pretty print JSON
| python -m json.tool
@bripkens
bripkens / mixins-common.js
Created October 15, 2012 12:15
Common Mixin approach
function extend(to, from) {
for (var key in from) {
if (from.hasOwnProperty(key)) {
to[key] = from[key];
}
}
}
function Label() { this.text = ''; };
Label.prototype.setLabel = function(text) { this.text = text || '' };
@bripkens
bripkens / gist:3986755
Created October 31, 2012 12:22
Mercurial changeset summary as JSON file
#!/bin/bash
OUT="changesets.json"
echo "[" > $OUT
hg log | grep "^changeset:" | sed 's/changeset.*:/ "/g' | sed 's/$/",/g' | sed '$s/,$//' >> $OUT
echo ']' >> $OUT
@bripkens
bripkens / simple-function-call.js
Created November 24, 2012 06:15
'JavaScript, State of the Art' article series: simple function example
// JSFiddle: http://jsfiddle.net/qQk7v/
var addMessage = function(message) {
var isWindowScope = window === this,
extendedMessage = message + ' (called with window context: ' + isWindowScope + ')',
textNode = document.createTextNode(extendedMessage);
document.body.appendChild(textNode);
};
addMessage('Welcome to: ' + location);​
// Renders the following in the body:
@bripkens
bripkens / type-coercion.js
Created November 24, 2012 06:24
'JavaScript, State of the Art' article series: type coercion
> "20" - 10
10
> "20" + 10
2010
> "42" == 42
true
> undefined == null
true
> Number.MIN_VALUE + 1 == 1
true
@bripkens
bripkens / eqeqeq.js
Created November 24, 2012 06:25
'JavaScript, State of the Art' article series: eqeqeq
> "42" === 42
false
> undefined === null
false
> 42 === 42.0
true
@bripkens
bripkens / functional-table.html
Created December 19, 2012 19:26
Functional programming in JavaScript example with Lo-Dash
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.js"></script>
<table id="people">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Occupation</th>
</tr>
</thead>