Skip to content

Instantly share code, notes, and snippets.

@philip-goh
philip-goh / bridge_postgres.sh
Created June 14, 2020 08:22
Access PostgreSQL running on your host from within WSL2
#!/bin/bash
socat -d -d TCP-LISTEN:5432,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5432
@philip-goh
philip-goh / promise_test.js
Created April 25, 2018 08:29
Javascript promises and exception handling
// Just a simple test to see how exception handling works in a promise.
function someFunc() {
return new Promise((fulfil, reject) => {
fulfil("This is from a promise");
});
}
someFunc()
.then(res => {
console.log(`Result: ${res}`);
@philip-goh
philip-goh / convert.cu
Created July 21, 2013 19:02
CS344 Udacity Problem Set 1 solution. The tricky bit is working out the x and y offsets in the kernel.
// Homework 1
// Color to Greyscale Conversion
//A common way to represent color images is known as RGBA - the color
//is specified by how much Red, Grean and Blue is in it.
//The 'A' stands for Alpha and is used for transparency, it will be
//ignored in this homework.
//Each channel Red, Blue, Green and Alpha is represented by one byte.
//Since we are using one byte for each color there are 256 different
@philip-goh
philip-goh / update_packages.py
Created October 16, 2012 20:06
Update all python packages
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
@philip-goh
philip-goh / enable_trim.sh
Created October 13, 2012 18:37
Enable trim on Mountain Lion
#!/bin/bash
#This script is based on the instructions presented on:
#http://digitaldj.net/2011/07/21/trim-enabler-for-lion/
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4D)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
sudo touch /System/Library/Extensions/
@philip-goh
philip-goh / CMakeLists.txt
Created October 12, 2012 18:09
A basic cmake template that creates a minimal project
cmake_minimum_required(VERSION 2.6)
#Create an executable called Minimal that depends on minimal.cpp. Additional source files
#should be space separated.
add_executable(Minimal minimal.cpp)
project(Minimal)
#Tell the compiler to link to the static runtime
add_definitions(-static)
#Define preprocessor macro to get boost::threads working on Windows
@philip-goh
philip-goh / screen_grab.cpp
Created October 10, 2012 13:54
Take a screenshot and write it out as a JPEG in C++ on Windows
#include <iostream>
#include <windows.h>
#include <gdiplus.h>
#include <memory>
using namespace Gdiplus;
using namespace std;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{