Skip to content

Instantly share code, notes, and snippets.

View tonkla's full-sized avatar
🏠
Working from home

Surakarn Samkaew tonkla

🏠
Working from home
View GitHub Profile
@tonkla
tonkla / httpSrc.directive.ts
Created September 2, 2017 04:07
httpSrc.directive.ts
import { Directive, ElementRef, Input, OnInit } from '@angular/core';
import { Http, Headers, RequestOptionsArgs, ResponseContentType } from '@angular/http';
import { AuthenticationService } from '../services';
@Directive({ selector: '[httpSrc]' })
export class HttpSrcDirective implements OnInit {
@Input('httpSrc') url: string;
constructor(private el: ElementRef, private http: Http, private authService: AuthenticationService) {}
@tonkla
tonkla / whois
Created March 13, 2017 05:38
Batch WHOIS lookup
#!/bin/bash
if [ "$#" == "0" ]; then
echo "You need to supply at least one argument!"
exit 1
fi
DOMAINS=('.com' '.net' '.org')
ELEMENTS=${#DOMAINS[@]}

Keybase proof

I hereby claim:

  • I am tonkla on github.
  • I am tonkla (https://keybase.io/tonkla) on keybase.
  • I have a public key ASDrxFwTdCyuuJHtwdhv4JQXe6Nfmv79AU9wnjHidGf-AQo

To claim this, I am signing this object:

@tonkla
tonkla / round.go
Last active January 28, 2017 13:10
Go's math.Round(num float64, precision int)
func Round(num float64, precision uint) float64 {
pow := math.Pow(10, float64(precision))
n := int((num * pow) + math.Copysign(0.5, num))
return float64(n) / pow
}
@tonkla
tonkla / blogelf.thor
Created March 15, 2012 15:01
Blog migration script. Migrate from MySQL to Markdown text file (Jekyll).
require 'rubygems'
require 'erb'
require 'mysql2'
require 'thor'
class Blogelf < Thor
desc 'migrate', 'Migrate from MySQL to Markdown text file (Jekyll)'
def migrate
Dir.mkdir('_posts') unless Dir.exist?('_posts')
db = Mysql2::Client.new(host: 'localhost', username: 'root', database: 'blogelf')
@tonkla
tonkla / drupal_to_rails_db_migration.thor
Created November 1, 2011 16:32
Thor script is used to migrate blog posts from Drupal to Rails
#! /usr/bin/env thor
require 'mysql2'
class Tonkla < Thor
desc 'migrate', 'migrate tonkla.com\'s blog posts from Drupal to Rails'
def migrate
db_from = Mysql2::Client.new(host: 'localhost', username: 'root', database: 'tonkla_com')
db_to = Mysql2::Client.new(host: 'localhost', username: 'root', database: 'klass_blog_development')
result = db_from.query('SELECT r.title, r.body, n.created AS created_at, r.timestamp AS updated_at