Skip to content

Instantly share code, notes, and snippets.

View pete911's full-sized avatar
🏠
Working from home

Peter Reisinger pete911

🏠
Working from home
View GitHub Profile
@pete911
pete911 / file to array
Created August 15, 2012 09:05
convert file to array
String fileContent = new Scanner(file).useDelimiter("\\A").next();
String[] fileLines = fileContent.split(System.lineSeparator());
@pete911
pete911 / line count
Last active October 4, 2015 05:18
count lines in a file
# sed
sed -n '$=' file
# awk
wc -l file | awk '{print $1}'
@pete911
pete911 / gist:2299764
Created April 4, 2012 08:47
change underscores for hyphens in file names
for i in *.txt; do mv $i $(echo "$i" | sed 's/_/-/'); done
@pete911
pete911 / python simple http server
Created March 22, 2012 17:40
basic python http server
import BaseHTTPServer
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
mappings = {'/' : {'GET' : 'test'}}
def main_handler(self, method='GET'):
# get request url (without url params) and remove trailing /
request_url = self.path.split('?')[0].rstrip('/')
@pete911
pete911 / curl - reponse code
Created March 22, 2012 15:38
get http response code
# -s = silent, -w = write out format, -o = output file
curl -s -w %{http_code} http://www.google.co.uk/ -o /dev/nul
@pete911
pete911 / vim highlight tabs
Created March 7, 2012 21:16
vim highlight tabs
:set listchars=tab:>-,trail:-
@pete911
pete911 / grails with git
Created February 14, 2012 13:01
grails with git
grails integrate-with --git
@pete911
pete911 / vim column select
Created February 14, 2012 11:48
vim block wise visual
CTRL-V (in win CTRL-Q) ($ if need to extend to end of each line) then I to edit and ESC to make changes
@pete911
pete911 / html slidy
Created February 13, 2012 17:28
html slidy
http://www.w3.org/Talks/Tools/Slidy2/
@pete911
pete911 / padding string with chars
Created February 9, 2012 11:15
java - string padding with characters - one liner
String.format("%10s", "foo").replace(' ', '*');