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
@khanhicetea
khanhicetea / gmail_imap_dump_eml.py
Last active November 5, 2018 17:13 — forked from robulouski/gmail_imap_dump_eml.py
Gmail IMAP Exporter Tool
#!/usr/bin/env python
#
# Very simple Python script to dump all emails in an IMAP folder to files.
# This code is released into the public domain.
#
# RKI Nov 2013
#
import sys
import imaplib
import getpass
@khanhicetea
khanhicetea / Singleton.md
Created May 2, 2015 04:14
Design Patterns

Intent

  • Ensure that only one instance of a class is created.
  • Provide a global point of access to the object.

Implementation

Singleton Diagram

class Singleton
{
// 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 / 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
@khanhicetea
khanhicetea / Unlike-all-fanpage-on-FB.md
Last active December 11, 2017 12:48
Unlike all fanpages on Facebook
  1. Go to FB Wall > View Activity Log > Likes > Pages and Interests
  2. Scroll to the end of log (more log more pages could be unliked)
  3. Open Console (F12 > Tab Console)
  4. Paste this code to console and Enter.
var links = $$('._42ft._42fu._4-s1._2agf._p._42gx');
var i = 0;

unlike_all = function () {
 links[i].click();
@khanhicetea
khanhicetea / nginx.conf
Created November 5, 2015 07:26
NginX https redirect ( Cloudflare's flexible ssl )
server {
listen 80;
server_name example.com www.example.com;
if ($http_x_forwarded_proto = "http") {
return 301 https://$server_name$request_uri;
}
... directives to generate a response
}
@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';