Skip to content

Instantly share code, notes, and snippets.

View yeungon's full-sized avatar
💭
In JavaScript we trust

Vuong Nguyen yeungon

💭
In JavaScript we trust
View GitHub Profile
@yeungon
yeungon / convertSheet2Json.gs
Created May 8, 2017 05:54 — forked from daichan4649/convertSheet2Json.gs
spreadsheet のデータを JSON として読み込む(Google Apps Script)
function convertSheet2Json(sheet) {
// first line(title)
var firstRange = sheet.getRange(1, 1, 1, sheet.getLastColumn());
var firstRowValues = firstRange.getValues();
var titleColumns = firstRowValues[0];
// after the second line(data)
var lastRow = sheet.getLastRow();
var rowValues = [];
for(var rowIndex=2; rowIndex<=lastRow; rowIndex++) {
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@yeungon
yeungon / data.php
Created June 3, 2017 05:59
database class
<?php
// Lớp database
class DB
{
// Các biến thông tin kết nối
private $hostname = 'localhost',
$username = 'root',
$password = '',
$dbname = 'newspage';
@yeungon
yeungon / basiclayout.css
Last active June 9, 2017 05:31
left menu and basic layout
@charset "UTF-8";
/*CSS document - Charset kia giúp hiển thị tiếng Việt trong CSS*/
*{
margin: 0px;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
<!DOCTYPE html>
<html>
<head>
<title>Đang học css</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<!-- <link rel="stylesheet" type="text/css" href="ngonngu.css"> -->
</head>
<body>
@yeungon
yeungon / code_edit_wordpress_theme.php
Last active June 28, 2017 04:20
frequently used code for designing Wordpress theme
Đây là những đoạn code bạn sẽ dùng thường xuyên trong quá trình lập trình theme wordpress. Bạn chỉ cần hiểu tác dụng của nó như thế nào sau đó copy và dán nó để chạy thôi. Mình đã viết sẵn cho bạn rồi, không cần phài suy nghĩ chi nhiều nhé he he.
1.Code lấy bài viết mặt định.
PHP:
<!-- Get post mặt định -->
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; else : ?>
<p>Không có</p>
@yeungon
yeungon / validate_email.js
Last active June 28, 2017 04:20
validate email
function validateEmail(strEMail) {
//Validating the email field
var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if (!strEMail.match(reg)) {
return (false);
}
return(true);
}
// source: http://1tudien.com/js/warning.js
@yeungon
yeungon / gist:b9f92b1618560ea6130b6c360541bab8
Created August 1, 2017 14:20 — forked from marcgg/gist:733592
Regex to get the Facebook Page ID from a given URL
# Matches patterns such as:
# https://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/my_page_id => my_page_id
# http://www.facebook.com/#!/my_page_id => my_page_id
# http://www.facebook.com/pages/Paris-France/Vanity-Url/123456?v=app_555 => 123456
# http://www.facebook.com/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/#!/page_with_1_number => page_with_1_number
# http://www.facebook.com/bounce_page#!/pages/Vanity-Url/45678 => 45678
# http://www.facebook.com/bounce_page#!/my_page_id?v=app_166292090072334 => my_page_id
# http://www.facebook.com/my.page.is.great => my.page.is.great
@yeungon
yeungon / [PHP] - sort out email address _ REGEX
Last active August 25, 2017 03:58
[PHP] - sort out email address _ REGEX
$text = "Ngày thử nhất tôi đăng ký một cái email là [email protected], ngày thứ hai tôi đăng ký là [email protected]";
$res = preg_match_all("/[a-z0-9]+[_a-z0-9.-]*[a-z0-9]+@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})/i",$text,$matches);
if ($res) {
// array_unique loại bỏ các phần từ nào trùng nhau
foreach(array_unique($matches[0]) as $email) {
echo $email . "";
}
}
// Kết quả:
@yeungon
yeungon / split unicode-vietnamese string
Created December 5, 2017 01:22
split unicode/vietnamese string
function str_split_unicode($str, $l = 0) {
if ($l > 0) {
$ret = array();
$len = mb_strlen($str, "UTF-8");
for ($i = 0; $i < $len; $i += $l) {
$ret[] = mb_substr($str, $i, $l, "UTF-8");
}
return $ret;
}