Skip to content

Instantly share code, notes, and snippets.

@ii0
ii0 / gist:751697b29b750d6fafb1df8e23bbd430
Created November 1, 2016 05:45 — forked from hSATAC/gist:5343225
Http Redirect in Golang
package main
import (
"log"
"net/http"
)
func redirect(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "http://www.google.com", 301)
@ii0
ii0 / phantom.js
Created August 22, 2016 06:29 — forked from Breefield/phantom.js
PhantomJS Custom Headers
var page = require('webpage').create();
// User-Agent is supported through page.settings
page.settings.userAgent = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25';
// This is how you set other header variables
page.customHeaders = {'Referer': 'localhost'};
@ii0
ii0 / gist:be0aa35feca85556a6ef50f8fc1d2ca1
Created April 29, 2016 10:27 — forked from mdeous/gist:823821
example: parsing html with lxml and xpath
import lxml.html
html = lxml.html.parse("http://pypi.python.org/pypi") # can take an url, a filename or an object with a .read() method
packages = html.xpath('//tr/td/a/text()') # get the text inside all "<tr><td><a ...>text</a></td></tr>"
print packages
Out[7]:
[u'celery\xa02.2.3',
u'django-celery\xa02.2.3',
u'kombu\xa01.0.3',
@ii0
ii0 / gist:b5bbc540d4f9d4091841f863fade6624
Created April 25, 2016 15:02 — forked from palexander/gist:2975305
Compiling and running mosh on Dreamhost
# Thanks to @samsonjs for the cleaned up version:
# https://gist.github.com/samsonjs/4076746
PREFIX=$HOME
VERSION=1.2.3
# Install Protocol Buffers
wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2
tar -xf protobuf-2.4.1.tar.bz2
cd protobuf-2.4.1
@ii0
ii0 / Linux 常用命令锦集.md
Created April 25, 2016 02:58 — forked from dotku/Linux 常用命令锦集.md
Linux 相关的内容
  1. 查看版本

     # Finding your kernel release
     $ uname -r
     > 3.16.0-34-generic
     
     # Finding your distribution release
     $ lsb_release -a
     > Distributor ID: Ubuntu  
    

> Description: Ubuntu 14.10

@ii0
ii0 / gist:024bef19f8626e36f3bdf9fbceb6026f
Created April 19, 2016 03:06 — forked from iwanbk/gist:2295233
TCP Echo Client in Golang
package main
import (
"net"
"os"
)
func main() {
strEcho := "Halo"
servAddr := "localhost:6666"
tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
@ii0
ii0 / http_get.go
Created April 8, 2016 05:24 — forked from ijt/http_get.go
Example of using http.Get in go (golang)
package main
import (
"fmt"
"http"
"io/ioutil"
"os"
)
func main() {
@ii0
ii0 / gist:2387bd801aec6890f2e58932833d154b
Created April 3, 2016 17:41 — forked from mattetti/gist:3798173
async fetching of urls using goroutines and channels
package main
import (
"fmt"
"net/http"
"time"
)
var urls = []string{
"http://pulsoconf.co/",
@ii0
ii0 / search.php
Created March 15, 2016 07:45 — forked from antirez/search.php
<?
require("redis.php");
require("json.php");
$term = $_GET['term'];
$r = new Redis("127.0.0.1","6379");
$r->connect();
$items = $r->zrangebylex("kernel","[$term","[$term\xff",Array("LIMIT","0","10"));
@ii0
ii0 / RedisPythonPubSub1.py
Created February 3, 2016 03:48 — forked from jobliz/RedisPythonPubSub1.py
A short script exploring Redis pubsub functions in Python
import redis
import threading
class Listener(threading.Thread):
def __init__(self, r, channels):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()
self.pubsub.subscribe(channels)