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()
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
"""
module mydjangolib.bigint_patch
A fix for the rather well-known ticket #399 in the django project.
Create and link to auto-incrementing primary keys of type bigint without
having to reload the model instance after saving it to get the ID set in
the instance.
Logs:
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<h1 class="text-center login-title">Sign in to continue to Bootsnipp</h1>
<div class="account-wall">
<img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
alt="">
<form class="form-signin">
<input type="text" class="form-control" placeholder="Email" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
# requires python 3.2.3 or higher
import concurrent.futures
def f(x):
print ("working on task: %s" %{x})
if x-1 > 0 :
return x-1 # I want this task back in the queue.
def main():
Queue = [x for x in range(4)]