Skip to content

Instantly share code, notes, and snippets.

View apua's full-sized avatar
💭
Seeking next epic moment

Apua Juan apua

💭
Seeking next epic moment
View GitHub Profile
@apua
apua / type_system.rst
Created May 19, 2019 11:28
Julia Type System Note
@apua
apua / code_split_tool.py
Created May 12, 2019 10:28
Julia-like :func:`include` for Python
"""
:func:`include` works like Julia :func:`include` for code splitting.
When a Python code is too large to maintain, it could be split into files,
as well as done in Julia code.
:func:`include` works as Julia built-in :func:`include` to merge code
with given relative path. It is done with Python built-in :func:`exec`
and :mod-attr:`__file__`
"""
@apua
apua / gòngfěi_fish.jl
Last active June 10, 2021 11:05 — forked from fkztw/korean_fish.py
Yet another chatbot
# Julia 1.0.3
buzzwords = (
"自經區", "自貿區",
"摩天輪", "愛情摩天輪", "愛情產業鏈",
"發大財", "愛河的水甘甘", "選總統",
"迪士尼",
"F1", "F1賽車場", "F1 賽車場",
"賭馬", "賽馬",
"九二共識", "一中各表", "一國兩制", "兩岸統一",
)
@apua
apua / xxx.py
Last active January 24, 2019 09:05
# Python unittest
class TestTransactionControl(unittest.TestCase):
def test_create_commit(self):
id_ = self.create()
self.should_have_this_record(id_)
def test_create_rollback(self):
self.request_start()
id_ = self.generate_id()
self.request_fail()
@apua
apua / grouping.hs
Last active January 6, 2019 10:24
find broken lines and merge
module T where
import Test.QuickCheck
import Test.DocTest
-- |
-- >>> grouping [21,5,0,16,21,23]
-- [[21],[5,0,16],[21],[23]]
--
-- >>> all (\g -> sum g >= 21) [[21],[5,0,16],[21],[23]]
@apua
apua / 01_for_loop.py
Created December 3, 2018 01:48
Infinite Recursion by async in Python
f = print
i = 1
while i<9999:
f(i)
i += 1
@apua
apua / game_of_life.py
Last active November 30, 2018 10:37
Game of Life
# ref: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life#Examples_of_patterns
# Python 3.6
import collections
import typing
#import asyncio
Point = collections.namedtuple('Point', ['x', 'y'])
Point.__add__ = lambda self, other: Point(self.x + other.x, self.y + other.y)
@apua
apua / linked_list.c
Last active October 26, 2018 18:50
Learn creating linked list in Rust style
// ref: https://doc.rust-lang.org/rust-by-example/custom_types/enum/testcase_linked_list.html
#include <stdio.h>
#include <stdlib.h>
enum NodeType { Cell, Nil };
typedef struct LinkedList LinkedList;
typedef struct NodeCell {
int car;
@apua
apua / to_matrix.py
Last active October 16, 2018 10:08
1-dim List to 2-dim Matrix
r"""
>>> L = [1,2,3,4,5,6,7]
Imperative
==========
>>> def f(L, c):
... matrix = []
... row = []
@apua
apua / go_hell_cmp.py
Created September 13, 2018 18:19
WTF cmp
def natural_cmp(a, b):
'''
Usage:
list.sort(cmp=util.natural_cmp)
or
sorted_list = sorted(list, cmp=util.natural_cmp)
Sorts by alpha and then by numeric hence lists like:
row1
row2