Skip to content

Instantly share code, notes, and snippets.

View lancetw's full-sized avatar
🐈

Hsin-lin Cheng lancetw

🐈
View GitHub Profile
@lancetw
lancetw / gist:01a2ed683021a2cee4b7
Last active August 29, 2015 14:01
each / inject / each_with_object
class String
def count_words
h = Hash.new(0)
self.downcase.gsub(/[[:punct:]]/, '').split.each { |w| h[w] += 1 }
return h
end
end
#print 'a b c d e a b a a b c d d e f'.count_words #=> {"a"=>4, "b"=>3, "c"=>2, "d"=>3, "e"=>2, "f"=>1}
<div class="ctrl clearfix">
<a href="/m/main/mypage.jsp" class="btn btn-default pull-right">取消</a>
<a class="btn btn-primary pull-right" href="talk.jsp?Username=xxx">改傳訊息</a>
<a class="btn btn-warning pull-right" href="sticker.jsp?Username=xxx">改傳貼圖</a>
</div>
====Detecting hime install====
==>Hime binary found.
==>/usr/bin/hime: version 0.9.10 (git b745493), linked to /usr/lib/libgtk-x11-2.0.so.0
==>/usr/share/doc/hime/ChangeLog: 0.9.10
====Detecting OS/Distribution====
Linux 3.19.3-3-ARCH #1 SMP PREEMPT Wed Apr 8 14:10:00 CEST 2015 x86_64 GNU/Linux
原文
ループが書けなくなる(或いは再帰依存症)レベル10
http://d.hatena.ne.jp/yuki_neko_nyan/20090217/1234850409
level 0
不會寫遞迴,也沒辦法用遞迴思考。只覺得用迴圈寫就好了。
level 1
開始學習遞迴,但只要一用遞迴思考就覺得煩。有時還會忘了寫終止條件。覺得實在太麻煩了還是想寫迴圈就好。
import request from 'superagent'
import {
SIGNUP_USER_STARTED,
SIGNUP_USER_COMPLETED,
SIGNUP_USER_FAILED
} from 'shared/constants/ActionTypes'
import { auth } from 'shared/actions/AuthActions'
export function submit (form) {
return async dispatch => {
export function login (form) {
return async dispatch => {
dispatch({ type: AUTH_USER_STARTED })
try {
const res = await auth(form)
if (res && res.token) {
setToken(res.token)
return dispatch({
type: AUTH_USER_COMPLETED,
token: res.token
export async function auth (form) {
return new Promise((resolve, reject) => {
request
.post('/api/v1/login')
.set('Accept', 'application/json')
.auth(form.email, form.password)
.end(function (err, res) {
if (!err && res.body) {
resolve(res.body)
} else {
#include <iostream>
/* C++ 14 */
int main(void) {
auto add = [](auto x, auto y) {return x + y;};
printf("%d", add(1,2));
}
#include <iostream>
#include <string>
using namespace std;
#ifdef _WIN32
#include <windows.h>
void _sleep(unsigned int milliseconds)
{
// borrow from react-redux-starter-kit
// https://github.com/davezuko/react-redux-starter-kit
export function createConstants (...constants) {
return constants.reduce((acc, constant) => {
return Object.assign({}, acc, { [constant]: constant })
}, {})
}
export function createReducer (initialState, reducerMap) {