Skip to content

Instantly share code, notes, and snippets.

View carlcarl's full-sized avatar

Carl Huang carlcarl

View GitHub Profile
@carlcarl
carlcarl / exercise.tour.go
Created May 4, 2017 02:43 — forked from zyxar/exercise.tour.go
tour.golang exercise solutions
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)
@carlcarl
carlcarl / cheatsheets.md
Created March 30, 2017 10:30 — forked from JustinTW/cheatsheets.md
Linux 大量檔案操作 Cheatsheets (最快速的方法蒐集)

產生檔案

產生 1000 個 500kb 的隨機檔案

for i in {1..100000}; do head -c 500 /dev/urandom > dummy$i; done

產生隨機內容大檔案 (1G)

@carlcarl
carlcarl / graceful_auto_reconnect.py
Created July 10, 2016 17:46 — forked from anthonywu/graceful_auto_reconnect.py
Gracefully handle a PyMongo AutoReconnect
import functools
import pymongo
import logging
import time
MAX_AUTO_RECONNECT_ATTEMPTS = 5
def graceful_auto_reconnect(mongo_op_func):
"""Gracefully handle a reconnection event."""
@functools.wraps(mongo_op_func)
@carlcarl
carlcarl / what-forces-layout.md
Created April 13, 2016 16:40 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@carlcarl
carlcarl / README.md
Created April 11, 2016 05:29
README template

$project

$project will solve your problem of where to start with documentation, by providing a basic explanation of how to do it easily.

Look how easy it is to use:

import project

Get your stuff done

Nginx使用者請看這
由於Let's Encrypt的安裝程式目前還沒有提供nginx模組(其實有在開發,只是還在測試階段),我們依舊可以透過安裝程式自動取得certification後,手動更新nginx的設定黨即可。
首先,我們先取得免費的憑證:
# 如果nginx正在執行中,請先把它關閉
$ sudo -s
$ service nginx stop
$ ./letsencrypt-auto certonly --email 你的email@你的email.net -d freessl.csie.io
@carlcarl
carlcarl / install_wifi_access_point.sh
Created November 4, 2015 14:30 — forked from dashohoxha/install_wifi_access_point.sh
How to setup a Wifi Access Point on Ubuntu 12.04 (or its derivatives).
#!/bin/bash
### Setup a wifi Access Point on Ubuntu 12.04 (or its derivatives).
### make sure that this script is executed from root
if [ $(whoami) != 'root' ]
then
echo "
This script should be executed as root or with sudo:
sudo $0
"
# 日本語用
$ sudo apt-get install libncursesw5-dev
# ソースコード取得
$ git clone https://github.com/jonas/tig.git
$ cd tig
$ git checkout -b my-build-2.0.1 tig-2.0.1
# ビルド, インストール
$ LDLIBS=-lncursesw CFLAGS=-I/usr/include/ncursesw make install prefix=$HOME/local
# http://www.coder4.com/archives/1589
scheduler = sched.scheduler(time.time, time.sleep)
def event(action_time):
print 'action_time:%s' % (action_time)
scheduler.enterabs(action_time + 5, 1, event, (action_time + 5,))
inittime = time.time()
@carlcarl
carlcarl / heart.css
Last active August 29, 2015 14:15
Heart css
.heart{
position: relative;
width: 200px;
height: 200px;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
background-color: #FF7E7E;