Skip to content

Instantly share code, notes, and snippets.

View roylee0704's full-sized avatar
🧘‍♂️

roylee0704

🧘‍♂️
  • Bangkok, Thailand
View GitHub Profile
const now = new Date();
const utcNow = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
// A js Date object stores 2 primitive values: x and tz, based on y. For instance: new Date(y); IF y = NULL, y = machine time.
// - y = machine time (x + tz)
// - tz = machine tz. i.e: +8
// - console.log(now.toString()) returns (x + tz);
@roylee0704
roylee0704 / Makefile
Created April 10, 2017 11:43 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config
configfile=config.env
ifdef cnf
configfile=$(cnf)
endif
include $(configfile)
export $(shell sed 's/=.*//' $(configfile))
# import deploy config
deployfile=deploy.env
@roylee0704
roylee0704 / dq.go
Created March 12, 2017 11:16
dynamo query
as := dynamo.New(sess, &aws.Config{Region: aws.String("ap-southeast-1")})
t := as.Table("Dev_Beam")
type SpMeta struct {
Distance float64 `dynamo:"distance"`
}
type beam struct {
TaskID int `dynamo:"task_id"` // Hash key, a.k.a. partition key
SpIDTimestamp string `dynamo:"sp_timestamp"` // Range key, a.k.a. sort key
@roylee0704
roylee0704 / gist:250b313e17d596b54b93a87098ae6085
Created March 8, 2017 12:54
what to do if intelli-sense not working
http://stackoverflow.com/questions/34423746/gocode-external-package-give-no-suggestion-for-vscode
INSERT INTO `gb_m_incentive_program` (`name`, `allow_multiple_per_cycle`, `priority`, `amount`, `criteria`, `created_at`, `updated_at`, `is_deleted`, `is_active`, `currency`, `iteration`, `cycle`, `duration`, `execution_count`, `current_iteration`, `current_cycle`, `starts_at`, `expires_at`, `next_run`, `prev_run`, `is_running`, `timezone`, `bonus`, `duration_unit`)
VALUES
(9, 'Incentive Milestone (Round 2)', 0, 1, 0.00, '{\"conditions\":[{\"table\":\"gb_m_task AS t\",\"columns\":[\"t.sp_id\"],\"count\":\"t.task_id AS score\",\"joinRaw\":[{\"value\":\"INNER JOIN gb_m_sp s ON s.sp_id = t.sp_id\"}],\"where\":[{\"column\":\"stage\",\"op\":\"=\",\"value\":\"6\"},{\"column\":\"overall_status\",\"op\":\"=\",\"value\":\"100\"},{\"column\":\"t.sp_id\",\"op\":\"is not\",\"value\":null},{\"column\":\"t.created_at\",\"op\":\">=\",\"var\":\"scandate_lower_bound\"},{\"column\":\"s.sp_type\",\"op\":\"=\",\"value\":0},{\"column\":\"t.created_at\",\"op\":\"<\",\"var\":\"scandate_upper_bound\"}],\"groupBy\":\"t.sp_id\",\"hav
@roylee0704
roylee0704 / git.plugin.zsh
Created February 7, 2017 04:33
oh-my-zsh/plugins/git/git.plugin.zsh
# Query/use custom command for `git`.
zstyle -s ":vcs_info:git:*:-all-" "command" _omz_git_git_cmd
: ${_omz_git_git_cmd:=git}
#
# Functions
#
# The name of the current branch
# Back-compatibility wrapper for when this function was defined herea in
@roylee0704
roylee0704 / 0_reuse_code.js
Created January 20, 2017 08:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@roylee0704
roylee0704 / laravel_start.bat
Created January 20, 2017 08:13
lavarel setup
cd ~/Homestead
vagrant up
@roylee0704
roylee0704 / is_time_based.sql
Last active February 7, 2017 09:10
check is within period/time_frame if is_time_based = 1
SELECT *
FROM gb_m_promo p
LEFT JOIN gb_n_promo_period t ON p.promo_code = t.promo_code
WHERE TRUE
AND CASE WHEN is_time_based = 1 THEN CURTIME() BETWEEN from_time AND to_time ELSE TRUE END;
# time diff
@roylee0704
roylee0704 / unique.sql
Created January 9, 2017 15:49
unique constraints
ALTER TABLE `gb_n_incentive` ADD CONSTRAINT `sp_id` UNIQUE `sp_id` (`sp_id`,`incentive_program_id`,`term_weeks`);
ALTER TABLE `gb_n_incentive` DROP INDEX `sp_id`;