Skip to content

Instantly share code, notes, and snippets.

@phondanai
phondanai / unicode_decimal_to_image.py
Created June 26, 2017 07:30
Create picture of 'Number, Decimal Digit' from unicode table
import sys
import unicodedata
from collections import defaultdict
from PIL import ImageFont, ImageDraw, Image
# Steal from https://stackoverflow.com/questions/14245893/efficiently-list-all-characters-in-a-given-unicode-category
def number_decimal_digit():
unicode_category = defaultdict(list)
# very expensive here
@phondanai
phondanai / cal-day.lisp
Last active April 5, 2017 05:20
Calculating total days from first day to current day of current year and calculate total saving if save from first day to current day.
(ql:quickload '(ningle clack woo))
(defun current-year ()
(multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(get-decoded-time)
(declare (ignore minute hour date month day-of-week dst-p tz))
year))
(defun current-saving (today_num)
@phondanai
phondanai / oil_price_bangchak.py
Last active February 9, 2017 08:51
Get fuel price from Bangchak web widget, แสดงราคาน้ำมัน บางจาก
from bs4 import BeautifulSoup
import requests
URL = "http://www.bangchak.co.th/oilprice-widget.aspx"
FUEL_TYPE = ["Hi-Diesel",
"Gasohol E85",
"Gasohol E20",
@phondanai
phondanai / longest_sequence.py
Created January 19, 2017 07:13
Stupid solution of print longest sequence of character from string s
s = 'azcbobobegghakl'
result = ''
tmp = ''
for i in range(len(s)-1):
if s[i] <= s[i+1]:
tmp += s[i]
if i == len(s) - 2:
tmp += s[i+1]
if len(tmp) > len(result):
@phondanai
phondanai / clean_srt_file.py
Last active December 9, 2016 08:04
Remove html tag (e.g.. color hex code) from SubRip (.srt) subtitle file
#!/usr/bin/env python3
import re
import sys
import os
def show_help():
print("Usage:")
print(sys.argv[0] + " <input_srt_file>" + " <output_srt_file>")
@phondanai
phondanai / lesson0.4-racket-intro.rkt
Last active September 2, 2022 04:04
Solution of Lesson 0.4 Introduction to Racket from Northeastern University
(require 2htdp/image)
; Ex 3:
; f->c : Real -> Real
; GIVEN: a temperature in degrees Fahrenheit as an argument
; RETURN: the equivalent temperature in degrees Celsius.
; Examples:
; (f->c 32) => 0
; (f->c 100) => 37.7777777777....
(define (f->c x)
@phondanai
phondanai / bulk_courses_delete.sh
Last active January 6, 2017 09:48
Open edX bulk delete multiple courses from input file.
#!/bin/bash
cd /edx/app/edxapp/edx-platform
while read NAME; do { echo 'y' ; echo 'y' ; } | sudo -u www-data /edx/bin/python.edxapp ./manage.py cms \
--settings=aws delete_course $NAME; done < /path/to/course_list_file
@phondanai
phondanai / split_and_count.rkt
Last active September 7, 2016 02:30
Split and count from text input
#lang racket
(define c 0)
(with-input-from-file "/path/to/file"
(thunk
(for ([line (in-lines)])
(set! c
(+ c
(length
@phondanai
phondanai / Vagrantfile
Created July 20, 2015 15:18
Open edX provision script for vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vbguest.auto_update = false
config.vm.define :edx do |edx_config|
edx_config.vm.box = "ubuntu/precise64"
edx_config.vm.hostname = "edx"
@phondanai
phondanai / mag-fix.sh
Created June 9, 2011 11:45
Fix the length of song which download from Magnatune store.
#!/bin/bash
# Fix the length of song which download from Magnatune store.
# mag-fix.sh by Phondanai Khanti
# Work with .ogg only!
# Require package: vorbis-tools
#
# usage: mag-fix.sh /path/to/source.ogg
# For the whole directory example