Skip to content

Instantly share code, notes, and snippets.

View thetrav's full-sized avatar

Travis Dixon thetrav

View GitHub Profile
@thetrav
thetrav / LazyVariables.groovy
Created October 10, 2012 07:18
Groovy Lazy Instance Variables
class LazyVariables {
def lazy(variables) {
variables.each { name, init ->
def chars = name.toCharArray()
chars[0] = Character.toUpperCase(chars[0])
def getter = "get${new String(chars)}"
this.metaClass[getter] = {
def value = init()
this.metaClass[name] = value
this.metaClass[getter] = { value }
@thetrav
thetrav / gist:7382137
Last active December 27, 2015 20:09
sample pact matchers
{
"provider": {
"name": "Animal Service"
},
"consumer": {
"name": "Zoo App"
},
"interactions": [
{
"description": "a request for animals",
@thetrav
thetrav / test.html
Created October 19, 2014 02:17
Bacon Dispatch?
<html>
<head>
<title>test eventTicks</title>
<script src="js/lib/zepto-1.1.4.js"></script>
<script src="js/lib/bacon-0.7.12.js"></script>
<script>
$(function() {
var ticks = new Bacon.Bus();
ticks.plug($(".ticker").asEventStream("click", function() {
return {tick: 1};
def double(i):
return i*2
def increment(i):
if i=='broken':
return None
return i+1
def flatten(listOfOptions):
return reduce(list.__add__, listOfOptions)
@thetrav
thetrav / Dockerfile
Created January 15, 2016 04:41
Ansible in Docker
FROM ubuntu
RUN apt-get update
RUN apt-get install -y wget build-essential python python-dev
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python get-pip.py
@thetrav
thetrav / limes.py
Created March 27, 2017 21:35
Average daily price of limes
import requests
from bs4 import BeautifulSoup
def coles_price():
r = requests.get('http://shop.coles.com.au/online/mobile/national/limes-loose')
if r.status_code == 200:
soup = BeautifulSoup(r.text, 'html.parser')
price_text = soup.find('p', {'class': 'price'}).get_text()
return float(price_text.replace('$', ''))
else:
@thetrav
thetrav / data.scala
Created April 6, 2017 03:44
generic Dao with Trait
trait Dao[T] {
val tableName: String
def find(id:String): ConnectionIO[Option[T]] =
Fragment.const("select * from $tableName where id = ") ++ fr"$id".query[T]
}
case class Foo(id: String, data: String)
object Foos extends Dao[Foo] {
@thetrav
thetrav / tbotc.pc
Last active February 22, 2018 07:40
psuedo code for a turn based offworld trading company
for each tick
for each company
execute destruction orders
productionBuildings
add resourceSource inputs
add stockPile inputs
add autoBuy inputs
consume power
@thetrav
thetrav / api.dart
Last active June 10, 2020 20:22
Upload file to server
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
Future<http.Response> uploadFile(
String url,
Map<String, String> headers,
Map<String, String> fields,
String fileName,
List<int> fileBytes) async {
var request = new http.MultipartRequest("POST", Uri.parse(url));
@thetrav
thetrav / gd_file_input.dart
Last active December 29, 2019 03:58
File input widget
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:growdata_shared_web/component/gd_red_text.dart';
class GdFileInput extends StatefulWidget {
final void Function(String, List<int>) fileSelected;
final List<String> extensions;
GdFileInput(this.fileSelected, {this.extensions});