Skip to content

Instantly share code, notes, and snippets.

View kuanyui's full-sized avatar
❄️
なんでそんなに慣れてんだよ!

クエン酸 kuanyui

❄️
なんでそんなに慣れてんだよ!
View GitHub Profile
@kuanyui
kuanyui / max.hs
Last active August 29, 2015 14:07
Recursively exploding head.
-- method 1
maxi :: (Ord a) => [a] -> a
maxi [] = error "Empty list."
maxi [x] = x
maxi (x:xs)
| x > maxTail = x
| otherwise = maxTail
where maxTail = maxi xs
-- method 2
@kuanyui
kuanyui / quicksort.hs
Created October 5, 2014 14:56
Quicksort algorithm with recursive.
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
largerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ largerSorted
# How to Reload Tmux Config:
#
# This can be done either from within tmux, by pressing Ctrl+B and then : to bring up a command prompt, and typing:
#
# :source-file ~/.tmux.conf
#
# Or simply from a shell:
#
# $ tmux source-file ~/.tmux.conf
@kuanyui
kuanyui / replace-elt.lisp
Created November 21, 2014 06:19
[Lisp] Non-destructively replace #N element in list. (recursion way)
(defun rep-elt (list &optional n new)
(cond ((null n)
list)
((> n 0)
(cons (car list) (rep-elt (cdr list) (1- n) new)))
((eq n 0)
(cons new (cdr list))
)))
@kuanyui
kuanyui / gnu_docs.css
Created November 27, 2014 12:41
Stylish for GNU documents
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("www.gnu.org") {
code, kbd {
border-radius: 2px;
padding:1px 10px;
}
code{
color: #006 !important;
background-color: #ddf !important;
}
@kuanyui
kuanyui / views.py
Created May 22, 2015 20:45
既然create view都已經寫這麼多,那有沒有辦法繼承並簡化update view的寫法?
class ProductCreate(StaffuserRequiredMixin, CreateView):
'''
Use URL parameter (GET) to decide if currently is under a category
'''
form_class = ProductForm
template_name = 'console/create_product.html'
submit_title = "建立商品"
def get_context_data(self, *args, **kwargs):
context = CreateView.get_context_data(self, *args, **kwargs)
@kuanyui
kuanyui / login.html
Last active August 29, 2015 14:21
(Unusable) Django AJAX login form.
{# accounts/includes/login.html #}
{% load crispy_forms_tags %}
<h1>Login</h1>
<div class="col-sm-12">
<form class="login-form" method="post">
{% csrf_token %}
{{ form|crispy }}
<button type="submit" class="btn btn-primary">Login!!!!!</button>
</form>
</div>
@kuanyui
kuanyui / find_duplicated_files.py
Last active August 29, 2015 14:24
Find duplicated files via MD5 checksum and output the list as file.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import hashlib, os, sys, math, threading, time, argparse, datetime, sqlite3
# filePath is relative path
# list.append() set.add()
class Hasher(threading.Thread):
def __init__(self, lock, file_walker):
threading.Thread.__init__(self)
@kuanyui
kuanyui / I want to do a form looks like this:
Last active August 29, 2015 14:26
I have a lot of `key: value` pairs to save strings in site, how to use `forms.Form` to make a form like this?
Site Configuration
site_title: ________________
site_subtitle: _________________
admin_email: _________________
admin_phone: _________________
[Save]

此僅為備份,因為原文在Facebook中。 作者:顏華容 https://www.facebook.com/artemis.yen/posts/10207549044542275

一點關於練琴效率的小心得 如果大家有興趣的話,在連假的這幾天可以實驗

實驗材料:沒有彈過的曲子(有沒有聽過無妨,因為聽過你也不見得會彈,哈哈。)

觀察曲式:意思就是說,「它是什麼時代來的誰?」