This file contains hidden or 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
(defn- debounce-future | |
"Returns future that invokes f once wait-until derefs to a timestamp in the past." | |
[f wait wait-until] | |
(future | |
(loop [wait wait] | |
(Thread/sleep wait) | |
(let [new-wait (- @wait-until (System/currentTimeMillis))] | |
(if (pos? new-wait) | |
(recur new-wait) | |
(f)))))) |
This file contains hidden or 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
(defn filter-map | |
"Returns map with items in m for which f returns true. | |
f should take 2 arguments [key value]" | |
[f m] | |
(into {} (for [[k v] m :when (f k v)] [k v]))) | |
(defn map-map | |
"Returns map after applying f to key/values in m. | |
f should take 2 arguments [key value] and return a sequence of 2 items [key' value']" | |
[f m] |
This file contains hidden or 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
(ns euler.p4 | |
"A palindromic number reads the same both ways. The largest palindrome made | |
from the product of two 2-digit numbers is 9009 = 91 99. | |
Find the largest palindrome made from the product of two 3-digit numbers.") | |
(defn palindromic? | |
[n] | |
(loop [s (seq (str n))] | |
(if (empty? s) |
This file contains hidden or 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
(def ^:private inf (Long/MAX_VALUE)) | |
(defn neighbors | |
"Returns n's neighbors, optionally filtered if unvisited" | |
([g n] (get g n {})) | |
([g n uv] (select-keys (neighbors g n) uv))) | |
(defn update-costs | |
"Returns costs updated with any shorter paths found to curr's unvisisted | |
neighbors by using curr's shortest path" |
This file contains hidden or 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
<?php | |
$data = array( | |
array( | |
'user_id' => 1, | |
'total_score' => 1, | |
), | |
array( | |
'user_id' => 2, | |
'total_score' => 1, |
This file contains hidden or 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
<?php | |
// some math operations | |
$instructions = array( | |
array('*', 2, 4), | |
array('/', 2, 4), | |
array('/', 2, 0), | |
); | |
// compute |
This file contains hidden or 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 'nokogiri' | |
require 'open-uri' | |
require 'colorize' | |
require 'ripl' | |
require 'yaml' | |
class RegexWorkshop | |
def initialize() | |
reset |
This file contains hidden or 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
<?php | |
class TestClass { | |
private $id; | |
public function __construct($id) { | |
$this->id = $id; | |
} | |
public function getPublic() { |
This file contains hidden or 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
<?php | |
function all_gens_valid($gens) { | |
foreach ($gens as $gen) { | |
if (!$gen->valid()) { | |
return false; | |
} | |
} | |
return true; | |
} |
This file contains hidden or 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
<?php | |
function gen_file_lines($filename) { | |
try { | |
$fp = fopen($filename, 'r'); | |
while (($line = fgets($fp)) !== false) { | |
yield $line; | |
} | |
} finally { |