Skip to content

Instantly share code, notes, and snippets.

Arnaud 'red' Rouyer joshleaves

Block or report user

Report or block joshleaves

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joshleaves
joshleaves / fuckyourails.rb
Created Apr 14, 2016
Rails is fucking up HTTP
View fuckyourails.rb
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
View gist:131cd947529ec79bb02c
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 / quiet_assets.rb
Created Apr 2, 2015
Mute assets in Rails logs. Place inside config/initializers/
View quiet_assets.rb
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
View keybase.md

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 / jude.js
Created Jul 22, 2013
My entry for @addyosmani's "Make lyrics with javascript" entry :)
View jude.js
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 / README.md
Last active Dec 19, 2015
TechShaker API guidelines
View README.md

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
View programmers-on-drugs.js
(function () {
module.exports = function (req, res, next) {
res.header('X-Powered-By', 'Programmers on drugs');
return next();
}
})();
@joshleaves
joshleaves / node-ga-routes.js
Created May 29, 2013
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.")
View node-ga-routes.js
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);
View debug.js
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 / js-6901.js
Created Apr 3, 2013
Quick and dirty implementation of RFC 6901: http://www.rfc-editor.org/rfc/rfc6901.txt Will do RFC 6902 later...maybe...
View js-6901.js
/*
// 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));
}
You can’t perform that action at this time.