Skip to content

Instantly share code, notes, and snippets.

View tigerhawkvok's full-sized avatar

Philip Kahn tigerhawkvok

View GitHub Profile
@tigerhawkvok
tigerhawkvok / pandoc_convert.command
Created November 12, 2016 19:19
Convert all HTML files into Markdown files in a given directory
#!/bin/bash
find . -type f -iregex .*\.html$ | while read line
do
printf 'Converting >>>%s<<<\n' "$line"
P_MD=${line%".html"}.markdown
pandoc --ignore-args -r html -w markdown < "${line}" | awk 'NR > 130' | sed '/<div class="site-info">/,$d' > "${P_MD}"
done
@tigerhawkvok
tigerhawkvok / StringUnescaper.coffee
Last active March 4, 2016 21:04
Unescape even fairly mutilated escaped string in Javascript
String::unescape = (strict = false) ->
###
# Take escaped text, and return the unescaped version
#
# @param string str | String to be used
# @param bool strict | Stict mode will remove all HTML
#
# Test it here:
# https://jsfiddle.net/tigerhawkvok/t9pn1dn5/
#
@tigerhawkvok
tigerhawkvok / stringify.js
Last active December 27, 2015 23:39
Stringify implementation -- played with after speaking with Andrew about it
function stringify(o) {
var c=new Array;
$.each(o,function(key,val){
if(typeof(val)!='object' || Array.isArray(val)) c.push(clean(key)+':'+clean(val));
else c.push(clean(key)+':'+stringify(val));
});
return "{"+c.join(",")+"}";
}
function clean(string) {
return escape(string).split('"').join('\"');
@tigerhawkvok
tigerhawkvok / polymerHelper.coffee
Created July 28, 2015 04:21
Workaround for lack of paper-dropdown
bindPaperMenuButton = (selector = "paper-menu-button", unbindTargets = true) ->
###
# Use a paper-menu-button and make the
# .dropdown-label gain the selected value
#
# Reference:
# https://github.com/polymerelements/paper-menu-button
# https://elements.polymer-project.org/elements/paper-menu-button
###
for dropdown in $(selector)
@tigerhawkvok
tigerhawkvok / README.md
Last active August 29, 2015 14:23
EBV Shipping estimator

Hey guys!

I've showed most of you guys this, but here's the breakdown:

http://eastbayvivarium.com/shipping-estimator.html

First things first, enter the weight of the animal. It defaults to grams, but tapping the toggle will change the entry to pounds.

@tigerhawkvok
tigerhawkvok / api.php
Created June 10, 2015 05:24
Easypost Integration
<?php
/***
* Target file for asynchronous hits
***/
if(isset($_SERVER['QUERY_STRING'])) parse_str($_SERVER['QUERY_STRING'],$_GET);
require_once('./core/core.php');
<!-- BROWSE HAPPY BEGINS HERE -->
<style>
.browsehappy {
display:block;
width:100%;
height:100px;
background-color:#f2dede;
margin: 0 0 10px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 22px;
@tigerhawkvok
tigerhawkvok / core.coffee
Last active August 29, 2015 14:22
Core Coffeescript helper functions
# Set up basic URI parameters
# Uses
# https://github.com/allmarkedup/purl
try
uri = new Object()
uri.o = $.url()
uri.urlString = uri.o.attr('protocol') + '://' + uri.o.attr('host') + uri.o.attr("directory")
uri.query = uri.o.attr("fragment")
catch e
console.warn("PURL not installed!")
@tigerhawkvok
tigerhawkvok / loadJS.coffee
Created May 27, 2015 20:20
Load Javascript file after page load
loadJS = (src, callback = new Object(), doCallbackOnError = true) ->
###
# Load a new javascript file
#
# If it's already been loaded, jump straight to the callback
#
# @param string src The source URL of the file
# @param function callback Function to execute after the script has
# been loaded
# @param bool doCallbackOnError Should the callback be executed if
@tigerhawkvok
tigerhawkvok / toTitleCase.coffee
Last active August 29, 2015 14:22
CoffeeScript toTitleCase
String::toTitleCase = ->
# From http://stackoverflow.com/a/6475125/1877527
str =
@replace /([^\W_]+[^\s-]*) */g, (txt) ->
txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
# Certain minor words should be left lowercase unless
# they are the first or last words in the string
lowers = [
"A"