Skip to content

Instantly share code, notes, and snippets.

View prestonp's full-sized avatar
😍
you had me at hello world

Preston Pham prestonp

😍
you had me at hello world
View GitHub Profile
@prestonp
prestonp / dash.js
Created July 15, 2016 04:12
dash button -> gotem
var get = require('simple-get');
var snuggle = 'a0:02:dc:23:50:30';
var dash_button = require('node-dash-button');
var dash = dash_button(snuggle);
var hornURL = 'http://got-em.mybluemix.net/sounds/horn?room=stacktheplanet';
dash.on("detected", function (){
get(hornURL, (err, res) => {
if (err) return console.log(err);
console.log(new Date().toLocaleString() + ' - triggered horn');
@prestonp
prestonp / main.go
Created July 6, 2016 13:38
middleware pattern go
package main
import (
"log"
"net/http"
"github.com/gorilla/mux"
)
// FooList handles listing foos
<!doctype html>
<html>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<body>
<div id="map"></div>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
</body>
</html>
@prestonp
prestonp / Base64.java
Last active December 21, 2015 21:33
base64 java
import java.io.ByteArrayOutputStream;
public class Base64
{
public static String encode(byte[] data)
{
char[] tbl = {
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
@prestonp
prestonp / .bash_profile
Last active March 29, 2017 22:32
dynamic emoji shell prompt
emoji() {
emojis=("🍕 " "💩 " "🐶 " "🍣 " "🍔 " "🍪 " "🐳 ")
echo ${emojis[$RANDOM % ${#emojis[@]} ]}
}
set_bash_prompt() {
# Define your prompt formatting here
export PS1="\d \t \u:\w\n$(emoji) "
}
@prestonp
prestonp / gist:ad5d1a3f9a026e34c44c
Last active May 13, 2024 11:40
mov to webm osx
@prestonp
prestonp / css.md
Last active September 2, 2015 21:28
css guide

Steps to better css

Step 1

Use normalize.css or a similar css reset. This will make browsers render more consistently.

Step 2

@prestonp
prestonp / pg-remote-access.md
Created June 19, 2015 06:39
enable remote access to postgres

From an authenticated session of Postgres

# show hba_file;
               hba_file
--------------------------------------
 /etc/postgresql/9.3/main/pg_hba.conf
(1 row)
var orderCharge = require('stamps/orders/charge');
db.orders.findOne( id, function (err, order ) {
var charge = orderCharge( order );
// getTotal is from orders/base.js
charge.getTotal();
// getApplicationCut is from orders/charge.js
charge.getApplicationCut();
@prestonp
prestonp / debounce.js
Created June 12, 2015 18:05
debounce
var debounce = function(fn, interval) {
var lock = false;
var id;
return function debouncedFn() {
var args = arguments;
var invoke = function() {
lock = false;
fn.apply(null, args);