View open_struct_example.rb
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 "ostruct" | |
class User | |
def initialize(basic_params) | |
@json_params = OpenStruct.new(basic_params) | |
end | |
def full_name | |
[ | |
@json_params.first_name, |
View incremental_counter_config.json
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
{ | |
"rules": { | |
".read": false, | |
".write": false, | |
"incremental_counter": { | |
".validate": "newData.isNumber() && newData.val() === data.val() + 1", | |
".read": true, | |
".write": true | |
} | |
} |
View auto_benchmark_with_ips.rb
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' | |
require 'benchmark/ips' | |
Benchmark.ips do |r| | |
r.report("+ ") do | |
42 + 42 | |
end | |
r.report("* ") do | |
42 * 42 |
View code.c
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
#include <stdio.h> | |
long long int myfunc (long long int i, long long int cache[]) | |
{ | |
if(cache[i]) { | |
return cache[i]; | |
} | |
if (i <= 2) { | |
return i; |
View add serial primary key to existing table.sql
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
ALTER TABLE mc_subscribers ADD COLUMN id BIGSERIAL; | |
UPDATE mc_subscribers SET id = nextval(pg_get_serial_sequence('mc_subscribers', 'id')); | |
ALTER TABLE mc_subscribers ADD PRIMARY KEY (id); |
View Monitor PG processes.sql
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
SELECT | |
age(now(), query_start) AS duration, | |
state, | |
pid, | |
query, | |
datname, | |
application_name, | |
waiting | |
FROM pg_stat_activity | |
ORDER BY duration DESC NULLS LAST; |
View count_words.rb
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
input = ["red", "green", "blue", "red", "blue"] | |
output = input.each_with_object(Hash.new(0)) do |word, o| | |
o[word] += 1 | |
end | |
p output | |
# {"red"=>2, "green"=>1, "blue"=>2} |
View trim_column.sql
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
update fb_audiences | |
set facebook_id = replace(facebook_id, '[^0-9]+$', ''); | |
SELECT id, facebook_id | |
FROM fb_audiences | |
WHERE facebook_id ~ '[^0-9]+$' |
View filter_9gag.js
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
(function() { | |
function hideBoringArticles(nodes) { | |
nodes.filter("article.badge-entry-container.badge-entry-entity").each(function(i, el) { | |
if($(el).data("entryVotes") < 20000) { | |
$(el).hide(); | |
} | |
}) | |
} | |
var MutationObserver = window.MutationObserver; |
View unfair_coin.rb
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 toss | |
(rand * 100) > 60 ? 1 : 2 | |
end | |
# Both players bet on 1 | |
def game | |
toss_1 = toss() | |
toss_2 = toss() | |
if toss_1 == 1 && toss_2 != 1 |
NewerOlder