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 / 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 / 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;
@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;
# 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 / 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 / Digits.swift
Last active November 22, 2016 17:26
Returns an array of the digits of an Int
import Foundation
extension Int {
var digits: [Int] {
return String(self).characters.map{Int(String($0))}.flatMap{$0}
}
}
@phrz
phrz / RepeatCharacter.swift
Created November 22, 2016 17:31
Repeat a character string or really any string with the multiplication operator
import Foundation
extension String {
static func *(_ s: String, _ i: Int) -> String {
guard i > 0 else { return "" }
return String(repeating: s, count: i)
}
}
print("a"*3) // prints "aaa"
@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