Skip to content

Instantly share code, notes, and snippets.

View khanhicetea's full-sized avatar
😎
solving human problems

KhanhIceTea khanhicetea

😎
solving human problems
View GitHub Profile
@khanhicetea
khanhicetea / bit-field-permission.php
Created June 20, 2014 16:11
Bit Field Permission Sample PHP
<?php
// Class BitField
class BitField
{
protected $roles = array();
protected $permission;
public function __construct()
{
$this->setPermission(0);
}
@khanhicetea
khanhicetea / auto_recovery_network.md
Last active August 29, 2015 14:05
Auto recovery network settings CentOS if it fails.

Step 1 : Backup working settings folder

cp -R /etc/sysconfig/network-scripts /etc/sysconfig/network-scripts_bak

Step 2 : Create bash file at /root/network.sh with below content

#!/usr/bin/env bash
// Paste this code in to Console
var a = $('.braille-contest-code')[1];
var items = $(a).find('.word');
var m = [];
var map = {
0: 0,
1: 3,
2: 1,
3: 4,
4: 2,
@khanhicetea
khanhicetea / hook.php
Created July 3, 2015 10:48
SQLLog Silex
// Source : https://groups.google.com/d/msg/silex-php/ceKqVPlwLg0/kPkcM5Hx5owJ
if ( $app['debug'] ) {
$logger = new Doctrine\DBAL\Logging\DebugStack();
$app['db.config']->setSQLLogger($logger);
$app->error(function(\Exception $e, $code) use ($app, $logger) {
if ( $e instanceof PDOException and count($logger->queries) ) {
// We want to log the query as an ERROR for PDO exceptions!
$query = array_pop($logger->queries);
$app['monolog']->err($query['sql'], array('params' =>
$query['params'], 'types' => $query['types']));
@khanhicetea
khanhicetea / convert_to_utf8.sql
Created November 16, 2015 11:18
MySQL changing to UTF8
-- Ref : http://stackoverflow.com/a/19301922
SELECT CONCAT("ALTER TABLE `",TABLE_SCHEMA,"`.`",TABLE_NAME,"` CHARACTER SET utf8 COLLATE utf8_unicode_ci;",
"ALTER TABLE `",TABLE_SCHEMA,"`.`",TABLE_NAME,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;")
AS `alter_sql`
FROM `information_schema`.TABLES
WHERE TABLE_SCHEMA = 'db_name';
@khanhicetea
khanhicetea / vst-install-rhel.sh
Created November 20, 2015 11:18
VestaCP-Centos-PHP5.6
#!/bin/bash
# Vesta RHEL/CentOS installer v.05
#----------------------------------------------------------#
# Variables&Functions #
#----------------------------------------------------------#
export PATH=$PATH:/sbin
RHOST='r.vestacp.com'
CHOST='c.vestacp.com'
@khanhicetea
khanhicetea / .bash_alias
Created November 25, 2015 05:15
PHP Security Check Alias
alias php_sec="curl -H 'Accept: text/plain' https://security.sensiolabs.org/check_lock -F lock=@`pwd`/composer.lock"
@khanhicetea
khanhicetea / vietnam_locations.js
Created July 26, 2015 14:14
Vietnam Location Data
{"01":{"id":"01","name":"H\u00e0 N\u1ed9i","type":"Th\u00e0nh Ph\u1ed1","children":{"001":{"id":"001","name":"Ba \u0110\u00ecnh","type":"Qu\u1eadn","location":"21 02 08N, 105 49 38E","parent_id":"01","children":[]},"002":{"id":"002","name":"Ho\u00e0n Ki\u1ebfm","type":"Qu\u1eadn","location":"21 01 53N, 105 51 09E","parent_id":"01","children":[]},"003":{"id":"003","name":"T\u00e2y H\u1ed3","type":"Qu\u1eadn","location":"21 04 10N, 105 49 07E","parent_id":"01","children":[]},"004":{"id":"004","name":"Long Bi\u00ean","type":"Qu\u1eadn","location":"21 02 21N, 105 53 07E","parent_id":"01","children":[]},"005":{"id":"005","name":"C\u1ea7u Gi\u1ea5y","type":"Qu\u1eadn","location":"21 01 52N, 105 47 20E","parent_id":"01","children":[]},"006":{"id":"006","name":"\u0110\u1ed1ng \u0110a","type":"Qu\u1eadn","location":"21 00 56N, 105 49 06E","parent_id":"01","children":[]},"007":{"id":"007","name":"Hai B\u00e0 Tr\u01b0ng","type":"Qu\u1eadn","location":"21 00 27N, 105 51 35E","parent_id":"01","children":[]},"008":{"id":"0
<?php
error_reporting(0);
$filename = __DIR__.preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
return false;
}
define('ROOT_PATH', dirname(dirname(__FILE__)));
@khanhicetea
khanhicetea / phpbox.sh
Last active December 4, 2015 19:03
Ubuntu PHP Box
#!/bin/bash
sudo apt-get update -y
# Add repository
sudo apt-get install -y python-software-properties
sudo add-apt-repository ppa:ondrej/php5-5.6 -y
sudo apt-add-repository ppa:rwky/redis -y
sudo apt-add-repository ppa:chris-lea/node.js -y
sudo apt-get update -y