View list-comprehension-equivalent.js
// equivalent haskell using list comprehension syntax
// [x^2 | x <- [1..10], rem x 2 == 0]
var list = [];
// no ranges ...
for (var i = 1; i < 11; i += 1) {
list.push(i);
}
View sticky_grid.rb
board = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
while (input = gets.chomp.to_i) != "exit"
board = board.map.with_index do |row, i|
row.map.with_index do |column, ii|
if column == input
"x"
View bind-confusion.hs
-- (>>=) :: Monad m => m a -> (a -> m b) -> m b
-- why are `a` and `b` different? i guess that signature means
-- they _can_ be but don't _need_ to be.
Just 5 >>= (\a -> Just (10 + a)) -- Just 15
View fizzbuzz.js
var ns = [];
for (var i = 0; i <= 100; i += 1) { ns.push(i); }
var fizzes = ns.map(function (member) {
if (member % 15 === 0) {
return 'fizzbuzz';
} else if (member % 3 === 0) {
return 'fizz';
} else if (member % 5 === 0) {
return 'buzz';
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
* {
box-sizing: border-box;
}
View regex-query.sql
-- http://www.petefreitag.com/cheatsheets/postgresql/
SELECT column FROM table WHERE column ~ 'foo.*';
View doseq-with-index.clj
;; https://groups.google.com/d/msg/clojure/cBCf_ftFSw4/xBG_SfMeMBAJ
(doseq [[idx item] (map-indexed vector a-lazy-seq)]
(do-stuff! item idx))
View populate.sh
#!/bin/bash
x=1
while [ $x -le 22222 ]
do
echo "log entry: $x" >> example.log
x=$(( $x + 1 ))
done
View onpaste.js
// re-enable paste on your favorite bank's website
document.querySelectorAll('input').forEach(function (input) {
input.setAttribute('onpaste', '');
});
View polymorphisms.hs
-- The key difference between parametric polymorphism and overloading (aka ad-hoc
-- polymorphism) is that parameteric polymorphic functions use one algorithm to
-- operate on arguments of many different types, whereas overloaded functions may
-- use a different algorithm for each type of argument.
-- John Mitchell, Concepts in Programming Languages
-- http://stackoverflow.com/a/13043262/382982
-- ad hoc/constrained => typeclasses
plus :: (Num a) => a -> a -> a