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
# This works because the first constant classes are assigned to automagically becomes their main name | |
ApplicationRecord = if feature_flag? | |
Class.new(ActiveRecord::Base) do | |
# implementation | |
end | |
else | |
ActiveRecord::Base | |
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
#! /usr/bin/env ruby | |
def words | |
@_words ||= open 'cmudict.dict' do |f| | |
f.each_line.with_object({}) do |line, acc| | |
word, *phonemes = line.strip.split ' ' | |
acc[word] = phonemes | |
end | |
end | |
rescue Errno::ENOENT |
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 | |
t.tablename, | |
indexname, | |
c.reltuples AS num_rows, | |
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size, | |
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size, | |
CASE WHEN indisunique THEN 'Y' | |
ELSE 'N' | |
END AS UNIQUE, | |
idx_scan AS number_of_scans, |
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 Main exposing (..) | |
import Html exposing (program, text, Html) | |
import Json.Decode exposing (succeed) | |
import Http | |
type alias Model = | |
Int |
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
import Array exposing (Array) | |
type alias Model = Array (Array Color) | |
type alias Point = (Int, Int) | |
type Color = Red | Green | Blue | Purple | |
set2d : Point -> Color -> Model -> Model | |
set2d (x, y) color model = | |
Array.get y model | |
|> Maybe.map (flip (Array.set y << Array.set x color) model) |
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 profile(**options) | |
fail "U WOT M8" unless block_given? | |
result = RubyProf.profile { yield } | |
Tempfile.open %w[vmm .cachegrind] do |tmp| | |
RubyProf::CallTreePrinter.new(result).print(tmp, **options) | |
spawn 'qcachegrind', tmp.path | |
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
{ | |
init: function(elevators, floors) { | |
_.random = function () { return 1; }; | |
Math.random = function () { return 1; }; | |
elevators.forEach(function (elevator) { | |
elevator.on("idle", function() { | |
elevator.goToFloor(0); | |
elevator.goToFloor(1); |
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 count_queries(&blk) | |
x = 0 | |
counter = -> (*args) { x += 1 } | |
ActiveSupport::Notifications.subscribed counter, 'sql.active_record', &blk | |
x | |
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
DIGIT_VALUES = { | |
'I' => 1, | |
'IV' => 4, | |
'V' => 5, | |
'IX' => 9, | |
'X' => 10, | |
'XL' => 40, | |
'L' => 50, | |
'XC' => 90, | |
'C' => 100, |
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
- 100.times do | |
%p/ | |
NewerOlder