Skip to content

Instantly share code, notes, and snippets.

View narate's full-sized avatar

Narate Ketram narate

View GitHub Profile
@narate
narate / nginx.conf
Created November 30, 2015 14:55
Simple nginx config with lua script
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
proxy_cache_path /data/cache/page levels=1:2 keys_zone=python:10m max_size=1g inactive=5m;
server {
access_log logs/access.log;
listen 8080;
lua_code_cache off;
@narate
narate / get-wrk-script.py
Last active October 28, 2015 10:55
Generate urls for wrk lua script
#!/usr/bin/env python
#-*-coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
from urlparse import urlparse
import urllib2
import json
import sys
import re
@narate
narate / school.py
Last active October 22, 2015 10:53
Thaischool.in.th sitemap scrapy spider.
# -*- coding: utf-8 -*-
import scrapy
from thaischool.items import ThaischoolItem
class SchoolSpider(scrapy.Spider):
name = "school"
allowed_domains = ["thaischool.in.th"]
base_url = 'http://www.thaischool.in.th/sitemap.php?page=%s&school_area=&province_id=&txtsearch='
start_urls = []
for i in range(1,236):
@narate
narate / fbbot.py
Created September 9, 2015 11:06
Get all html meta tag with facebookexternalhit/1.1 user agent
#!/usr/bin/env python
from BeautifulSoup import BeautifulSoup
import urllib2
import sys
if len(sys.argv) < 2 :
print 'Usage : fbbot.py URL'
exit()
http = urllib2.build_opener()
@narate
narate / one_line_json.lua
Created August 29, 2015 14:23
Just one line json
#!/usr/bin/env luajit
-- author : Narate Ketram
-- github.com/narate
-- usage :
--[[
echo '
{
"query": {
"bool": {
@narate
narate / parse_json
Last active August 29, 2015 14:14
Command line JSON parser.
#!/usr/bin/env luajit
-- author : Narate Ketram
-- github.com/narate
-- $ echo '{"name":"narate"}' | parse_json name
-- "narate"
local cjson = require 'cjson.safe'
local data = io.read('*all')
local json = cjson.decode(data)
@narate
narate / exif
Created December 17, 2014 11:00
Show EXIF of image using $ identify -format %[exif:*] /path/to/image/file
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage : $ exif /path/to/file"
exit
fi
echo "EXIF of `basename $1`"
identify -format %[exif:*] $1
@narate
narate / pretty_json.py
Last active September 30, 2016 00:06
Pretty print JSON from stdin. Code base from @aborigines [https://github.com/aborigines]. Base on this story on facebook -> https://www.facebook.com/koonnarate/posts/10202501031914513
#!/usr/bin/python
import sys
import json
data = sys.stdin.read()
json_data = json.loads("".join(data))
json_string = json.dumps(json_data, sort_keys=True, indent=4, ensure_ascii=False)
print(json_string)
@narate
narate / ws-log.html
Created August 7, 2014 07:57
Simple WebSocker listener
<!DOCTYPE html>
<html>
<head>
<style>
#logs_content {
border: 1px solid red;
width:98%;
height: 480px;
position:relative;
@narate
narate / apt-get
Last active August 29, 2015 14:04
Mac OS X software update command line tools for Debian/Ubuntu user!
#!/bin/bash
action=$1
if [[ "$action" == "update" ]]; then
softwareupdate -lv
elif [[ "$action" == "upgrade" ]]; then
softwareupdate -iva
else
echo "No action for $action"
fi