Skip to content

Instantly share code, notes, and snippets.

View phrz's full-sized avatar

Paul Herz phrz

  • Dallas
View GitHub Profile
@phrz
phrz / ordinal.py
Created August 17, 2012 21:00
Returns an English Ordinal Number.
def ordinal(number):
suffix="th"
ones=int(str(number)[-1])
tens=0
if number/10 >= 1:tens = int(str(number)[-2])
if tens != 1:
special = {1:"st",2:"nd",3:"rd"}
try:
suffix = special[ones]
except:
@phrz
phrz / simple.js
Created August 21, 2012 17:07
Some simple jQuery tricks and polyfills.
$(function(){
$('html').removeClass('no-js').addClass('js');
$('[autofocus]').focus();
if("placeholder" in document.createElement("input")) {
$('html').addClass('placeholder');
} else {
$('html').addClass('no-placeholder');
}
@phrz
phrz / istouch.js
Created August 21, 2012 17:09
Detect a touch device in javascript.
function isTouch() {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
}
@phrz
phrz / 960compact.css
Created August 24, 2012 03:09
960 Grid System (12 column) - in very compact CSS
/* BEGIN GRID STYLING */
.prototype {
outline: 1px solid red;
}
.row {
width: 940px;
padding: 0 10px;
margin: 0 auto;
@phrz
phrz / cool.css
Created June 12, 2013 16:28 — forked from anonymous/cool.css
html, body {
font-family: "Futura", sans-serif;
background: hsl(15,100%,50%);
color: #eee;
-webkit-font-smoothing: antialiased;
}
h1 {
text-align: center;
margin: 0 0 0 -10px;
padding: 0;
@phrz
phrz / progressBar.cpp
Created November 11, 2015 18:40
I made a command line progress bar in C++ for funsies
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[]) {
int width = 15;
for(int p = 0; p <= 100; ++p) {
int full = (double)p/100*width;
# not mine, just a backup from https://github.com/altercation/solarized/issues/167
# solarized dark color scheme
# background = solarized base03 = 0 43 54
defaults write TeXShop background_R 0.00
defaults write TeXShop background_G 0.169
defaults write TeXShop background_B 0.212
# commands = solarized red = 220 50 47
defaults write TeXShop commandred 0.86
@phrz
phrz / matplotlibsettings.py
Last active November 20, 2017 21:15
My matplotlib settings
import matplotlib
import seaborn as sns
plt = matplotlib.pyplot
%matplotlib inline
sns.set_style('whitegrid')
matplotlib.rcParams.update({
'figure.figsize': (10, 6), 'font.size': 16, 'axes.labelsize': 20, 'xtick.labelsize': 12,
'ytick.labelsize': 12, 'font.family': 'Helvetica,Arial,sans-serif'
})
%config InlineBackend.figure_format = 'retina'
@phrz
phrz / println.cpp
Last active September 22, 2016 17:49
A println function with variadic parameters for easy debugging-by-printing.
// [CITE] http://coliru.stacked-crooked.com/a/92a50828d6cb6f01
#ifndef _PRINTLN_CPP_
#define _PRINTLN_CPP_
#include <iostream>
template<typename T>
void println(const T& t) {
std::cout << t << std::endl;
@phrz
phrz / random.swift
Last active November 22, 2016 17:32
easy random number function given a Range in Swift 3
import Foundation
func random(_ r: ClosedRange<Int>) -> Int {
let span = abs(r.upperBound-r.lowerBound)
return Int(arc4random_uniform(UInt32(span)))+r.lowerBound
}
print(random(0...3)) // prints either 0, 1, 2, or 3