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
class Foo | |
def call_foo | |
foo | |
end | |
def call_self_foo | |
self.foo | |
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
require 'benchmark/ips' | |
N = 1_000_000 | |
ARRAY = N.times.map { rand } | |
Benchmark.ips do |x| | |
x.report("reject") do | |
arr = ARRAY.dup | |
out = [] | |
arr.reject! { _1 >= 0.5 } |
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 current_branch { git rev-parse --abbrev-ref HEAD } | |
Function ga { git add @Args } | |
Function gau { git add --update @Args } | |
Function gaa { git add --all @Args } | |
Function gapa { git add --patch @Args } | |
Function gb { git branch @Args } | |
Function gba { git branch -a @Args } | |
Function gbd { git branch -d @Args } | |
Function gbl { git blame -b -w @Args } | |
Function gbnm { git branch --no-merged @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
# Test validity of all your fixtures in one simple test. | |
# Just put this file somewhere, like maybe `test/models`, and run `bin/rails test test/models/fixture_test.rb`. | |
# Even gives you the line number of the fixture definition in the failure message! | |
require 'test_helper' | |
class FixturesTest < ActiveSupport::TestCase | |
Dir.glob(Rails.root.join('test', 'fixtures', '*.yml')).each do |filename| | |
set_name = File.basename(filename, '.yml') |
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 'active_support/core_ext/hash' | |
require 'benchmark/ips' | |
require 'json' | |
N = 1000 | |
M = 100 | |
TEST_ARRAY = N.times.map do |n| | |
h = { 'some_key' => "H #{n}" } | |
M.times do |m| |
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 Rein::SchemaDumper | |
def tables(stream) | |
super | |
check_constraints(stream) | |
end | |
def check_constraints(stream) | |
constraints = @connection.execute <<-SQL | |
select * | |
from information_schema.check_constraints as c, information_schema.constraint_column_usage as u |
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
N = 960939379918958884971672962127852754715004339660129306651505519271702802395266424689642842174350718121267153782770623355993237280874144307891325963941337723487857735749823926629715517173716995165232890538221612403238855866184013235585136048828693337902491454229288667081096184496091705183454067827731551705405381627380967602565625016981482083418783163849115590225610003652351370343874461848378737238198224849863465033159410054974700593138339226497249461751545728366702369745461014655997933798537483143786841806593422227898388722980000748404719 | |
def tupper(x, y) | |
0.5 < (((y/17).floor*(2 ** (-17 * x.floor - (y.floor % 17)))) % 2).floor | |
end | |
(N..N+16).each do |y| | |
105.downto(0) do |x| | |
print tupper(x, y) ? "\e[47m" : "\e[40m"; | |
print ' ' |
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 Foundation | |
class StringCalculator { | |
func add(string:String) -> Int { | |
let numbers = string.componentsSeparatedByString(",") | |
var total = 0 | |
for number in numbers { | |
total += (number as NSString).integerValue | |
} | |
return total |
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
@echo off | |
echo Getting your IP address... | |
echo. | |
curl ifconfig.me | clip | |
echo. | |
echo Your IP is in the clipboard :) | |
echo. | |
pause |