Skip to content

Instantly share code, notes, and snippets.

@aokolish
aokolish / tmux.md
Created October 13, 2012 16:47
quick way to kill all tmux sessions

This is the quickest way I've found to kill all tmux sessions

# detach from each session
<prefix>d

# kill tmux and all sessions
tmux kill-server
@aokolish
aokolish / anagrams.txt
Created September 22, 2012 21:16
list of anagrams
barrette batterer
barye beray yerba
basally salably
basaltic cabalist
base besa sabe
basion bonsai sabino
basketwork workbasket
bastille listable
bat tab
batcher brachet
@aokolish
aokolish / closest_web_safe.rb
Created November 3, 2017 21:14
closest web safe color...v2
WEB_SAFE_NUMBERS = [
0, # 00
51, # 33
102, # 66
153, # 99
204, # cc
255 # ff
]
def closest_web_safe_color(string)
@aokolish
aokolish / closest_web_safe.rb
Created November 3, 2017 20:35
closest web safe color
WEB_SAFE_NUMBERS = [
0, # 00
51, # 33
102, # 66
153, # 99
204, # cc
255 # ff
]
def closest_web_safe_color(string)
# https://leetcode.com/problems/count-primes/description/
# return the number of prime numbers less than a positive number n
def count_primes(n)
primes = []
(2..n-1).each do |i|
primes[i] = true
end
(2..Math.sqrt(n)).each do |i|
class Solution
def initialize
@known_strings = {}
end
def word_break(string, word_dict)
if @known_strings[string]
return @known_strings[string]
end
def replace_words(dict, sentence)
regex = /\A(#{dict.join('|')})/
sentence.split.inject([]) do |new_words, word|
if match_data = word.match(regex)
new_words << match_data.captures[0]
else
new_words << word
end
end.join(' ')
@aokolish
aokolish / search.exs
Last active June 16, 2016 23:34
binary search. `elixir search.exs` to run this. assuming you have elixir (`brew install elixir`)
defmodule Search do
def chop(_val, []), do: -1
def chop(val, [head|tail]) when tail == [] do
if val == head, do: 0, else: -1
end
def chop(val, list) do
chop(val, 0, length(list) - 1, list)
end
class Dependencies
def initialize
@dependencies = Hash.new {|h,k| h[k] = []}
end
def add_direct item, new_dependencies
@dependencies[item] += new_dependencies
end
def dependencies_for item
def validate_messages(message)
message.split(' ').each do |msg|
if valid? msg
puts msg + " VALID"
else
puts msg + " INVALID"
end
end
end