Skip to content

Instantly share code, notes, and snippets.

@eduardordm
eduardordm / currentquery.txt
Created March 15, 2013 19:37
Traces for Arel (oracle.rb)
SELECT * FROM (
SELECT raw_sql_.*, rownum raw_rnum_
FROM (SELECT "LANCAMENTOS".* FROM "LANCAMENTOS" ) raw_sql_
)
WHERE raw_rnum_ between 1 and 30
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
$scope.doStuff = function(attrs) {
if($rootScope.stuffLocked) {
return;
}
$rootScope.stuffLocked = true;
// load stuff, etc
$rootScope.stuffLocked = false;
@eduardordm
eduardordm / cached.js
Created February 22, 2013 19:23
AngularJS ephemeral caching. Consider a list of links containing which represent folders. Just like an email client, the user will browser between folders. ng-clicks will trigger switchFolder
$scope.switchFolder = function(attrs) {
// Results found on the last query will be available instantly (if any)
// you could also add a Message.is_query_cached to check if there are cached results
$scope.messages = Message.query_cached({ id: attr.some_id});
// Lets find the actual results, which can take longer
var messages = Message.query({ id: attr.some_id}, function () {
$scope.messages = message;
});
@eduardordm
eduardordm / gist:4691440
Created February 1, 2013 13:56
zurb form helper errors
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
errors = Array(instance.error_message).join(',')
%(<div class="error">#{html_tag}<small class="error">&nbsp;#{errors}</small></div>).html_safe
else
%(<div class="error">#{html_tag}</div>).html_safe
end
end
@eduardordm
eduardordm / gist:4634649
Last active December 11, 2015 17:28
trololol
def self.anual(fc0, fcj, n, d0, dj0)
fc0 = fc0.to_f
fcj = fcj.to_f
dn = dj0 >> n
dias = (dn - dj0).to_i
cet = 0
while true
total = 0.0
n.times do |j|
@eduardordm
eduardordm / twblock.rb
Created December 4, 2012 17:52
Blocks followers with no tweets (mostly fake followers)
require 'twitter'
Twitter.configure do |config|
config.consumer_key = 'trololol'
config.consumer_secret = 'trololol'
config.oauth_token = 'trololol-trololol'
config.oauth_token_secret = 'trololol'
end
begin
@eduardordm
eduardordm / gist:1873995
Created February 21, 2012 05:38
Good lord, where is NSString replaceWithPattern: ?!?!?!?!??!!?!?
int count = 1;
while ( [[NSFileManager defaultManager] fileExistsAtPath:[self filePath]] ) {
NSRegularExpression *regex =
[NSRegularExpression regularExpressionWithPattern:@"\\s\\(\\d\\)"
options:NSRegularExpressionCaseInsensitive
error:NULL];
NSString* str = [regex stringByReplacingMatchesInString:self.name
options:0
@eduardordm
eduardordm / gist:1108424
Created July 27, 2011 00:29
#rubyonrails
class User < ActiveRecord::Base
has_many :actions
end
class Actions < ActiveRecord::Base
belongs_to :movie
belongs_to :user
# add a scope called twitted - it's just a where!!!
end
before (:each) do
visit new_user_session_path
fill_in 'user_login', :with => 'OhMyTest'
fill_in 'user_password', :with => 'xix2x3xi'
click_button "user_submit"
end
@eduardordm
eduardordm / gist:1040673
Created June 22, 2011 17:52
REALLY??!??!?!
Started GET "/assets/application.js" for 127.0.0.1 at 2011-06-22 13:51:25 -0400
Compiled ~/Intermeta/smsy/app/assets/javascripts/application.js (3ms) (pid 60381)
Compiled ~/.rvm/gems/ruby-1.9.2-p180@rails31rc4/gems/jquery-rails-1.0.11/vendor/assets/javascripts/jquery.js (1ms) (pid 60381)
Compiled ~/.rvm/gems/ruby-1.9.2-p180@rails31rc4/gems/jquery-rails-1.0.11/vendor/assets/javascripts/jquery_ujs.js (0ms) (pid 60381)
Compiled ~/Intermeta/smsy/app/assets/javascripts/posts.js.coffee (80ms) (pid 60381)
Compiled ~/Intermeta/smsy/app/assets/javascripts/welcome.js.coffee (0ms) (pid 60381)
Served asset /application.js - 304 Not Modified (91ms) (pid 60381)
/Users/eduardo/.rvm/gems/ruby-1.9.2-p180@rails31rc4/gems/sass-3.1.2/lib/sass/util.rb:510: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]