Skip to content

Instantly share code, notes, and snippets.

View carlesso's full-sized avatar

Enrico Carlesso carlesso

View GitHub Profile
@carlesso
carlesso / gist:e27b362e5b9bd8d69b3b
Created February 21, 2015 23:45
Pry show-method applied to .=~
[16] pry(main)> show-method 'string'.=~
From: string.c (C Method):
Owner: String
Visibility: public
Number of lines: 14
static VALUE
rb_str_match(VALUE x, VALUE y)
{
@carlesso
carlesso / test.rb
Last active August 29, 2015 14:14
Ruby "somethingIdon'tknowhowtoname"?
class Something
key :foo
def do_foo_check
# I'd like to access key somehow here
put "I'm doing #{what}"
# Expecting I'm doing foo
end
key :foo
@carlesso
carlesso / db.yml
Created January 15, 2015 13:44
db.yml
- name: Create PostgreSQL Users for rails applications
sudo: yes
sudo_user: postgres
when: item.db == 'postgresql'
postgresql_user: db={{ item.postgresql.database }} name={{ item.postgresql.username }} password={{ item.postgresql.password }} priv=ALL
with_items: rails_applications
@carlesso
carlesso / .pryrc
Last active August 29, 2015 14:12
Pry::Commands.create_command 'echo' do
description 'Echo the input'
banner <<-BANNER
Usage: echo [ -j <joiner> ] <words>
BANNER
def setup
@joiner = ' '
end
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.009 000.009: --- VIM STARTING ---
000.110 000.101: Allocated generic buffers
000.202 000.092: locale set
000.220 000.018: GUI prepared
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.005 000.005: --- VIM STARTING ---
000.058 000.053: Allocated generic buffers
000.111 000.053: locale set
000.123 000.012: GUI prepared
@carlesso
carlesso / phantomtumblr.js
Last active March 15, 2016 04:01
Phantom Tumblr https error
var page = require('webpage').create();
var system = require('system');
page.onResourceRequested = function (request) {
system.stderr.writeLine('= onResourceRequested()');
system.stderr.writeLine(' request: ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function(response) {
system.stderr.writeLine('= onResourceReceived()' );
#!/usr/bin/env python
# Properly cycle through named workspaces on i3, preventing bugs related to "3: foo" names
# And in your .i3/config
#
# bindsym Mod4+h exec /home/carlesso/bin/i3_output prev
# bindsym Mod4+l exec /home/carlesso/bin/i3_output next
import sys
import i3
#!/usr/bin/env python
import sys
import i3
def get_workspace(position = None):
mon = next(el for el in i3.get_workspaces() if el["focused"])
current_output = next(output for output in i3.get_outputs() if (output["active"] and (output["name"] == mon["output"])))
if position is None:
position = "current"
#!/usr/bin/env ruby
require 'json'
CLIENT_ID="eCGgvaJ3hKHD4kmPazSQrWVHGyZEsbSi"
CLIENT_SECRET="qGQ3sssbcEV5Ihmh"
res = `curl -s https://dnc-test.apigee.net/oauth/client_credential/accesstoken?grant_type=client_credentials -X POST -d "client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}"`
p = JSON.parse(res)
puts p