Skip to content

Instantly share code, notes, and snippets.

View shelwinnn's full-sized avatar
😄

Shelwin Wei shelwinnn

😄
View GitHub Profile
<?php
/**
* 加密 hash,生成发送给用户的 hash 字符串
*
* @param array $hash_data
* @param string $hash_key
* @return string
*/
function encode_hash($hash_data, $hash_key = false)
// expires方法的参数是以秒为单位的,其他的方法跟localStorage的相同
// 方法有:getItem/setItem/removeItem/clear/expires
// 30秒后过期
storage.setItem("test","hello world").expires(30);
storage.setItem("test","hello world");
storage.expires(30);
// clear全部由storage创建的localStorage
@shelwinnn
shelwinnn / gist:b3a13eefbf4a3bfb4308
Last active August 29, 2015 14:26 — forked from romainneutron/gist:5340930
Download large files using Guzzle
<?php
use Guzzle\Http\Client;
require __DIR__ . '/vendor/autoload.php';
$tmpFile = tempnam(sys_get_temp_dir(), 'guzzle-download');
$handle = fopen($tmpFile, 'w');
$client = new Client('', array(
Client::CURL_OPTIONS => array(
@shelwinnn
shelwinnn / crawl.py
Last active July 6, 2016 07:52 — forked from venkat/crawl.py
Using gevent to crawl 100 links given a seed link, based off of http://blog.hownowstephen.com/post/50743415449/gevent-tutorial
# monkey-patch
import gevent.monkey
gevent.monkey.patch_all()
import gevent.pool
import gevent.queue
import sys
import re
import requests
FIELDS = ['cmd', 'command', 'start', 'end', 'delta', 'msg', 'stdout', 'stderr']
def human_log(res):
if type(res) == type(dict()):
for field in FIELDS:
if field in res.keys():
encoded_field = res[field].encode('utf-8')
print '\n{0}:\n{1}'.format(field, encoded_field)
@shelwinnn
shelwinnn / findport.sh
Created December 24, 2015 13:00 — forked from lusentis/findport.sh
bash script to find a free port to listen to
#!/bin/bash
#
# Please run as root.
# Usage: bash findport.sh 3000 100
#
if [[ -z "$1" || -z "$2" ]]; then
echo "Usage: $0 <base_port> <increment>"
exit 1

An Ansible summary

Patterns

  • all (or *)
  • hostname: foo.example.com
  • groupname: webservers
  • or: webservers:dbserver
  • exclude: webserver:!phoenix
  • intersection: webservers:&amp;staging
@shelwinnn
shelwinnn / golang_job_queue.md
Created April 3, 2018 04:04 — forked from harlow/golang_job_queue.md
Job queues in Golang
@shelwinnn
shelwinnn / karabiner_switch_input_source.json
Created November 7, 2022 13:28 — forked from gxfxyz/karabiner_switch_input_source.json
Karabiner-Elements config: switch input source | 输入法切换
{
"title": "Switch input source | 输入法切换",
"rules": [
{
"description": "Tap Command_L (⌘) → Switch input source to English | 短按左 Command (⌘) → 切换到英文输入法",
"manipulators": [
{
"conditions": [
{
"input_sources": [