Skip to content

Instantly share code, notes, and snippets.

View crazygit's full-sized avatar

Crazygit crazygit

View GitHub Profile
@crazygit
crazygit / ajax_get.js
Last active December 26, 2015 20:39
an example of send an ajax request
nocache = "&nocache=" + Math.random() * 1000000
request = new ajaxRequest()
request.open("GET", "urlget.php?url=oreilly.com" + nocache, true)
// 与post相比, get 请求不需要设置header
request.onreadystatechange = function()
{
if (this.readyState == 4)
{
if (this.status == 200)
@crazygit
crazygit / js_boolean.js
Last active August 29, 2015 13:57
javascript学习笔记
// javascrpt布尔值的类型转换
console.log(Boolean(NaN)); // flase
console.log(Boolean(null)); // false
console.log(Boolean(undefined)); // false
console.log(Boolean(0)); // false
console.log(Boolean([])); // true 注意这里与python不同
console.log(Boolean({})); // true 注意这里与python不同
@crazygit
crazygit / nginx
Last active August 29, 2015 14:14 — forked from vdel26/nginx
#!/bin/bash
#
# chkconfig: 2345 55 25
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
# For Debian, run: update-rc.d -f nginx defaults
# For CentOS, run: chkconfig --add nginx
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
@crazygit
crazygit / save_docker_images
Last active April 6, 2016 13:14
Save all docker images to tar files for copy to another machine
#!/usr/bin/env bash
####################################################################
# Usage:
# Save all docker images to tar files for copy to another machine
####################################################################
images=$(docker images | awk 'NR>1 && $1 != "<none>" {printf("%s:%s\n", $1, $2)}')
for image in $images
do
@crazygit
crazygit / install_go_tools.sh
Last active July 2, 2021 03:16
免翻墙安装Go tools
#!/usr/bin/env bash
# 免翻墙安装Go tools
branch="release-branch.go1.4"
mkdir -p $GOPATH/src/golang.org/x
git clone -b $branch git@github.com:golang/tools.git $GOPATH/src/golang.org/x/tools
git clone git@github.com:golang/net.git $GOPATH/src/golang.org/x/net
cd $GOPATH
go install golang.org/x/tools/cmd/goimports
@crazygit
crazygit / get_autosaling_name.sh
Created April 14, 2017 06:54
get aws ec2 autoscaling group name
# get current ec2 AutoScaling group name
# note: change region option as yours
aws autoscaling describe-auto-scaling-instances --region us-east-1 --output text --query=AutoScalingInstances[].AutoScalingGroupName --instance-ids=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
@crazygit
crazygit / diff_of_scrapy_Compose_and_MapCompse.py
Last active March 13, 2023 15:33
The difference of scrapy built in loader processor Compose and MapComose
from scrapy.loader.processors import Compose, MapCompose
proc = Compose(lambda v: v[0], str.upper)
proc(['hello', 'world']) # HELLO
mproc = MapCompose(lambda v: v[0], str.upper)
mproc(['hello', 'world']) # ['H', 'W']
@crazygit
crazygit / install_gnu_utilities.sh
Last active September 14, 2021 13:43
Use GNU Command Line Tools on macOS/OS X
# Refer: https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
brew install coreutils
brew tap homebrew/dupes
brew install binutils
brew install diffutils
brew install ed --with-default-names
brew install findutils --with-default-names
brew install gawk
brew install gnu-indent --with-default-names
brew install gnu-sed --with-default-names
@crazygit
crazygit / test_put_data_to_aws_firehose.py
Last active May 17, 2017 09:24
Test put data to AWS firehose
import boto3
import json
from datetime import datetime
# 本脚本只适用于适用特定的用户操作Firehose, 模拟角色可以参考
# http://boto3.readthedocs.io/en/latest/reference/services/sts.html#STS.Client.assume_role
# https://gist.github.com/gene1wood/938ff578fbe57cf894a105b4107702de
def list_delivery_streams(client):
response = client.list_delivery_streams(
@crazygit
crazygit / screen-stuff.md
Created August 12, 2017 06:00 — forked from gesellix/screen-stuff.md
screen and Docker for Mac
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty



screen -AmdS docker ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
screen -r docker
# enter, then disconnect with Ctrl-a d
screen -S docker -p 0 -X stuff $(printf root\\r\\n)
screen -r docker