Skip to content

Instantly share code, notes, and snippets.

@fishtreesugar
fishtreesugar / cn_id.ex
Last active July 3, 2016 08:23
util functions in Elixir for Chinese ID
defmodule CnId do
defp parse!(id) do
<<adcode :: 6-bytes, year :: 4-bytes, month :: 2-bytes, day :: 2-bytes, seq_code :: 3-bytes, check_code :: 1-bytes>> = id
%{
adcode: adcode,
birthday: Date.from_iso8601!("#{year}-#{month}-#{day}"),
seq_code: seq_code,
check_code: check_code
@fishtreesugar
fishtreesugar / ex_tricks.ex
Last active May 20, 2016 04:34
elixir tricks
# Anonymous constructor
(&%{ok: &1}).(1) # => %{ok: 1}
Enum.map 1..5, &{&1, &1 * 2} # => [{1, 2}, {2, 4}, {3, 6}, {4, 8}, {5, 10}]
(&[1|&1]).(2) # => [1 | 2]
#macro
Enum.reduce items, %{}, fn item, map ->
Map.update(map, item, 1, & &1 + 1)
end
@fishtreesugar
fishtreesugar / notes.md
Last active February 22, 2020 15:10
Erik Meijer FP Foundamentals Notes

#Erik Meijer FP Foundamentals Notes

ch1 Introduction & History

  • The next 700 programming languages -- Peter Landin // describede DSL 11:25
  • One-combinator basis for lambda-terms -- Jeroen Fokker // SKI combinator 21:04
  • Static Typing Where Possible, Dynamic Typing When Needed -- Erik Meijer // 24:00

ch2 First Step

  • prove xs = take n xs ++ drop n xs // 7:18
  • F# |&gt; //9:50
#!/usr/bin/env stack
{- stack
--resolver lts-5.11
--install-ghc
runghc
--package wreq
--package text
--package containers
--package lens
-}
#!/bin/bash
# NAME : fscan_v3.sh
# VERSION : v3
# AUTHOR : FTS
# Example : sudo bash fscan_v3.sh 2008 2010 3001 3002 1 6
# $1 lower-grade
# $2 upper-grade
# $3 lower-major