Skip to content

Instantly share code, notes, and snippets.

taiansu / Main.hs
Last active February 28, 2020 19:30
pattern matching in Haskell
View Main.hs
module Main where
-- data, you can think this is something like {:user, name, age} in Elixir
data User = User String Int
foo (User "John" _) = 100
foo (User _ age) = age
-- tuple
bar (_, _, 3) = 100
taiansu / code_lock.ex
Last active February 11, 2020 06:07
:gen_statem official example in elixir
View code_lock.ex
defmodule CodeLock do
@behaviour :gen_statem
@name :code_lock
# Client API
def start_link(code) do
:gen_statem.start_link({:local, @name}, __MODULE__, code, [])
taiansu /
Created September 24, 2019 21:34 — forked from scottopell/
Fix corrupted exFAT disk macOS/OSX

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

Disk Utility is unable to repair this at first, but the fix is this:

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
taiansu / webpack.config.js
Created May 9, 2019 21:12
Example webpack.config.js
View webpack.config.js
const webpack = require('webpack');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = (env, options) => ({
optimization: {
minimizer: [
taiansu /
Last active December 19, 2019 02:55
JavaScript Expression

什麼是表達式: Expression

最後會回傳一個值 (包括 null) 的 JavaScript 語法

2 // 數字

1 + 1 // 數學運算
taiansu /
Last active April 24, 2020 07:54
webpack+babel configs for React
#!/usr/bin/env bash
# remove this file whenever you don't need it. you need json package to execute the last part.
echo 'installing npm dependencies...'
npm i -s react react-dom prop-types react-hot-loader
echo 'installing npm devDependencies...'
npm i -D @babel/cli @babel/core @babel/plugin-syntax-dynamic-import @babel/preset-env @babel/preset-react babel-loader clean-webpack-plugin html-webpack-plugin webpack webpack-cli webpack-dev-server
echo 'add scripts to package.json...'
json -f package.json -I -e "this.scripts.start=\"webpack-dev-server --mode development --open\""
json -f package.json -I -e "\"webpack --mode production\""
taiansu / data.rb
Last active January 15, 2019 03:58
functional practice
View data.rb
students = [
{age: 18, first_name: "Shane", last_name: "Osbourne"},
{age: 22, first_name: "John", last_name: "Doe"},
{age: 12, first_name: "John", last_name: "Barker"},
{age: 40, first_name: "Ben", last_name: "Haskell"},
{age: 34, first_name: "Ben", last_name: "Barker"},
{age: 9, first_name: "Shane", last_name: "Doe"},
{age: 33, first_name: "Lee", last_name: "Ruby"}
taiansu /
Last active October 27, 2019 15:40 — forked from nicbet/
Sass versions of Bootstrap 4 and Fontawesome 5 with Elixir / Phoenix Framework 1.3 and 1.4 using Webpack

Sass versions of

  • Bootstrap 4
  • Fontawesome 5.5

with Elixir / Phoenix Framework 1.3 and 1.4 using Webpack 4 and Babel 7

taiansu / .dialyzer_ignore.exs
Created July 6, 2018 16:09
Dialyzer ignore for phoenix 1.3.3, Elixir 1.6.6 & OTP 21.0
View .dialyzer_ignore.exs
{":0:unknown_function Function Access.get/3 does not exist."},
{":0:unknown_function Function ArgumentError.exception/1 does not exist."},
{":0:unknown_function Function Ecto.Adapters.Postgres.in_transaction?/1 does not exist."},
{":0:unknown_function Function Ecto.Adapters.Postgres.rollback/2 does not exist."},
{":0:unknown_function Function Ecto.Adapters.SQL.query/4 does not exist."},
{":0:unknown_function Function Ecto.Adapters.SQL.query!/4 does not exist."},
{":0:unknown_function Function Ecto.Adapters.SQL.to_sql/3 does not exist."},
{":0:unknown_function Function Ecto.LogEntry.log/1 does not exist."},
{":0:unknown_function Function Ecto.Repo.Preloader.preload/4 does not exist."},
taiansu / Caesar.hs
Last active May 24, 2018 18:15
Flolac week of code 4: caesar cipher
View Caesar.hs
import Data.List (group, sort, sortOn)
import qualified Data.Map as M
encode :: Int -> String -> String
encode n = fmap (fetchChar . shift . fromEnum) where
shift = (+ n) . subtract 65
fetchChar = (cycle ['A'..'Z'] !!)
decode :: String -> (String, Int)
decode str = fst . head $ sortOn snd matrix where