Skip to content

Instantly share code, notes, and snippets.

@luochen1990
luochen1990 / shareAP.bat
Created April 8, 2015 02:50
Windows上创建WIFI热点 共享网络连接
netsh wlan show drivers
netsh wlan set hostednetwork mode=allow ssid=SharedAP key=12345678
netsh wlan start hostednetwork
@echo 创建虚拟网卡成功后,需要共享当前的Internet连接:
@echo -- 打开[网络和共享中心]
@echo -- 点击[更改适配器设置]
@echo -- 右键{你现在上网用的连接,如'本地连接'}
@echo -- 点击[属性]
@echo -- 点击[共享]
@luochen1990
luochen1990 / most-used-regex.coffee
Last active February 15, 2017 01:51
Most Used Regex in JavaScript
capitalize = (s) -> s.replace /(?:_|^)([a-z])/g, (_, c) -> c.toUpperCase() # 'hello_world' to 'HelloWorld'
uncapitalize = (s) -> s.replace /([A-Z])/g, (_, c) -> '_' + c.toLowerCase() # 'HelloWorld' to 'hello_world'
is_chinese_char = (c) -> /[\u4E00-\u9FA5\uF900-\uFA2D]/.test c
//c++11
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#include <assert.h>
#include <ctime>
#include <cstdio>
#include <functional>
import Data.List
import Data.Function
import Control.Monad
groupOn f = groupBy ((==) `on` f) . sortBy (compare `on` f)
uniq = map (!! 0) . groupOn id
-- 场景:假设a得到了数字x,b得到了数字y
-- 可看做二分图,其中possibleX,possibleY是顶点,possible是边,(aGuessY x)和(bGuessX y)分别表达x点和y点的邻接点集
possibleX = [4..198]
import Data.List
import Data.Function
import Control.Monad
groupOn f = groupBy ((==) `on` f) . sortBy (compare `on` f)
uniq = map (!! 0) . groupOn id
-- 场景:假设a得到了数字x,b得到了数字y
-- 可看做二分图,其中possibleX,possibleY是顶点,possible是边,(aGuessY x)和(bGuessX y)分别表达x点和y点的邻接点集
possible = [(5, 15), (5, 16), (5, 19), (6, 17), (6, 18), (7, 14), (7, 16), (8, 14), (8, 15), (8, 17)]
@luochen1990
luochen1990 / aggregator.coffee
Last active August 29, 2015 14:20
stream data aggregator
require 'coffee-mate/global'
compareDictOn = (f) ->
(da, db) ->
[da, db] = [f(da), f(db)]
for k, va of da
vb = db[k]
if (not vb?) or (va < vb)
return -1
else if (not va?) or (va > vb)
@luochen1990
luochen1990 / 2048.hs
Created June 27, 2015 14:42
2048 game in Haskell
{-# LANGUAGE ForeignFunctionInterface #-}
import System.Console.ANSI (clearScreen)
import Data.Char
import Foreign.C.Types
import Prelude hiding (Left, Right)
import GHC.Exts (groupWith, sortWith)
import Control.Arrow
import System.Random
import System.IO
import Data.Hashable
isPrime x = all (\p -> x `mod` p /= 0) . takeWhile ((<= x) . (^ 2)) $ primes
primes = 2 : 3 : filter isPrime [5..]
@luochen1990
luochen1990 / BinarySearch.hs
Last active October 14, 2020 09:03
Binary Search in Haskell
module BinarySearch(binarySearch, discreteBinarySearch, continuousBinarySearch) where
binarySearch :: ((a -> a -> Bool), (a -> a -> a)) -> (a, a) -> (a -> Bool) -> Maybe a
binarySearch (closeEnough, mid) (x0, x1) f = if y0 == y1 then Nothing else Just (iter x0 x1 y0 y1) where
(y0, y1) = (f x0, f x1)
iter x0 x1 y0 y1 = if closeEnough x0 x1
then (if y0 then x0 else x1)
else
let
xm = mid x0 x1
@luochen1990
luochen1990 / kochSnowflake.hs
Created January 14, 2017 09:46
The koch Snowflake implementation (with bmp exports)
{-# language NoMonomorphismRestriction #-}
import Control.Monad
import Test.QuickCheck hiding (scale)
import Codec.BMP
import qualified Data.ByteString
import Data.Word
--------------------- Point & Vec etc ----------------------
type Scalar = Double