As configured in my dotfiles.
start new:
tmux
start new with session name:
class Integer | |
def collatz_chain_size | |
n = self | |
chain = [] | |
until n == 1 | |
chain << n | |
n.even? ? n /= 2 : n = n * 3 + 1 | |
end | |
[chain.size, chain.first] | |
end |
class Weazel | |
CHARS = [*'A'..'Z', ' '] | |
def initialize target | |
@target = target | |
@best = Array.new(28) { CHARS.sample }.join | |
end | |
def call | |
0.upto Float::INFINITY do |n| |
#!/bin/sh | |
gem search --no-vers | parallel -j0 -I$ 'curl -O `curl https://rubygems.org/api/v1/gems/$.json | jq -r .gem_uri`' |
class Chromosome | |
attr_accessor :bit_string, :fitness | |
def initialize length, bit_string = nil | |
@length = length | |
if bit_string.nil? | |
generate_random length | |
else | |
@bit_string = bit_string |
# A simple translate from a string to integer. | |
# A minus before all numbers will be consider to be a negative number. | |
def atoi(str) | |
return str if !str.is_a? String | |
fixed_str = fix(str) | |
result = 0 |
module AtoiString | |
refine String do | |
def atoi | |
fixed_self = fix self | |
result = 0 | |
fixed_self.each_char do |c| | |
result = result * 10 + c.to_i | |
end | |
As configured in my dotfiles.
start new:
tmux
start new with session name:
require 'json' | |
test2 = { | |
:foo1 => { | |
:target => "Something1", | |
:alias => "some_alias1" | |
}, | |
:foo2 => { | |
:target => "Something2", | |
:alias => "some_alias2" |
require "./alfred" | |
results = Alfred::Feedback.new | |
available_outputs = `./SwitchAudioSource -a | grep "(output)" | sed 's/ (output)$//'` | |
current_output = `./SwitchAudioSource -c` | |
def ditch_line available, current | |
available.split("\n").delete_if { |line| line == current }.join("\n") | |
end |
array = (1..12).map &:to_s | |
class Array | |
def insert_every n, this | |
each_slice(n).inject { |r, a| r << this << a }.flatten | |
end | |
end | |
array.insert_every 3, ',' | |
#=> ["1", "2", "3", ",", "4", "5", "6", ",", "7", "8", "9", ",", "10", "11", "12"] |