Skip to content

Instantly share code, notes, and snippets.

@yfwz100
yfwz100 / rollup-plugin-smart-asset#22-package.json
Last active April 11, 2021 11:48
rollup-plugin-smart-asset#22
{
"name": "commonjs-smart-asset",
"version": "1.0.0",
"private": true,
"description": "An example for https://github.com/sormy/rollup-plugin-smart-asset/issues/22 .",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-commonjs": "^18.0.0",
@yfwz100
yfwz100 / genetic_algorithm_example.py
Created December 22, 2016 09:18
An example illustrate the usage of genetic library in python.
# -*- coding: utf-8 -*-
import random
import genetic.individuals import SingleChromosomeIndividual
import genetic.selection import bimodal
import genetic.populations import PanmicticPopulation
# 需要定义 data 变量
@yfwz100
yfwz100 / mlp.py
Created September 7, 2016 03:53
A two-layer perceptron.
import numpy as np
class MLP(object):
def __init__(self, init_r1=0.001, init_r2=0.001, init_hidden_nodes=10, init_max_iter=100000):
self._r1 = init_r1
self._r2 = init_r2
self._hidden_nodes = init_hidden_nodes
self._max_iter = init_max_iter
@yfwz100
yfwz100 / perceptron.py
Last active September 7, 2016 03:52
A simple Perceptron implementation
import numpy as np
class Perceptron(object):
def __init__(self, init_r=0.01, init_max_iter=100000):
# the parameter to optimized.
self._w = None
self._theta = None
@yfwz100
yfwz100 / .vimrc
Created June 7, 2016 09:27 — forked from andyfowler/.vimrc
Swap iTerm2 cursors in vim insert mode when using tmux
" tmux will only forward escape sequences to the terminal if surrounded by a DCS sequence
" http://sourceforge.net/mailarchive/forum.php?thread_name=AANLkTinkbdoZ8eNR1X2UobLTeww1jFrvfJxTMfKSq-L%2B%40mail.gmail.com&forum_name=tmux-users
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
@yfwz100
yfwz100 / ipgw.sh
Last active November 23, 2016 13:31
ipgw.neu.edu.cn
#!/bin/bash
USERNAME= # YOUR USERNAME HERE
PASSWORD= # YOUR PASSWORD HERE
case $1 in
"on")
out=`curl 'https://ipgw.neu.edu.cn/srun_portal_pc.php?ac_id=1&' -H 'Origin: http://ipgw.neu.edu.cn' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,en;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Referer: http://ipgw.neu.edu.cn/srun_portal_pc.php?ac_id=1&' -H 'Connection: keep-alive' -H 'DNT: 1' --data "action=login&ac_id=1&user_ip=&nas_ip=&user_mac=&url=&username=$USERNAME&password=$PASSWORD&save_me=0&ajax=1" --compressed --silent`
if [[ $out == login_ok* ]]; then
echo "登录成功"
@yfwz100
yfwz100 / state_machine.py
Created January 25, 2016 06:50
A simple state machine implementation.
# coding: utf8
class StateMachine(object):
""" A state machine targeting the singleton update process.
A normal workflow will look like:
>>> sm = StateMachine('init')
>>> @sm.state('init')
>>> def init():
@yfwz100
yfwz100 / throttle.coffee
Last active August 31, 2015 15:56
延迟函数执行,降低触发频率。
# 函数节流方案
# 延迟函数执行,降低触发频率
throttle = (fn, intv=500) ->
firstTime = on
timer = null
() ->
args = arguments
if firstTime
@yfwz100
yfwz100 / tictactoe.py
Last active August 29, 2015 14:23
TicTacToe
def agent_utility(board, pos, mark, step=1):
if board[pos] == 0:
board = board.copy()
board[pos] = mark
if step == 1:
return (
-sum(sum(1 if count_nonzero(r==0) + count_nonzero(r==-mark) == 3 else 0 for r in m) for m in [board, board.T, board.flat[[[0, 4, 8], [2, 4, 6]]]]),
sum(sum(1 if count_nonzero(r==0) + count_nonzero(r==mark) == 3 else 0 for r in m) for m in [board, board.T, board.flat[[[0, 4, 8], [2, 4, 6]]]]),
min(min(3-count_nonzero(r==-mark) if count_nonzero(r==0) + count_nonzero(r==-mark) == 3 else 3 for r in m) for m in [board, board.T, board.flat[[[0, 4, 8], [2, 4, 6]]]])
)
@yfwz100
yfwz100 / ScreenCaptureUtil.java
Created April 20, 2014 15:51
Screenshot for Swing Component
import java.awt.BufferedImage;
import java.awt.Component;
import javax.imageio.ImageIO;
/**
* A piece of code describing how to capture the screen of a component.
*
* @author yfwz100
*/