Skip to content

Instantly share code, notes, and snippets.

View narate's full-sized avatar

Narate Ketram narate

View GitHub Profile
@narate
narate / README.md
Last active August 29, 2015 13:57
purge -- force disk cache to be purged (flushed and emptied)

สร้างไดเรคทอรี่ $HOME/bin

เปิด Terminal แล้วทำตามนี้

$ mkdir -p $HOME/bin

สร้างไฟล์ $HOME/bin/free-mem

$ touch $HOME/bin/free-mem

ใส่โค้ด free-mem.sh ไปใน $HOME/bin/free-mem ให้ copy โค้ด free-mem.sh จะ command + C หรือ คลิกขวา copy ก็ได้ เอาให้ครบ

@narate
narate / CountChars.java
Created June 19, 2014 09:43
Count chars in Java
import java.util.Random;
public class CountChars {
static char[] chars;
static int[] count;
static String[][] graph;
public static void main(String args[]) {
chars = new char[100];
count = new int[26];
rand_char(chars);
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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