Skip to content

Instantly share code, notes, and snippets.

View CyrusOfEden's full-sized avatar
🐉
Kaizen

Cyrus CyrusOfEden

🐉
Kaizen
View GitHub Profile
VOWELS = %w[a e i o u y]
def translate(words)
words.split(/\W/).map do |word|
until VOWELS.include?(word[0])
word += word[0,2] == "qu" ? word.slice!(0, 2) : word.slice!(0)
end
word + "ay"
end.join(" ")
end
@CyrusOfEden
CyrusOfEden / event.rb
Last active August 29, 2015 14:05
Streamer
class Event < ActiveRecord::Base
scope :starting, { where(start_time: 5.minutes.ago..5.minutes.from_now) }
scope :ending, { where(end_time: 5.minutes.ago..5.minutes.from_now) }
# ...
end
@CyrusOfEden
CyrusOfEden / ngram_search.js.coffee
Last active August 29, 2015 14:05
Efficient Searching
# ALL NGRAMS CACHE (cache this client-side)
# ================
ngrams = {} # Assuming ngrams is a pre-populated hash
# ALL RECORDS CACHE (cache this client-side)
# =================
Records = [] # an array of all records
ShadowRecords = [] # an array of all records' ids
PLAYS = {
:scissors => [:paper, :lizard],
:spock => [:scissors, :rock],
:lizard => [:spock, :paper],
:rock => [:lizard, :scissors],
:paper => [:rock, :spock]
}
PLAYS.freeze
HANDS = [:rock, :paper, :scissors, :lizard, :spock]
HANDS.freeze
RESULTS = {
rock: {
lizard: 'crushes',
scissors: 'crushes'
},
paper: {
rock: 'covers',
class Hand
WEAPONS = [:rock, :paper, :scissors, :lizard, :spock]
attr_reader :weapon
def initialize(weapon)
@weapon = weapon.to_sym
end
def valid?
#!/bin/zsh
# Share a file on https://file.io
# Dependencies: jq
# Optional Dependencies: xclip
# Usage:
# fileio -t TTL [FILE]
defmodule Algorithm do
require Logger
# Helpers
def pmap(collection, fun) when is_function(fun) do
master = self()
collection
|> Enum.map(fn elem ->
result_pid = spawn_link fn ->
defmodule Algorithm do
# Helpers
def parallel(collection, fun) when is_function(fun) do
master = self()
collection
|> Enum.map(fn item ->
Task.start fn ->
fun.(item)
send(master, self())
def delete_all(collection, value) when is_list(collection) do
List.foldr collection, [], fn
x, acc when x == value ->
acc
x, acc ->
[x|acc]
end
end