Skip to content

Instantly share code, notes, and snippets.

View phamquocbuu's full-sized avatar
💻

Buu Pham phamquocbuu

💻
View GitHub Profile
$("select :selected").map(function (i, element) { return jQuery(element).text(); }).get();
<?php
$imgData = str_replace(' ','+',$_POST['image']);
$imgData = substr($imgData,strpos($imgData,",")+1);
$imgData = base64_decode($imgData);
// Path where the image is going to be saved
$filePath = $_SERVER['DOCUMENT_ROOT']. '/ima/temp2.png';
// Write $imgData into the image file
$file = fopen($filePath, 'w');
fwrite($file, $imgData);
@phamquocbuu
phamquocbuu / auto.haravan.mark.js
Last active February 23, 2019 04:36
Haravan - Auto scroll and mark as read
n=0;
var time_interval = 1000;
var last_height = 0;
list = $('.scroll-conversation');
function todo(timeout) {
a = setTimeout(
function(){
if (n>40) {
console.log('n = ' + n + ' - DONE');
return false;
@phamquocbuu
phamquocbuu / vietnamese.phonenumber.regex.js
Created October 1, 2018 08:33
Regex matches Vietnamese mobile phone number
(?<=[^0-9]|^)((([0oO][\\.\\- ]?)?[^2][\\.\\- ]?([0-9][\\.\\- ]?){8})|(([0oO][\\.\\- ]?)?1[\\.\\- ]?[2689][\\.\\- ]?([0-9][\\.\\- ]?){8}))(?=[^0-9]|$)
@phamquocbuu
phamquocbuu / bw.email.sh
Created September 28, 2018 08:35
Check server bandwidth and alert by email if it exceeds the limit
#!/bin/bash
MAX=1000
EMAIL=phamquocbuu@gmail.com
EMAIL_FROM=phamquocbuu@gmail.com
DATA=`sar -n DEV 5 5`
USE=`echo "$DATA" | grep 'eth0' | tail -n1 | awk '{print $6}'`
UNIT=`echo "$DATA" | grep 'IFACE' | tail -n1 | awk '{print $6}'`
USE=`echo "$USE/1" | bc`
sar -n DEV 1 3 | grep 'eth0' | tail -n1 | awk '{print $5, $6}'
@phamquocbuu
phamquocbuu / count.sh
Created September 19, 2018 09:30
Count number of files in a folder per day
find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
@phamquocbuu
phamquocbuu / rsync.time.sh
Created September 19, 2018 01:22
rsync files created in timespan
cd /to/path/
rsync -avR --files-from=<(find . -type f -newermt 20170401 ! -newermt 20170530 -exec basename {} \;) . username@SERVER_IP:/path/to/destination/;

Using SET CHARACTER SET utf8 after using SET NAMES utf8 will actually reset the character_set_connection and collation_connection to @@character_set_database and @@collation_database respectively.

The manual states that

SET NAMES x is equivalent to

SET character_set_client = x;
SET character_set_results = x;
@phamquocbuu
phamquocbuu / import.sh
Created August 14, 2018 08:41
GUnzip and import latest database file
find /PATH/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1 | xargs gunzip ;
find /PATH/ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2 | tail -n 1 | perl -pe 'chomp' | xargs cat | mysql -u DB_USER DB_NAME ;