Skip to content

Instantly share code, notes, and snippets.

View TheGU's full-sized avatar
🎯
Focusing

Pattapong J. TheGU

🎯
Focusing
  • 021
  • Bangkok, Thailand
  • X @thegu
View GitHub Profile
@TheGU
TheGU / URLSequenceShortener.js
Created June 16, 2015 02:47
Create shorten URL like counting in base 62
var shortener = function(seq) {
var new_str = "";
var chars = "abcdefghijklmnopqrstuvxzwyABCDEFGHIJKLMNOPQRSTUVXZWY1234567890";
while (seq > 0) {
var k = seq % chars.length;
if (k == 0) {
k = 62;
seq--;
}
seq = Math.floor(seq / chars.length);
@TheGU
TheGU / crawl_and_download.py
Last active August 29, 2015 14:27
a script to crawl a page then download all file to local disk (http://pattapongj.com/2015/08/11/python-crawler-and-download/)
# -*- coding: utf-8 -*-
import requests
import re
import urlparse
import urllib
import os
from bs4 import BeautifulSoup
base_url = "http://downloads.khinsider.com/game-soundtracks/album/patapon-2"
crawl_link_string = "Download"
@TheGU
TheGU / uploader.go
Created September 11, 2015 10:07
Golang to upload file to google drive with progress bar using Google API
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
@TheGU
TheGU / ssl_patch.py
Created February 19, 2017 09:08
Monkey patch for CERTIFICATE_VERIFY_FAILED when using urllib
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
@TheGU
TheGU / tumblr_unfollow_inactive_blog.py
Last active August 6, 2017 21:25
Python 3 script to unfollow inactive tumblr blog. You can specific numbers of inactive days to unfollow. Set CONSUMBER KEY and CONSUMBER SECRET then run a script and follow the step.
#!/usr/bin/env python
# pip install oauth2
# oauth2==1.9.0.post1
import oauth2 as oauth
from urllib.parse import urlparse, parse_qsl, urlencode
import json
from datetime import datetime,timedelta
# Number of inactive days of blog to unfollow
@TheGU
TheGU / ubuntu_show_ip.sh
Created August 4, 2017 10:24
Show Ip on login screen after Ubuntu boot / auto set in rc.local to show new ip every boot up
sed -i "/^exit 0/ilsb_release -d | awk '{ print \$2 \" \" \$3 \" \" \$4 \" \\\\\\\n \\\\\\\l\" }' > /etc/issue " /etc/rc.local
sed -i "/^exit 0/i/sbin/ifconfig | grep \"inet addr\" | grep -v \"127.0.0.1\" | awk '{ print \$2 }' >> /etc/issue " /etc/rc.local
sed -i "/^exit 0/i\\\n" /etc/rc.local
@TheGU
TheGU / setup_mac.sh
Last active February 2, 2024 17:02
Setup mac (brew,git, zsh with prezto, iterm2 and default app)
#!/bin/bash
# Brew : The missing package manager for macOS
# https://brew.sh/
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Git
brew install git
git config --global core.autocrlf input
@TheGU
TheGU / upgrade_openssh_openssl.sh
Created February 1, 2019 02:21
Upgrade openssh and openssl on rhel6
#!/bin/bash
# Prepare folder
mkdir -p /app/ssh_upgrade && cd /app/ssh_upgrade
# Get openssl source file : openssl-1.0.2q.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2q.tar.gz
# Get openssh source file : openssh-7.7p1.tar.gz
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.7p1.tar.gz
@TheGU
TheGU / s3_upload.py
Created February 19, 2021 00:36
Upload to AWS S3 then recheck content with md5 hash
import os
import boto3
import botocore
import hashlib
def md5sum(filepath):
hash = hashlib.md5()
with open(filepath, "rb") as f:
for chunk in iter(lambda: f.read(128 * hash.block_size), b""):
@TheGU
TheGU / setup_windows_powerline.md
Last active March 26, 2022 10:09
Setup Oh-My-Posh powerline on Windows 10