Skip to content

Instantly share code, notes, and snippets.

var node = {
value: -120,
left: {
value: -2120,
left: { value: -20 },
right: { value: -30 }
},
right: {
value: -20,
left: {value: 20 },
@lamchau
lamchau / add-ip.sh
Last active August 29, 2015 14:17
add IPs to access PostgreSQL remotely (Short URL: http://git.io/hiFi)
#!/bin/sh
# prerequisite: sudo su - postgres
CONFIGURATION_FILE="/etc/postgresql/9.4/main/pg_hba.conf"
CURRENT_IP=$(last -i | grep "still logged" | awk '{ print $3 }')
IPV4_REGEX="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
if [ ! -f "$CONFIGURATION_FILE" ]; then
echo "File not found: $CONFIGURATION_FILE"
exit 1
// do not use result cache, nor line and column tracking
{ var indentStack = [], indent = ""; }
start
= INDENT? lines:( blank / line )*
{ return lines; }
line
= SAMEDENT line:(!EOL c:. { return c; })+ EOL?
@lamchau
lamchau / 0_reuse_code.js
Last active August 29, 2015 14: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
@lamchau
lamchau / clear-quora-notifications.js
Created February 16, 2015 20:32
Clearing notifications on Quora
var clickElement = function(element) {
if (!element) {
return;
}
var event = document.createEvent('HTMLEvents');
event.initEvent('click', true, true);
event.eventName = 'click';
element.dispatchEvent(event);
};

Code Review

A guide for reviewing code and having your code reviewed.

Everyone

  • Accept that many programming decisions are opinions. Discuss tradeoffs, which you prefer, and reach a resolution quickly.
(function(Factory) {
function isInteger(n) {
return typeof n === 'number' &&
isFinite(n) &&
n > -9007199254740992 &&
n < 9007199254740992 &&
Math.floor(n) === n;
}
var SHA_CHARS = '0123456789abcdef';
def message(message, tries)
if tries > 0
puts message + " Please try again. You have #{tries} tries remaining."
else
puts "Game over! :("
end
end
min = 1
max = 100