Skip to content

Instantly share code, notes, and snippets.

View benhosmer's full-sized avatar

Ben Hosmer benhosmer

View GitHub Profile
@benhosmer
benhosmer / atrium_project_case_migration.sql
Created October 16, 2013 19:19
Move cases within OpenAtrium to a different group.
UPDATE casetracker_case SET pid='NEWPROJECTNID' WHERE pid='OLDPROJECTNID';
UPDATE og_ancestry SET group_nid='OLDGROUPNID' WHERE nid in ('CASENODEID', 'OTHERCASENODEID');
@benhosmer
benhosmer / populate.yaml
Created September 18, 2013 20:04
Populate a jinja variable in a configuration file.
/srv/salt/populate/init.sls:
{% set host_name = grains['host'] -%}
testfile:
file:
- managed
- name: /home/vagrant/testfile
- source: salt://populate/testfile
- template: jinja
- defaults:
@benhosmer
benhosmer / simple-grid.py
Created September 9, 2013 17:31
Create a simple grid and print it properly in python.
#!/usr/bin/env python
board = [ ['-'] *3 for i in range(3) ]
for i, line in enumerate(board):
for char in line:
print char,
print
@benhosmer
benhosmer / disable_comments.sql
Created August 6, 2013 18:37
Mass disable comments for existing Drupal nodes. Credit: https://drupal.org/node/103064#comment-4922950
UPDATE `node` SET `comment` = '2' WHERE `type` = 'toolkit';
UPDATE node_revision SET comment=2 WHERE nid IN (SELECT nid FROM node WHERE node.type='toolkit');
@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