Skip to content

Instantly share code, notes, and snippets.

View iamken1204's full-sized avatar
👩‍💻
bumped by a crashed etcd cluster

Kettan iamken1204

👩‍💻
bumped by a crashed etcd cluster
  • Taipei, Taiwan
View GitHub Profile
#!/usr/bin/env bash
YESTERDAY=$(date -d 'yesterday' '+%Y-%m-%d')
PID_FILE=/var/run/nginx.pid
LOG_FILE=/data/error.log
OLD_FILE=/data/error-$YESTERDAY.log
mv $LOG_FILE $OLD_FILE
kill -USR1 $(cat $PID_FILE)
@iamken1204
iamken1204 / cidr_match.php
Created March 17, 2017 02:53
Check the given ip is within a specific subnet
<?php
/**
* @reference http://stackoverflow.com/questions/594112/matching-an-ip-to-a-cidr-mask-in-php-5
*/
function cidr_match($ip, $range)
{
list ($subnet, $bits) = explode('/', $range);
$ip = ip2long($ip);
@iamken1204
iamken1204 / php-html-css-js-minifier.php
Created February 14, 2017 02:29 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
// Based on <https://github.com/mecha-cms/extend.minify>
define('MINIFY_STRING', '"(?:[^"\\\]|\\\.)*"|\'(?:[^\'\\\]|\\\.)*\'');
define('MINIFY_COMMENT_CSS', '/\*[\s\S]*?\*/');
define('MINIFY_COMMENT_HTML', '<!\-{2}[\s\S]*?\-{2}>');
define('MINIFY_COMMENT_JS', '//[^\n]*');
define('MINIFY_PATTERN_JS', '\b/[^\n]+?/[gimuy]*\b');
define('MINIFY_HTML', '<[!/]?[a-zA-Z\d:.-]+[\s\S]*?>');
@iamken1204
iamken1204 / ClientIP.php
Last active December 21, 2016 08:45
Client IP getter
<?php
/**
* @phpversion ^7.0
* @see http://devco.re/blog/2014/06/19/client-ip-detection/
*/
class ClientIP
{
private $ip = '';
@iamken1204
iamken1204 / How_to_use_UglifyJS.md
Last active December 19, 2016 07:32
How to use UglifyJS

How to use UglifyJS

  • Step 1
    Update package.json

    • Add "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony" into dependencies.
      (The tag harmony is to enable es6)
    • Add "uglify": "node uf.js" into scripts.
  • Step 2

Keybase proof

I hereby claim:

  • I am iamken1204 on github.
  • I am kettan (https://keybase.io/kettan) on keybase.
  • I have a public key whose fingerprint is A010 0DB8 AABD 7EF1 26A9 BF4F A950 65E8 F795 D5E4

To claim this, I am signing this object:

@iamken1204
iamken1204 / ajax.js
Last active September 20, 2016 08:19
/**!
* ajax - v2.1.2
* Ajax module in Vanilla JS
* https://github.com/fdaciuk/ajax
* Sun May 15 2016 12:45:49 GMT-0300 (BRT)
* MIT (c) Fernando Daciuk
*/
/**
@iamken1204
iamken1204 / ajax.js
Created July 11, 2016 02:44
An AJAX method implemented by Promise().
'use strict'
/**
* Example:
* var returnedData
* function myCallback(data) {
* returnedData = JSON.parse(data)
* }
* ajax('your-api-url')
* .get()
@iamken1204
iamken1204 / youtube.carousel.html
Last active July 9, 2016 04:34
An example of youtube embedded videos in carousel. And on-cick-change video triggers.
@iamken1204
iamken1204 / multi-server.go
Last active June 29, 2016 03:12 — forked from filewalkwithme/main.go
Listening multiple ports on golang http servers
package main
import "net/http"
func main() {
finish := make(chan bool)
server8001 := http.NewServeMux()
server8001.HandleFunc("/foo", foo8001)
server8001.HandleFunc("/bar", bar8001)