Skip to content

Instantly share code, notes, and snippets.

View donamkhanh's full-sized avatar

Do Nam Khanh donamkhanh

View GitHub Profile
{
"title": "Takeout API",
"discoveryVersion": "v1",
"ownerName": "Google",
"version_module": true,
"resources": {
"exports": {
"methods": {
"get": {
"flatPath": "v2/{service}/exports/{exportId}",
@donamkhanh
donamkhanh / WebRtcPeer.js
Created July 2, 2018 14:43
Fix bug show black video on Safari when using kurento-utils.js
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
if (isSafari) {
if (constraints.offerToReceiveAudio) {
pc.addTransceiver('audio');
}
if (constraints.offerToReceiveVideo) {
pc.addTransceiver('video');
}
@donamkhanh
donamkhanh / yearview.js
Created June 4, 2018 12:08
YearView for fullcalendar v3.6.1
var YearView = View.extend({ // make a subclass of View
startDate: null,
endDate: null,
days: [],
initialize: function() {
// called once when the view is instantiated, when the user switches to the view.
// initialize member variables or do other setup tasks.
},
@donamkhanh
donamkhanh / route.php
Created December 27, 2016 08:02
Logical division demo for API versioning
<?php
Route::group(['prefix' => 'v1.1'], function () {
Route::get('users', function () {
// Matches The "/v1.1/users" URL
});
});
Route::group(['prefix' => 'v2.0'], function () {
Route::get('users', function () {
// Matches The "/v2.0/users" URL
@donamkhanh
donamkhanh / list_sizes_of_mysql_db.sql
Created August 8, 2016 10:24
List sizes of MySQL databases
SELECT table_schema AS "Database name", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;
@donamkhanh
donamkhanh / m2-deploy.sh
Last active August 9, 2016 02:21
Scripts for deploying Magento2
#!/bin/sh
echo "Switch to working folder"
cd /var/www/
echo "Pulling latest code"
sudo git reset --hard origin/master && sudo git pull
echo "Running Magento 2 deployment script..."
echo "Removing ./var/generation, ./var/view_preprocessed and ./pub/static folders..."
@donamkhanh
donamkhanh / gist:b5e024f2025768f0b0cba93d62edb99b
Created June 25, 2016 03:31 — forked from adrienne/gist:3180103
Haversine formula (PHP/MySQL)
/**
* Generates the string for the Haversine function. We assume that the `zipcode`, `latitude`,
* and `longitude` columns are named accordingly. We are also not doing much error-checking
* here; this is a simple text cruncher to make things prettier.
* We may also be integrating some extra SQL in, passed in via the $extra parameter
*
* @param string $table The table to search in
* @param float $lat The latitude part of the reference coordinates
* @param float $lng The longitude part of the reference coordinates
* @param int $radius The radius to search within
@donamkhanh
donamkhanh / migrate.sh
Created May 17, 2016 08:27 — forked from dj1020/migrate.sh
Upgrade MAMP to Mysql 5.7 tested by Ken Lin 2015/11/09
#!/bin/sh
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.9-osx10.10-x86_64.tar.gz
tar xfvz mysql-5.7*
echo "stopping mamp"
sudo /Applications/MAMP/bin/stop.sh
sudo killall httpd mysqld
echo "creating backup"
UPDATE callbacks cb
INNER JOIN clients c
ON c.id = cb.client_id
SET cb.client_user_id = c.user_id
@donamkhanh
donamkhanh / xskt_scraping.php
Last active January 7, 2016 16:18
Extract lottery number of xskt.com.vn from 01/01/2015 to present
<?php
date_default_timezone_set('Asia/Ho_Chi_Minh');
include_once __DIR__ . '/simple_html_dom.php';
// Connecting, selecting database
$host = '127.0.0.1';
$user = 'root';
$pass = 'root';
$dbName = 'lottery';