Skip to content

Instantly share code, notes, and snippets.

@torgeir
torgeir / gist:8718436
Created January 30, 2014 20:53
Lock your screen
brew install sl
echo "alias ls='sl'" >> .profile
. .profile
@torgeir
torgeir / requirejs.html
Created January 31, 2014 14:39
Requirejs plugin to load different resources based on some condition.
<!doctype html>
<meta charset=utf-8>
<title>requiretest</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script>
define("A", [], function () {
function A () { console.log('A') }
return A;
});
@torgeir
torgeir / jackson-json-expose-field-ignore-setter.java
Created February 14, 2014 08:29
Jackson json, expose field but ignore setter.
@JsonIgnore
private field;
@JsonPropety
public String getField() {}
/* no setter */
@torgeir
torgeir / upgrade_rasplex.sh
Last active August 29, 2015 13:56
Upgrading an experimental RasPlex build.
# grab the latest build
wget http://downloads.sourceforge.net/project/rasplex/experimental/rasplex-RPi.arm-9.9.20.tar
tar -xvf rasplex-RPi.arm-9.9.20.tar
# move into the target directory
cd rasplex-RPi.arm-9.9.20/target
# create the .update/ folder if you dont already have it
ssh pi mkdir .update
@torgeir
torgeir / valid_git_urls_for_npm.txt
Last active August 29, 2015 13:56
Valid git urls for npm.
git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+ssh://user@hostname/project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish
@torgeir
torgeir / cross-browser-media-width-media-height.js
Created March 4, 2014 09:33
JavaScript cross-browser @media (width) and @media (height) values
// http://stackoverflow.com/questions/1248081/get-the-browser-viewport-dimensions-with-javascript
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
@torgeir
torgeir / floating-point-arithmetics-iee754.js
Created March 13, 2014 08:30
Floating point arithmetics, IEE754
// http://stackoverflow.com/questions/588004/is-floating-point-math-broken
// https://en.wikipedia.org/wiki/IEEE_754#Basic_formats
// Don't use ==
0.1 + 0.2 == 0.3 // false
0.1 + 0.2 // 0.30000000000000004
var x = 0.2;
var y = 0.3;
var equal = (Math.abs(x - y) < 0.000001)
@torgeir
torgeir / make-summary.md
Last active August 29, 2015 13:57
Make summary.

Make summary

Expose env variables.

export PATH := node_modules/.bin:$(PATH)

Keep file lists.

template_source := templates/*.handlebars
template_js := build/templates.js
@torgeir
torgeir / a-heartbleed-locally-using-vagrant-nodejs-and-a-vulnerable-openssl.md
Last active August 29, 2015 13:59
Test heartbleed locally using vagrant, node.js and a vulnerable openssl.
  1. Setup vagrant

    vagrant init hashicorp/precise32

  2. Make the vagrant config change (on your local computer, see Vagrantfile)

    vagrant up

    vagrant ssh

@torgeir
torgeir / coercing.js
Last active August 29, 2015 14:00
js number coercing
var n = Number(1);
var m = n;
n = null;
console.log(m); // 1
var o = new Number(1);
var p = o;
o = null;
console.log(p); // {}