Skip to content

Instantly share code, notes, and snippets.

@ronan-mch
ronan-mch / JobsRetrievalScript.sh
Created October 24, 2011 20:11
This script uses bash commands to retrieve data from the Jobs.ie front page and process it into a spreadsheet friendly format
#!/bin/bash
#jobs.ie retrieval script
# This command invokes wget and saves the output file to temp1.txt
wget www.jobs.ie -O source-file.txt
# Prints current date to file
date >> scraper-dir/results.txt
@ronan-mch
ronan-mch / StackOverflow.py
Created October 24, 2011 20:35
This is a script for scraping the site Stack Overflow's user pages and returning relevant data from the html doc as a csv
#Stack Overflow scraper script
#imports necessary modules
from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup
import time
username = raw_input("Username: ")
@ronan-mch
ronan-mch / vectors.py
Created November 9, 2011 21:56
This is a script which performs several vector functions
# this function adds two vectors together to produce a new vector, vector3.
# first vector 3 is defined as an array. then, an if sentence tests
#which vector is longer. this means that vectors of unequal sizes can be added
# together. - except that this doesn't actually work... loop stops
# the for loop adds each element of the first vector to that of its counterpart
# the output is then appended to vector3, the new output.
def vectorAdd(vector1,vector2):
vector3 = []
if len(vector1)<= len(vector2):
@ronan-mch
ronan-mch / show.js
Created September 27, 2012 15:26
clever jQuery function to show more or less of an item
//call relevant function on click of showMore/Less links
$("[id^=show]").click(function(){
var functionCall = $(this).attr("id").substring(4,8);
var boxName = $(this).attr("id").substring(8);
window["show" + functionCall](boxName);
});
/**
* @param boxName string
* @pre boxName = Subjects || Notes
@ronan-mch
ronan-mch / user_input.rb
Created October 2, 2012 13:51
Ruby code for getting confirms from user
def prompt(*args)
print(*args)
gets.chomp!
end
def confirm(*args)
answer = prompt(*args, "(Y/N)")
if (answer.downcase =~ /^y|^n/)
return answer =~ /y/ ? true : false
else
@ronan-mch
ronan-mch / bundler.rb
Last active December 13, 2015 18:38
This program takes files of a given type and bundles them together into a single complete file. It is intended for web developers who need to develop their css and js in separate files for the sake of modularity, but need to reduce the number of HTTP requests to increase page serve time. It can either take a list of files or the name of a direct…
# == Synopsis
# This application bundles multiple files into a
# single file. It is intended for use with js and css
# files to allow developers to work on modular files
# which can be bundled together to minimise http requests.
# == Examples
# This command bundles all css files in the relative
# directory styles and its subdirectories into one
# file complete.css.
@ronan-mch
ronan-mch / hash to xml
Created June 28, 2013 07:58
recursive function to render xml from a multidimensional hash using Nokogiri.
def write_xml(hash)
builder = Nokogiri::XML::Builder.new do |xml|
hash_to_xml(hash, xml)
end
render xml: builder
end
def hash_to_xml(hash, xml)
hash.each do |key, value|
if value.is_a? String
@ronan-mch
ronan-mch / relator_scrape.py
Created November 14, 2013 18:43
scrape relator codes from Library of Congress - will only work on ScraperWiki
import scraperwiki
import lxml.html
# Grab the page and turn it into an lxml object
html = scraperwiki.scrape("http://www.loc.gov/marc/relators/relaterm.html")
root = lxml.html.fromstring(html)
authorizedList = root.find_class("authorized") # get the title (has class authorized)
codeList = root.find_class('relator-code') # get the code (has class relator-code)
codeDict = dict()
@ronan-mch
ronan-mch / iso639-2.da.yml
Created April 4, 2014 13:52
iso three letter lang codes in danish. from http://madsenworld.dk/forms/lcode-dk.htm
AAR: Afar
ABK: Abkhaziansk
ACE: Akinesisk
ACH: Acoli
ADA: Adangme
AFA: Afro-Asiatisk (Andre)
AFH: Afrihili (Kunstsprog)
AFR: Afrikaans
AJM: Aljamia (udgået)
AKA: Akan
@ronan-mch
ronan-mch / log_parser.sh
Last active August 29, 2015 14:01
two shell scripts to parse a series of apache logs
# Start parse wrapper
num=$1
for i in $(seq 1 $num); do
echo "getting log for $i days ago";
./log_parser.sh "$i days ago";
done
# Start log parser
#!/bin/bash
#get timestamp for requested date