Skip to content

Instantly share code, notes, and snippets.

@taiansu
taiansu / goldbach.hs
Last active May 12, 2018 11:07
Flolac week of code 3: goldbach
goldbach :: Int -> Maybe(Int, Int)
goldbach n = search halfOfPrimes where
search [] = Nothing
search (x:xs) = if isPrime (n - x) then Just (x, n - x) else search xs
halfOfPrimes = 2 : [ x | x <- [3, 5..half], isPrime x]
half = div n 2
isPrime :: Int -> Bool
isPrime 2 = True
isPrime n = not $ any isFactor (2 : [3, 5 .. (square n)])
<li class='fruits'>Apple</li>
<li class='fruits'>Banana</li>
<li class='fruits'>Coconut</li>
<li class='fruits'>Cherry</li>
<li class='fruits'>Pear</li>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8" />
<title>Dom sample page</title>
<link rel="stylesheet" href="../css/main.css"/>
<style>
.found-element
{
border: 2px solid #000000;
@taiansu
taiansu / histogram.hs
Last active May 12, 2018 08:44
Flolac week of code 2: histogram
module Histogram where
import Data.List (unfoldr, foldl')
histogram :: [Int] -> String
histogram = addFootter . unlines . graph . tally where
addFootter s = s ++ "==========\n0123456789\n"
tally :: [Int] -> [(Int, Int)]
tally = foldl' accu ary where
ary = zip [0..9] (repeat 0)
@taiansu
taiansu / nub.hs
Last active May 12, 2018 08:45
Flolac week of code 1: nub
nub' :: [Int] -> [Int]
nub' = foldr f [] where
f x xs
| x `elem` xs = xs
| otherwise = x:xs
-- without using `elem`
nub'' :: [Int] -> [Int]
nub'' = foldr f [] where
f x xs
@taiansu
taiansu / food.ex
Last active March 29, 2018 18:42
Food Functional
defmodule Food do
def reduce([], _), do: "😵"
def reduce(foods, f), do: Enum.reduce(foods, f)
def eat(_, "💀"), do: "💀"
def eat(stuff, _) do
if is_food(stuff), do: "💩", else: "💀"
end
def is_food(_), do: true # implement yourself
@taiansu
taiansu / 0_Outline.md
Last active March 24, 2019 04:21
Install Elixir and phoenix

Elixir 安装導覧

我們將安裝下列項目:

  1. Elixir
  2. Node.js
  3. Postgresql 資料庫
  4. Phoenix

由於 macOS 及 linux 可以使用 asdf 這個語言版本管理器,所以我們將介紹用它來安裝 elixir 及 nodejs 的方式。而 Windows 則會使用 chocolatey 來安裝。

@taiansu
taiansu / karabiner.json
Created January 23, 2018 07:18
karabiner switch input method
{
"description": "Left Command to Switch Input Source",
"manipulators": [
{
"conditions": [
{
"type": "input_source_if",
"input_sources": [
{
"language": "en"
defmodule RescueDemo do
def main do
data
|> wrapper_action
|> follow_up_function
end
def wrapper_action(data) do
try do
dangerous_action(data)
@taiansu
taiansu / math.md
Last active November 15, 2016 06:50

前題

  • [2..9] and [2..9]
  • 小明(積)
  • 小華(和)

step 1: 小明說積為_偶數_,代表老師告訴他的值可能是以下這些

4, 6, 8, 10, 12, 14, 16, 18,