Skip to content

Instantly share code, notes, and snippets.

William Speirs wspeirs

Block or report user

Report or block wspeirs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View simple shell scripting
const x:num = 123.456; // this is a constant that never changes
const y:str = "hello world"; // constant string literal
var a:str = "hello"; // create a string variable, and assign to string literal
var b:num = 23.4; // create a number variable, and assign number
var c:str[] = ["hello", "world"]; // create an array variable, assign literal
CWD = "/path/to/current/directory"; // CWD is a special variable that can be set or read, and represents the current working directory
print(ARG[0]); // ARG is a spcecial variable that can only be read; it is a str[]. The first argument (zero index) is the first argument passed to the script.
wspeirs / qt_logging.cpp
Created Apr 11, 2019
Example of how to use logging in QT
View qt_logging.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QLoggingCategory>
let mut wal_file = try!(OpenOptions::new().read(true).write(true).create(true).open(tree_file_path.to_owned() + ".wal"));
// if we have a WAL file, just replay it into the mem_tree
if try!(wal_file.metadata()).len() != 0 {
let mut buff = vec![0; node_size];
while true {
match wal_file.read_exact(&mut buff) {
Ok(_) => {
let k = try!(decode(&buff[0..max_key_size]));
QueryRunner runner = new QueryRunner(dataSource);
// Use the BeanListHandler implementation to convert all
// ResultSet rows into a List of Person JavaBeans.
ResultSetHandler<List<Person>> handler = new BeanListHandler<Person>(Person.class);
// Execute the SQL statement and return the results in a List of
// Person objects generated by the BeanListHandler.
List<Person> persons = runner.query("SELECT * FROM Person").execute(handler);
AsyncExecutor asyncRun = new AsyncExecutor(Executors.newFixedThreadPool(5));
// Setup the UpdateExecutor
UpdateExecutor executor = runner.update("UPDATE Person SET height=:height WHERE name=:name")
.bind(":height", 2.05)
.bind("name", "John Doe");
// Returns a Future for the update call
QueryRunner runner = new QueryRunner(dataSource);
// Execute the SQL insert statement
runner.insert("INSERT INTO Person (name,height) VALUES (:name,:height)")
.bind("name", "John Doe")
.bind("height", 1.82)
// Now it's time to rise to the occation...
// Use a ResultSetHandler implementation, ArrayHandler, to convert the
// first row into an Object[].
ResultSetHandler<Object[]> handler = new ArrayHandler();
// Create a QueryRunner that will use connections from
// the given DataSource
QueryRunner runner = new QueryRunner(dataSource);
// Generate a QueryExecutor for the query
QueryExecutor executor = runner.query("SELECT * FROM Person WHERE first_name=:first_name and last_name = :last_name");
wspeirs /
Created Nov 13, 2013
Simple statistics using commons-math3
final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values
final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values
final Frequency frequency = new Frequency();
// add numbers into our stats
for(int i=0; i < NUM_VALUES; ++i) {
values[i] = rng.nextInt(MAX_VALUE);
public void getIntegerEvent(Integer event) throws InterruptedException {
System.out.println(System.currentTimeMillis() + ":\t" + name + " got " + event);
wspeirs / merged
Created Jan 20, 2013
Merged template and context.
View merged
Dear Bill-
This is an e-mail because you signed up for and we're really happy that you did.
Here are 3 cool articles you can read:
- Welcome
- Parsing the Command Line
- Document Templating or Mail Merge
You can’t perform that action at this time.