Skip to content

Instantly share code, notes, and snippets.

View tongrhj's full-sized avatar

Jared Tong tongrhj

View GitHub Profile
@tongrhj
tongrhj / instructions.md
Last active July 20, 2018 06:46
Yarn 1.9.0 Custom Formula for Homebrew (brew)

To install

brew unlink yarn

brew install https://gist.githubusercontent.com/tongrhj/5604a804cc133bf54753343737d19141/raw/cac5605d352fe97848140c6d933f96f31e987122/yarn.rb
@tongrhj
tongrhj / chatbot-resources.md
Last active July 13, 2018 03:05
List of chat bot & conversational assistants frameworks (Singapore)
* http://simplicable.com/new/accidental-complexity-vs-essential-complexity
* The Imposter's Handbook
* Grokking Algorithms
@tongrhj
tongrhj / gist:29fcb988ad64a3f3925c2482cbdc7357
Created January 13, 2017 04:55
boolean-matrix-answer-ruby.rb
=begin
Given a 2-dimensional matrix mat[M][N] of size M X N containing only the values 0 and 1, modify it such that if a matrix cell mat[i][j] is 1 then all the cells of ith row and jth column are set to 1 as well.
Example 1
The matrix
1 0
0 0
should be changed to following
@tongrhj
tongrhj / regex.js
Last active December 22, 2016 07:05
Email Validator Regex
function isEmail (str) {
return str ? /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/.test(str) : false
}
const test = require('ava')
const sinon = require('sinon')
test('validate#isEmail returns true if unicode emails', t => {
t.true(isEmail('💩+तфâ.πüñó1@ӕ.昭字'))
})
@tongrhj
tongrhj / macOS-instructions.txt
Last active December 15, 2016 05:34
How to find current wifi password from command line
security find-generic-password -D 'AirPort network password' -wa 'INSERT SSID NAME HERE'
@tongrhj
tongrhj / gist:04fa0495915b2bc5e8fe6a611875f292
Created October 11, 2016 06:16
Liquid Variable to calculate relative days left
<div><span style="font-size: 12px; color: #999999; line-height: 125%;">* {% if offer.expiry_date %}{% assign expiry_timestamp = (offer.expiry_date | date: '%s') %}{% assign now_timestamp = (now | date: '%s') %}{% assign seconds_apart = (expiry_timestamp | minus: now_timestamp) %}{% assign days_apart = (seconds_apart | divided_by: 86400 ) %}Current offer expires on {{ offer.expiry_date | date: '%-d %b %Y' }}<strong>{% if 2 &lt;= days_apart &lt;= 6 %} ({{ days_apart}} days left){% elsif days_apart == 1 %} (tomorrow){% else %} (today){% endif %}</strong>.{% endif %} Offers may change from time to time.</span>
</div>
@tongrhj
tongrhj / redux-practice.js
Last active August 30, 2016 05:17
Getting Started With Redux
// Practice Exercise to Accompany Egghead Course by Dan Abramov Getting Started with Redux
const alphabets = Array.from('abcdefghijklmnopqrstuvwxyz')
const abcSnake = (state = ['a'], action) => {
deepFreeze(state)
switch (action.type) {
case 'APPEND':
return appendToSnake(state)
@tongrhj
tongrhj / example.js
Last active August 4, 2016 09:48
Bomberman
var matrix = [[1,0,0], [0,0,0]]
function bomber(i, j) {
var selectedCell = matrix[i][j]
if (selectedCell != 1) return
matrix.forEach((elem, idx, array) => {
console.log(elem)
elem.splice(j, 1, 1)
})
var arrayLength = matrix[i].length
@tongrhj
tongrhj / solution.js
Created February 26, 2016 15:44
Hackertrail Fixx Digital Code Challenge Feb 2016
// bake your code here
importPackage(java.io);
importPackage(java.lang);
var stdin = new BufferedReader(new InputStreamReader(System['in']));
var numberOfPackets = parseInt(stdin.readLine(), 10);
while (numberOfPackets >= 1) {
var totalCandies = 0;
var candyPackets = [];
var numberOfMoves = 0;