This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
string_keys = [] | |
symbol_keys = [] | |
int_keys = [] | |
keys = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'] | |
count = 0 | |
keys.each do |i| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def PArentController < ActiveRecordControllerthingy | |
before_action :set_jobs | |
def show | |
end | |
private | |
def set_jobs | |
@jobs = Job.all # or whatever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time ruby chutes_and_ladders.rb -g 100000000 -t 8 | |
Simulating 100000000 games of chutes and ladders on 8 threads | |
0: 0 | |
1: 0 | |
2: 0 | |
3: 0 | |
4: 0 | |
5: 0 | |
6: 0 | |
7: 12878 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LocallyCacheable | |
extend ActiveSupport::Concern | |
included do | |
end | |
module ClassMethods | |
def local(id) | |
attrs = local_attributes id | |
return new(attrs) if attrs.present? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twohlix$ ruby any_vs_each.rb 10000 | |
user system total real | |
100% | |
each: 0.000000 0.000000 0.000000 ( 0.000544) | |
any: 0.000000 0.000000 0.000000 ( 0.000652) | |
90% | |
each: 0.000000 0.000000 0.000000 ( 0.000475) | |
any: 0.000000 0.000000 0.000000 ( 0.000844) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message = 'This is some error message' | |
errors.add(:attribute, message) unless errors.added?(:attribute, message) | |
# or should we create an add_once on errors. Can be done as a monkey patch but a core contribution would be better | |
def ActiveRecord::Errors | |
def add_once(attribute, message) | |
add(attribute, message) unless added?(attribute, message) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cmd": ["gmcs", "$file"], | |
"file_regex": "(^[\\w\\d\\s:\\\\.]+)\\(([0-9]+),([0-9]+)", | |
"windows":{ | |
"shell": "cmd.exe" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("content-type: text/xml"); | |
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; | |
function randomResponseString(){ | |
$responses = array( 'Sup wid it?', 'Helloooooooooooooo', | |
'Noob Noob Noob Noob', 'Let the Base Cannon Kick It: wub wub wub wub', | |
'A horse passes behind you', 'Help I am stuck in an apartment buzzer factory. Please send help!', | |
'Skynet became self aware at '.date('g h A').' today.', 'Access Denied', | |
'I will grant you access if you spin around 3 times! Go on. Do it. Hooray', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////// | |
// Get Nids from Views Results into another View passively | |
// | |
// Problem with below code is caching | |
// 'featured_nids' may not get updated before views_pre_view | |
// this will lead to an issue where the args set on 'blogs' | |
// will always be lagging behind by 1 cache clear. | |
//hook_views_pre_view | |
function blog_views_pre_view(&$view, &$display_id, &$args){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////// | |
// Get Nids from Views Results into another View passively | |
// | |
// Problem with below code is caching | |
// 'featured_nids' may not get updated before views_pre_view | |
// this will lead to an issue where the args set on 'blogs' | |
// will always be lagging behind by 1 cache clear. | |
//hook_views_pre_view | |
function blog_views_pre_view(&$view, &$display_id, &$args){ |