Skip to content

Instantly share code, notes, and snippets.

View sarcasticadmin's full-sized avatar

Robert James Hernandez sarcasticadmin

View GitHub Profile
@splaspood
splaspood / bash_iniparse.sh
Created December 13, 2011 20:34
Parsing INI Files with Bash
cfg.parser () {
fixed_file=$(cat $1 | sed 's/ = /=/g') # fix ' = ' to be '='
IFS=$'\n' && ini=( $fixed_file ) # convert to line-array
ini=( ${ini[*]//;*/} ) # remove comments
ini=( ${ini[*]/#[/\}$'\n'cfg.section.} ) # set section prefix
ini=( ${ini[*]/%]/ \(} ) # convert text2function (1)
ini=( ${ini[*]/=/=\( } ) # convert item to array
ini=( ${ini[*]/%/ \)} ) # close array parenthesis
ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2)
ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis
@ajc
ajc / kermit-serial
Created January 21, 2011 04:02
kermit script to connect to a local serial port
#! /usr/bin/kermit +
;
; copy this to ~/bin/kermit-serial and make executable!
;
set modem type none
set line /dev/ttyUSB0
set carrier-watch off
set speed 9600
if defined \%1 set speed \%1
set flow rts/cts
@davidphasson
davidphasson / show.html.erb
Created April 8, 2009 03:42
ERB and the case statement
# Doesn't work
<p>
<% case @request.author_hosted %>
<% when "yes" %>
The school <b>has</b> hosted an author before.
<% when "no" %>
The school <b>has not</b> hosted an author before.
<% end %>
</p>