Skip to content

Instantly share code, notes, and snippets.

View daxeh's full-sized avatar

Adrian Teh daxeh

  • Sydney, Australia
  • 19:49 (UTC +10:00)
View GitHub Profile
@daxeh
daxeh / after_res_hooks.js
Created November 26, 2017 00:33 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups
@daxeh
daxeh / cheatsheet-heroku-deploy
Last active November 24, 2017 12:11
Adhoc NodeJS static server
heroku login
heroku create your-app-name
## Existing .git
git push heroku master
## create instance
heroku ps:scale web=1
## your-app-name.herokuapp.com
@daxeh
daxeh / common_divisors.php
Last active November 24, 2017 12:12
Print a list of common divisors given two integers.
<?php
// Print a list of common divisors given two integers.
function generate($min, $max) {
// Base case: max >= min > 1
if ($min <= 1 || $min > $max) {
return;
}
// A divisor if, max modulo min has 0 remainder, print it.
echo $max % $min == 0 ? " $min " : '';
// A Unit test template for Tape
// See 5 Questions every unit test must answer:
// https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d
import test from 'tape';
test('What are you testing?', assert => {
const msg = 'what should it do?'
const actual = 'what was the output?';
@daxeh
daxeh / .htoprc
Created September 17, 2017 12:48
htop rc file
fields=0 48 17 18 38 39 40 2 46 47 49 1
sort_key=39
sort_direction=0
hide_threads=0
hide_kernel_threads=0
hide_userland_threads=0
shadow_other_users=0
highlight_base_name=0
highlight_megabytes=1
highlight_threads=0
@daxeh
daxeh / awake.applescript
Created July 21, 2017 15:21
OSX Automator Applescript prevent computer from sleeping. Simplified interaction with auto-dismiss prompt and notification
on run {input, parameters}
set clickedValue to "Continue"
repeat while clickedValue is not "Don't Continue"
display notification "Executing command 'caffeinate -t 9600' " with title "Awake Notification" subtitle "Caffeinate started."
if (do shell script "caffeinate -t 9600") is "" then
set theDialogText to "Awake duration ended. Would you like to continue?"
set theDialog to display dialog theDialogText giving up after 5 buttons {"Don't Continue", "Continue"} default button "Continue"
set clickedValue to button returned of theDialog
end if
@daxeh
daxeh / fish.nanorc
Created July 2, 2017 00:43
nanorc syntax highlighting for .fish files
set tabsize 2
set tabstospaces
syntax "fish" "\.fish$"
## Blocks
color brightwhite,blue "\<(function|begin|end)\>"
## Structure
color brightblue "\<(switch|case|if|else|do|while|for|in|begin|return|end)\>"
@daxeh
daxeh / Lockscreen.app
Last active July 29, 2017 11:36
OSX Automator: Applescript to lock screen by suspending system to login window
on run {input, parameters}
display dialog "Click 'Continue' to lock screen." giving up after 5 buttons {"Cancel", "Continue"} default button "Continue" cancel
button "Cancel"
--> Result: {{button returned:"Continue", gave up:true}
return input
end run
on run {input, parameters}
do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend"
@daxeh
daxeh / docker-sh.fish
Created June 6, 2017 01:53
Docker: fish command bash_profile to running container
function docker-sh
if count $argv > /dev/null
command docker exec -ti $argv bash
else
echo "Usage: docker-sh CONTAINER_ID"
end
end