Skip to content

Instantly share code, notes, and snippets.

View matths's full-sized avatar
💻
In a former live I was a flash developer.

Matthias Dittgen matths

💻
In a former live I was a flash developer.
View GitHub Profile
@matths
matths / gist:1207164
Created September 9, 2011 19:54 — forked from denis/gist:48774
download & install git code completion from github mirror while git.kernel.org is down
cd /tmp
git clone git://gist.github.com/946648.git
cd git
git checkout git-completion.bash
cp git-completion.bash ~/.git-completion.bash
cd ~
rm -rf /tmp/git
echo -e "source ~/.git-completion.bash" >> .bash_profile
@matths
matths / gist:2771311
Created May 22, 2012 20:06
grab user's facebook album cover pictures
// don't forget to set &oauth=1 in FB.init
// check for valid login, the easy way:
if (FB._authResponse != null)
FB.login(function(r) {}, {scope: 'user_photos'})
FB.api('/me/albums', function(d) {
for (var i=0; i<d.data.length; i++) {
console.log(d.data[i].id, d.data[i].name, d.data[i].link);
@matths
matths / gist:2783365
Created May 24, 2012 18:37
Fisher Yates shuffle of a jQuery selection
// http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
$.fn.scramble = function() {
var i = this.length;
if (i > 0) {
var j;
var tmp;
while (--i) {
j = Math.floor(Math.random() * (i + 1));
t = this[j];
this[j] = this[i];
@matths
matths / gist:4500902
Created January 10, 2013 10:04
some basics using NSJSONSerialization (iOS5 and up.)
NSString *strArrayExample = @"%5B%22hello%22%2C%22world!%22%2C12%5D";
NSString *strObjectExample = @"%7B%22a%22%3A%221%22%2C%22b%22%3A%22c%22%7D";
NSString *str = [strArrayExample stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"str:: %@", str);
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"type of data:: %@", NSStringFromClass([json class]));
#!/bin/sh
CURRENT=$(node -v)
#version details
VERSION=$(curl -L -s http://nodejs.org/dist/latest/ \
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
| tail -n1)
PLATFORM=linux
ARCH=x64
@matths
matths / output.txt
Last active August 29, 2015 13:58
When beginning with node.js and modules, it's always difficult to understand the difference between exports and module.exports. Exports is a local reference to an empty plain object ({}), where module.exports is also referring to. But module.exports is what is assigned to the return value of the require() method, not exports. Changing exports to…
exports {}
module.exports {}
module.exports == exports YES
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exports {}
module.exports function myExport() { console.log('an exported function instead of a plain object'); }
module.exports == exports NO
an exported function instead of a plain object
@matths
matths / https2http.md
Created April 30, 2014 15:26
https2http Snippet

https2http Bookmarklet

Replace all occourences of "https" with "http" in the following tags.atrributes:

  • script.src
  • link.href
Array.prototype.slice.call(document.querySelectorAll('script')).map(function(v,i) { v.src = v.src.replace(/https/, 'http'); console.log(i, v.src);});Array.prototype.slice.call(document.querySelectorAll('link')).map(function(v,i) { v.href = v.href.replace(/https/, 'http'); console.log(i, v.href);});
@matths
matths / parse.js
Created May 7, 2014 09:10
Line-by-line manipulation of text files (eg. error log files) using node.js' new Stream.Transform functionality and pipe(). You can call this directly from your shell, eg. $ node parse.js error.log
var fs = require('fs');
var TransformLine = require('./TransformLine');
// syntax example:
// $ node parse.js error.log
var inFile = process.argv[2];
var outFile = process.argv[3];
if (!inFile) {
@matths
matths / http-and-ssh-proxy.js
Last active August 29, 2015 14:01 — forked from bnoordhuis/http-and-https-proxy.js
A node.js proxy listening on port 80 that forwards HTTP or SSH traffic to different ports. Thus SSH might become reachable to a somewhat restrictive hotel or corporate firewall, while HTTP can still be served as well.
var fs = require('fs');
var net = require('net');
var http = require('http');
var sshAddress = '22';
var httpAddress = '8080';
var incoming = '80';
http.createServer(httpConnection).listen(httpAddress);
net.createServer(tcpConnection).listen(incoming);
@matths
matths / TestApp.js
Created August 12, 2014 19:04
NodObjC Example of drawRect call (not working)
// dependencies
var ObjC = require('NodObjC');
// ObjC dependencies
ObjC.import('Foundation');
ObjC.import('Cocoa');
ObjC.import('AppKit');
ObjC.import('QuartzCore');
// using ARC