Skip to content

Instantly share code, notes, and snippets.

@IanHopkinson
IanHopkinson / tests.py
Created Nov 20, 2020
A gist illustrating testing in Python using unittest
View tests.py
#!/usr/bin/env python
# encoding: utf-8
"""
Some exercising of Python test functionality based on:
https://docs.python.org/3/library/doctest.html
https://docs.python.org/3/library/unittest.html
Generating tests dynamically with unittest
View csvconcat.py
import csv
mydir = "C:/Users/Nessa/Documents/Work/Coding/Test"
os.chdir(mydir)
all_filenames = [i for i in glob.glob("*.{}".format("csv"))]
all_data = []
for f in all_filenames:
@IanHopkinson
IanHopkinson / start.sh
Created Mar 21, 2016
Modified start.sh for Docker Toolbox.
View start.sh
#!/bin/bash
trap '[ "$?" -eq 0 ] || read -p "Looks like something went wrong... Press any key to continue..."' EXIT
VM=default
#DOCKER_MACHINE=./docker-machine.exe
DOCKER_MACHINE=/c/Program\ Files/Docker\ Toolbox/docker-machine.exe
if [ ! -z "$VBOX_MSI_INSTALL_PATH" ]; then
VBOXMANAGE="${VBOX_MSI_INSTALL_PATH}VBoxManage.exe"
@IanHopkinson
IanHopkinson / lxml_examples.py
Created Nov 24, 2015
Examples of xpath queries using lxml in python
View lxml_examples.py
#!/usr/bin/env python
# encoding: utf-8
import lxml.etree
import lxml.html
import requests
xml_sample = """<?xml version="1.0" encoding="UTF-8"?>
<foo:Results xmlns:foo="http://www.foo.com" xmlns="http://www.bah.com">
<foo:Recordset setCount="2">
@IanHopkinson
IanHopkinson / 0_reuse_code.js
Created Jul 17, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@IanHopkinson
IanHopkinson / get_people
Created Jun 6, 2014
Get people appearing with a list of people from NewsReader
View get_people
#!/usr/bin/env python
# encoding: utf-8
from __future__ import unicode_literals
import json
import requests
import scraperwiki
from collections import OrderedDict
@IanHopkinson
IanHopkinson / get_timeline
Created Jun 6, 2014
Get a timeline from the NewsReader API
View get_timeline
#!/usr/bin/env python
# encoding: utf-8
from __future__ import unicode_literals
import json
import requests
import scraperwiki
from collections import OrderedDict
@IanHopkinson
IanHopkinson / pandas_finance.py
Created Apr 8, 2014
Get Yahoo!Finance data on ScraperWiki
View pandas_finance.py
#!/usr/bin/env python
"""
Save stock ticker data from Yahoo! Finance to sqlite.
"""
import datetime as d
import sqlite3
import pandas.io.data as web
import pandas.io.sql as sql
@IanHopkinson
IanHopkinson / view-source.R
Last active Dec 21, 2015
R used to generate views of ScraperWiki's Twitter Search tool
View view-source.R
#!/usr/bin/Rscript
# Script to create r-view 2013-08-14
# Ian Hopkinson
source('scraperwiki_utils.R')
NumberOfTweets<-function(){
query = 'select count(*) from tweets'
number = ScraperWikiSQL(query)
return(number)