Skip to content

Instantly share code, notes, and snippets.

require 'ftools'
# DirInit::Manager handles directory initialization and clean-up when
# there are many concurrent processes that wants to modify the
# directory in the same way.
#
# An example usage is when each process wants to copy some temporary
# files to the directory and delete these files after finishing its
# job. Problems may occur when the first process delete the files
# while the second process is still using the files.
# Console login script for Kasetsart University Internet login page.
# It uses Curl to load pages and post data.
# To use it, you need ruby (sure!) and curl installed.
def build_hidden_option_list(html)
list = []
tags = html.scan(/<input[^>]*hidden[^>]*>/)
tags.each do |tag|
res = tag.match(/name='([^']*)' .*value='(.*)'/)
list << [res[1],res[2]]
# Another console login script for Kasetsart University Internet login page.
# This one allows you to login for other machine (by specifying the IP).
# It uses Curl to load pages and post data.
def build_hidden_option_list(html)
list = []
tags = html.scan(/<input[^>]*hidden[^>]*>/)
tags.each do |tag|
res = tag.match(/name='([^']*)' .*value='(.*)'/)
list << [res[1],res[2]]
#!/usr/bin/env ruby
# This script checks the current dir for sass files,
# and if some of them get updated, recompiles it into css.
CHECK_PERIOD = 5 # in seconds
def find_sass_files
return Dir["*.sass"]
end
@jittat
jittat / cat.rb
Created June 16, 2012 17:52
Wikipedia article dump
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'optparse'
DEFAULT_RECURSE_LEVEL = 2
BAD_STARTERS = ['template','portal','user','book']
URL_BASE = 'http://en.wikipedia.org/wiki/'
rlevel = DEFAULT_RECURSE_LEVEL
@jittat
jittat / lcs_len_th.py
Created February 28, 2013 04:21
This code calculates the length of the LCS between two strings. It also deals with Thai digits and roman digits.
def to_roman(a):
if a >= '๐' and a <= '๙':
return chr(ord(a) - ord('๐') + ord('0'))
return a
def is_same_digit(a,b):
if a < '0' and a > '9':
return False
aa = to_roman(a)
@jittat
jittat / classlist.py
Created July 21, 2014 19:50
Load student lists from all sections from regis.ku.ac.th
import sys
import getpass
import requests
import codecs
from bs4 import BeautifulSoup
CAMPUS = 'B'
def login(username, password):
logindata = { 'UserName': username,
def extract_line(line):
"""
>>> extract_line("* hello world")
('hello world', 1)
>>> extract_line("** this is a ** test!!")
('this is a ** test!!', 2)
"""
depth = 0
l = len(line)
while (depth < l) and (line[depth] == '*'):
@jittat
jittat / pepmass.ipynb
Created February 12, 2019 06:01
Pep mass
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jittat
jittat / sokoban.py
Last active February 22, 2019 05:55
Sokoban template
class Box:
def __init__(self,r,c,board):
pass
class Player:
def __init__(self,r,c,board):
pass
def move_up(self):
pass