Skip to content

Instantly share code, notes, and snippets.

View joshleaves's full-sized avatar

Arnaud 'red' Rouyer joshleaves

View GitHub Profile

Keybase proof

I hereby claim:

  • I am joshleaves on github.
  • I am redleaves (https://keybase.io/redleaves) on keybase.
  • I have a public key whose fingerprint is 4444 68FD 668F 20DE 4046 1DD2 0831 CF3F BE3A 6E84

To claim this, I am signing this object:

@joshleaves
joshleaves / quiet_assets.rb
Created April 2, 2015 14:15
Mute assets in Rails logs. Place inside config/initializers/
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
Rails.logger.level = previous_level
end
compdef () {
local opt autol type func delete eval new i ret=0 cmd svc
local -a match mbegin mend
emulate -L zsh
setopt extendedglob
if (( ! $# ))
then
print -u2 "$0: I need arguments"
return 1
fi
@joshleaves
joshleaves / js-6901.js
Created April 3, 2013 10:24
Quick and dirty implementation of RFC 6901: http://www.rfc-editor.org/rfc/rfc6901.txt Will do RFC 6902 later...maybe...
/*
// Will only throw on missing leading '/'
*/
JSON.pointer = function (object, pointer) {
if ('undefined' === typeof object || 'undefined' === typeof pointer || '/' === pointer) {
return object;
}
if ('/' !== pointer.substr(0, 1)) {
throw new SyntaxError('Unexpected character ' + pointer.substr(0, 1));
}
var d = 0;
var stack = [];
var LOG = console.log;
Function.prototype.callMe = Function.prototype.call;
Function.prototype.call = function () {
var depth = '';
for (var i = 0; i < d; ++i) { depth = depth + ' '; };
++d;
LOG('>>' + arguments.callee.caller.name);
stack.push(depth + '>> ' + arguments.callee.caller.name);
@joshleaves
joshleaves / node-ga-routes.js
Created May 29, 2013 11:36
How to use node-ga with routes instead of as a middleware. Based on the third example from http://expressjs.com/api#app.VERB ("Several callbacks may also be passed, useful for re-using middleware that load resources, perform validations, etc.")
var ga = require('node-ga')('UA-XXXXXXXX-Y', { safe: true});
/* your usual express options */
app.get('/logged-route', ga, LoggedRouteHandler);
app.get('/non-logged-route', NonLoggedRouteHandler);
(function () {
module.exports = function (req, res, next) {
res.header('X-Powered-By', 'Programmers on drugs');
return next();
}
})();
@joshleaves
joshleaves / README.md
Last active December 19, 2015 23:59
TechShaker API guidelines

First steps

You should have your api keyset (two keys) ready. If not, generate them. These tokens are tied to your account, and thus, to your identity. Like all API keys, these are of course NON-TRANSFERABLE and should never be communicated to third-parties (and I won't call you and ask them either).

With these two keys in hand, you'll then need a request. Let's just issue a PUT on /users/test_user with "github=testgithub". In curl this should look like this:

$ curl -X PUT -d "github=testgithub" http://api.techshaker.com/users/test_user

Well, not really, we also need to authenticate. Authentification is done by adding your API_KEY ("the short one") to the headers as "X-API-KEY". Like this:

$ curl -X PUT -H "X-API-KEY: YOUR-API-KEY" -d "github=testgithub" http://api.techshaker.com/users/test_user

@joshleaves
joshleaves / jude.js
Created July 22, 2013 23:26
My entry for @addyosmani's "Make lyrics with javascript" entry :)
var jude = 'jude';
var yeah = 'yeah';
var hey = 'hey';
var sixjude = [ jude, jude, jude, jude, jude, jude ];
var sixyeah = [ yeah, yeah, yeah, yeah, yeah, yeah ];
console.log(yeah);
console.log(sixjude.map(parseInt).join() + '(' + sixyeah.join() + ')');
console.log(sixjude.map(parseInt).join() + hey + jude);
@joshleaves
joshleaves / fuckyourails.rb
Created April 14, 2016 13:32
Rails is fucking up HTTP
2.2.0 :001 > opts = {
2.2.0 :002 > body: {
2.2.0 :003 > references: [
2.2.0 :004 > { item_id: 1, item_type: 'Part', code: 'IP5-SCREEN', gem_code: '1-UPTO-13' },
2.2.0 :005 > { item_id: 1, item_type: 'Accessory', code: 'SELFIE-FU', gem_code: '13-NUMBERS' }
2.2.0 :006?> ]
2.2.0 :007?> }
2.2.0 :008?> }
=> {:body=>{:references=>[{:item_id=>1, :item_type=>"Part", :code=>"IP5-SCREEN", :gem_code=>"1-UPTO-13"}, {:item_id=>1, :item_type=>"Accessory", :code=>"SELFIE-FU", :gem_code=>"13-NUMBERS"}]}}
2.2.0 :009 > opts.to_query