Skip to content

Instantly share code, notes, and snippets.

View benhosmer's full-sized avatar

Ben Hosmer benhosmer

View GitHub Profile
@benhosmer
benhosmer / gist:5968115
Last active December 19, 2015 14:19
Install a specific version using homebrew.
# From SO: http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula
# Or just: brew install https://raw.github.com/Homebrew/homebrew-versions/master/yourpkg-version.rb
Simple Workflow
Step 1:
Navigate to your homebrew base directory (usually this is /usr/local) Example:
cd /usr/local
@benhosmer
benhosmer / rpm2cpio.sh
Created June 18, 2013 18:24
Extract SPEC file from and RPM.
#!/bin/bash
rpm2cpio my-rpm-file-name.rpm | cpio -idmv
@benhosmer
benhosmer / sql_demo.py
Last active December 18, 2015 00:48
sqlite3 quickstart with python.
# Create a table with the following SQL syntax:
# $ sqlite3 db/testing.db
# create table places(id integer primary key, name text, xloc int, yloc int);
# insert into places values(NULL, 'Stream', 300.3, 100.4);
# select * from places;
# 1|Stream|300.3|100.4
# for NULL in SQL, use the Python None
import sqlite3
@benhosmer
benhosmer / timed_capture.py
Last active December 17, 2015 18:29
Raspberry pi camera module time-delayed loop.
#!/usr/bin/env python
'''
Usage:
python timed_capture.py
'''
import datetime
from time import sleep
import subprocess
fps = 1 # The number of frames to capture per second.
@benhosmer
benhosmer / barcode.py
Created May 6, 2013 15:51
Using SL4A to read the barcode results data in python.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import android
droid = android.Android()
scan = droid.scanBarcode().result
result = [(scan['extras']['SCAN_RESULT'])]
droid.dialogCreateAlert('u'.join(result))
droid.dialogShow()
@benhosmer
benhosmer / gist:5387869
Last active December 16, 2015 05:59
Kickstart my CentOS-Minimal machine with some helpful utilities.
# Setup the CentOS Base with helpful utilities
#!/bin/bash
yum update -y
yum install system-config-firewall-tui vim screen sudo man git -y
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum install salt-minion --enablerepo=epel -y
@benhosmer
benhosmer / ddfilesize.sh
Created April 3, 2013 19:55
Using dd to create a file of a certain size.
# Generate a file of a specified size
# Use if=/dev/urandom for random stuff in the file
# This creates a file that is 3mb seek=$[1024*x] where x is the size in MB's you want it to be.
dd if=/dev/zero of=3mbfile.png bs=1024 count=0 seek=$[1024*3]
@benhosmer
benhosmer / gist:5118626
Last active November 28, 2018 04:42
My Drupal 6/7 nginx site configuration file.
# Drupal 6 NGINX Configuration File
# Enable www.mysite.com or mysite.com to be served
server {
server_name www.mysite.com;
rewrite ^/(.*) $scheme://mysite.com/$1 permanent;
}
server {
server_name mysite.com;
access_log /var/log/nginx/mysite.com-access.log;
@benhosmer
benhosmer / export-drupal-user-email.sh
Created March 7, 2013 12:56
Quickly output a list of Drupal user's email addresses using mysqldump.
echo 'select mail from users' | mysql -u root -p DBNAME > /home/yourhomedirectory/users.txt
@benhosmer
benhosmer / time-files-modified.py
Created January 25, 2013 14:12
Find the oldest and newest file in a directory and sort them.
#!/usr/bin/env python
import os
path = 'data'
os.chdir(path)
files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)
oldest = files[0]
newest = files[-1]