Skip to content

Instantly share code, notes, and snippets.

View gabebw's full-sized avatar

Gabe Berke-Williams gabebw

View GitHub Profile
--- /dev/fd/13 2019-06-26 17:28:12.960405019 -0700
+++ /dev/fd/14 2019-06-26 17:28:12.960830329 -0700
@@ -70,7 +70,7 @@
json.AAK.longitude = "173.63699340820312";
json.AAK.name = "Buariki Airport";
json.AAK.timezone = "10";
-json.AAK.tz_name = "\\N";
+json.AAK.tz_name = null;
json.AAL = {};
json.AAL.altitude = "10";
raw_panda = "🐼"
# panda is U+1F43C according to wikipedia
puts raw_panda
puts "\uf09f\u90bc"
# puts "\u2728"
# puts "\ud83d\udc3c".force_encoding("UTF-8")
# puts raw_panda.each_codepoint { |x| p x }
# puts raw_panda.each_byte { |x| p x }
@gabebw
gabebw / bin-setup
Created January 16, 2016 06:43
React setup
#!/bin/sh
# This goes in bin/setup
npm install --save \
gulp \
browserify \
react \
react-dom \
babelify \
@gabebw
gabebw / file.txt
Created September 9, 2015 04:38
LYAH: Ch 9, I/O
Hey there
line two
whoa
{-
The expression problem: Adding new data types and new functionality to
existing data types is at odds.
OOP:
* adding new data types is easy
- just write new code, and adhere to the API
* But adding new functionality to existing data types is hard
-- Added type signatures
module PatternMatching where
import Data.Char (isUpper)
-- `:t even` shows that `even` needs `Integral`, but nothing more precise
-- than that
anyEven :: (Integral a) => [a] -> Bool
anyEven list = not $ null $ filter even list
module PatternMatching where
-- Return the first character of a String, or the question mark character for an
-- empty string.
-- > firstCharacter "hello"
-- 'h'
-- > firstCharacter ""
-- '?'
-- Hint: String is the same as [Char].
firstCharacter :: String -> Char
firstCharacter (c:_) = c
module HeadTailInitLast where
-- middle [1] == []
-- middle [1..6] == [2, 3, 4, 5]
middle :: [a] -> [a]
middle s@(_:_:_:_) = tail $ init s
middle _ = []
-- Maybe more Rubyish:
middle' :: [a] -> [a]
middle' s

Ch 1: Basics

GHCI

  • :l baby to load baby.hs
  • :t (+) to show function type
    • parentheses required for infix functions
  • * is an infix function (because it's punctuation)
    • so 5 * 3 is parsed exactly as * 5 3, which is really (* 5) 3

Lists