Skip to content

Instantly share code, notes, and snippets.

View mixu's full-sized avatar

Mikito Takada mixu

View GitHub Profile
@mixu
mixu / oauth.php
Created February 6, 2011 22:16
Oauth provider (early version...)
<?php
class Controller_Oauth extends Controller_App {
/**
* Models
* - Consumer (for keeping track of sites which have access to your oAuth provider)
* - Token (request token (type 0) or an access token, (type 1))
*
*/
@mixu
mixu / gist:1270915
Created October 7, 2011 17:49
HN steveblock
// ==UserScript==
// @name Hacker News Steve Filter
// @description Filter "Hacker News" items about Steve Jobs
// @include http://news.ycombinator.com/*
// ==/UserScript==
(function(){
var list = ['steve', 'jobs', 'job\'s'];
// get spans
@mixu
mixu / httptest.js
Created November 28, 2011 22:43
Difference between OSX and Linux on Node 0.4.12
// Illustrates a difference in behavior between OSX and Linux
// (tested on OSX and Arch)
var http = require('http');
var server = http.createServer();
server.on('request', function (req, res) {
res.writeHead(200);
res.end('Hello world.');
@mixu
mixu / gist:1559933
Created January 4, 2012 12:54
Implementing classes in JS without Object.create
var Animal = function(name) {
this.name = name;
};
Animal.prototype.move = function(meters) {
console.log(this.name+" moved "+meters+"m.");
};
var Snake = function() {
Animal.apply(this, Array.prototype.slice.call(arguments));
@mixu
mixu / gist:2313880
Created April 5, 2012 20:31
List git branches and last log line
#/bin/bash
git branch -r | while read line ;
do
echo
echo "************" ${line#origin/}
echo
git log -1 $line
done
@mixu
mixu / gist:2783272
Created May 24, 2012 18:20
Formatting JSON from stdin using Node
Pipe curl to:
node -e 'var d = "", p=process.stdin; p.resume(); p.on("data", function(c){d+=c;}); p.on("end", function(){ console.log(require("util").inspect(JSON.parse(d), false, null, true))})'
var i = 0;
function fillLocalStorage(size) {
try {
window.localStorage.setItem('data'+i++, new Array(size).join('a'));
} catch(e) {
if(size == 1) {
throw e;
} else {
return fillLocalStorage(Math.floor(size / 2));
}
@mixu
mixu / compare.sh
Created October 23, 2012 23:34
Require() shim size comparison (minified with uglifyjs)
echo "AlmondJS shim: "
curl --silent https://raw.github.com/jrburke/almond/master/almond.js | uglifyjs --no-copyright | wc -c
echo "Browserify shim: "
curl --silent https://raw.github.com/substack/node-browserify/master/wrappers/prelude.js | uglifyjs --no-copyright | wc -c
echo "Browserbuild shim: "
curl --silent https://raw.github.com/LearnBoost/browserbuild/master/lib/require.js | uglifyjs --no-copyright | wc -c
echo "GlueJS new shim: "
@mixu
mixu / gist:5016664
Created February 22, 2013 21:25
Repo fetching
(function() {
var repos = [];
function parse_link_header(header) {
// Split parts by comma
var parts = (header ? header.split(',') : []),
links = {};
// Parse each part into a named link
parts.forEach(function(p) {
@mixu
mixu / gist:5726204
Created June 7, 2013 00:23
Stack trace experiment in Chrome
// this function can get the full stack trace, however, it's usefulness is
// somewhat limited by the fact that Chrome Dev tools can only display full
// urls that are passed as the first argument as a string. That means that
// every log line is preceded by a massively ugly URL block that works as
// a link but this is only mildly useful. There is no way to get the dev
// tools to linkify shorter URLs - if that were possible, then this
// might be a usable solution from a UI perspective
function getStack() {
var orig = Error.prepareStackTrace;