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
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()) |
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
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 -> |
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
#!/bin/zsh | |
# Share a file on https://file.io | |
# Dependencies: jq | |
# Optional Dependencies: xclip | |
# Usage: | |
# fileio -t TTL [FILE] |
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 Hand | |
WEAPONS = [:rock, :paper, :scissors, :lizard, :spock] | |
attr_reader :weapon | |
def initialize(weapon) | |
@weapon = weapon.to_sym | |
end | |
def valid? |
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
HANDS = [:rock, :paper, :scissors, :lizard, :spock] | |
HANDS.freeze | |
RESULTS = { | |
rock: { | |
lizard: 'crushes', | |
scissors: 'crushes' | |
}, | |
paper: { | |
rock: 'covers', |
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
PLAYS = { | |
:scissors => [:paper, :lizard], | |
:spock => [:scissors, :rock], | |
:lizard => [:spock, :paper], | |
:rock => [:lizard, :scissors], | |
:paper => [:rock, :spock] | |
} | |
PLAYS.freeze |
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
# 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 |
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 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 |
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
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 |
NewerOlder