Skip to content

Instantly share code, notes, and snippets.

View billspat's full-sized avatar

Pat Bills billspat

View GitHub Profile
@billspat
billspat / bs_button_helper.rb
Created June 5, 2013 17:56
Rails view helpers for bootstrap links and buttons with icons
# bootstrap button helpers, iconified
# known to work with gem "bootstrap-sass", ">= 2.3.0.0"
def iconified_link_to(icon, body, url, html_options = {})
# not a button, see below
link_to url, html_options do
"#{content_tag(:i, nil, :class => icon.to_s )}  #{body}".html_safe
end
end
@billspat
billspat / loc_shortner.rb
Created June 11, 2013 11:05
simple class to shorten addresses and location descriptions
class LocShortener
@@shortening_file = 'shortening.yaml'
@@shortenings = {}
yamlstr = File.read(@@shortening_file)
YAML.load(yamlstr).each {|k,v| @@shortenings[Regexp.new(k,Regexp::IGNORECASE)] = v}
class << self
def shortenings
@@shortenings
#!/bin/bash
unload() {
kextstat | grep "org.virtualbox.kext.VBoxUSB" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxUSB
kextstat | grep "org.virtualbox.kext.VBoxNetFlt" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxNetFlt
kextstat | grep "org.virtualbox.kext.VBoxNetAdp" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxNetAdp
kextstat | grep "org.virtualbox.kext.VBoxDrv" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxDrv
}
load() {

Requirements

  • bootstrap with typeahead
  • jquery

Explanation

This will use bootstrap with typeahead to create an autocomplete search.

#!/usr/bin/env ruby
# very simple csv to xml convert, targeted for ruby 2.0 +
# depends on activesupport 4 gem which add #to_xml method to hash and array
require 'csv'
require "active_support/core_ext"
if ARGV.length < 1 || ARGV[0] == "-h"
puts "usage : ruby csv2xml.rb myfile.csv > myfile.xml"
@billspat
billspat / dbf2csv.py
Created April 14, 2015 19:06
simplistic conversion of DBF to CSV. See docstring in code for usage
#!/usr/bin/env python
"""dbf2csv.py
DRAFT 4/14/2015 PS Bills, ICER
example python code to read DBF and write to standard CSV.
Requires dbfread python package installed ( http://dbfread.readthedocs.org )
and Python 2.7 or greater
Example usage :
python dbconvert.py MYFILE.DBF
@billspat
billspat / test_numpy.py
Last active January 5, 2016 07:07 — forked from osdf/test_numpy.py
#!/usr/bin/env python
import numpy
import sys
import timeit
try:
import numpy.core._dotblas
print( 'FAST BLAS')
except ImportError:
print( 'slow blas')
@billspat
billspat / underscorify.sh
Created December 10, 2015 05:20
simple bash script to replace non-alphanumerics with underscores, probably written a million times before this.
#!/bin/bash
# examine all files names in current directory and emit a 'mv' command to rename
# if the filename has non alphanumeric in it, other than dot or underscore
# first loop all files, could use find for this, since loop isn'te recursive
for f in *.*; do
# if filename has bad chars
if [[ $f =~ [^a-zA-Z0-9_\.] ]]; then
@billspat
billspat / fixnames.py
Created January 23, 2016 13:54
make os x files windows friendly
# fix names
# toy program that looks for non-windows-friendly file names on an OS X system and emits "mv" commands to rename them.
# checks that files are uniquely named. Does not check for length of file path
# run the mv commands to make the changes
# TEST before using; no guarantees; in Public domain
import re
import os, sys
#
# illegal chars
#!/usr/bin/env python
import sys
import urllib2
from xml.etree import ElementTree as ET
def getforecast(zipcode):
"""gets current forecast from wunderground"""
url='http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query={}'
forecastxml = urllib2.urlopen(url.format(zipcode)).read()