Skip to content

Instantly share code, notes, and snippets.

View lpgauth's full-sized avatar
😄
busy building cool stuff

Louis-Philippe Gauthier lpgauth

😄
busy building cool stuff
View GitHub Profile
require 'rubygems'
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::XML(open('http://search.twitter.com/search.atom?q=&ands=test&lang=en&rpp=10'))
doc.xpath('//feed/entry').first.children.each do |t| puts t.attributes end
--- a/vendor/plugins/paperclip/lib/paperclip.rb
+++ b/vendor/plugins/paperclip/lib/paperclip.rb
@@ -222,8 +222,8 @@ module Paperclip
after_save :save_attached_files
before_destroy :destroy_attached_files
- define_callbacks :before_post_process, :after_post_process
- define_callbacks :"before_#{name}_post_process", :"after_#{name}_post_process"
+ define_model_callbacks :post_process
+ define_model_callbacks :"#{name}_post_process"
require 'rubygems'
require 'grackle'
client = Grackle::Client.new(:auth=>{:type=>:basic,:username=>'lpgauth',:password=>'password'})
while true do
begin
if client.users.show?({:screen_name=>'soundcloud'}).followers_count == 24999
client.friendships.create!({:screen_name=>'soundcloud'})
break
cleanup() ->
[erase(K) || K <- [?SAVE_QS,
?SAVE_PATH,
?SAVE_RECV,
?SAVE_BODY,
?SAVE_BODY_LENGTH,
?SAVE_POST,
?SAVE_COOKIE,
?SAVE_FORCE_CLOSE]],
ok.
@lpgauth
lpgauth / gist:847543
Created February 28, 2011 16:21
mochiweb_request:cleanup()
cleanup() ->
[erase(K) || K <- [?SAVE_QS,
?SAVE_PATH,
?SAVE_RECV,
?SAVE_BODY,
?SAVE_BODY_LENGTH,
?SAVE_POST,
?SAVE_COOKIE,
?SAVE_FORCE_CLOSE]],
ok.
A = 1,
B = undefined,
C = 3,
Struct = {struct, [
{<<"A">>, A},
{<<"B">>, B},
{<<"C">>, c}]},
JSON = mochijson2:encode(Struct).
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
find_best_connection(Tid, Max_pipe) ->
case ets:first(Tid) of
{Cur_sz, Pid} when Cur_sz < Max_pipe ->
ets:delete(Tid, {Cur_sz, Pid}),
ets:insert(Tid, {{Cur_sz + 1, Pid}, []}),
{ok, Pid};
_ ->
{[{{adx,generate_bid_request,2}, 4, 54.049, 0.069},
{{adx,generate_response,3}, 2, 15.107, 0.037},
{{adx,generate_bid_response_ads,2}, 1, 6.980, 0.028},
{{piqi_tools,encode_rpc_request,2}, 1, 0.000, 0.020},
{{piqi_tools,convert,6}, 1, 0.000, 0.042},
{{ibrowse,send_req,6}, 1, 0.000, 0.017},
{{adx_piqi,parse_bid_request,1}, 1, 0.000, 0.016},
{{piqi_ext,gen_bid_request,2}, 2, 0.000, 0.020}],
{ {error_handler,undefined_function,3}, 13, 76.136, 0.249}, %
[{{error_handler,ensure_loaded,1}, 13, 35.550, 0.250},
-module(test).
-export([json/0]).
json() ->
Id = <<"abc123">>,
Name = undefined,
User = [],
User2 = [{<<"id">>, Id} | User],
User3 = [{<<"name">>, Name} | User2],
@lpgauth
lpgauth / gist:1029334
Created June 16, 2011 14:32
nodejs pattern
var wait = function(callbacks, done) {
var counter = callbacks.length;
var next = function() {
if(--counter == 0) {
done();
}
};
for(var i = 0; i < callbacks.length; i++) {
callbacks[i](next);
}