Skip to content

Instantly share code, notes, and snippets.

View jamiecook's full-sized avatar

Jamie Cook jamiecook

View GitHub Profile
@jamiecook
jamiecook / enum.rb
Last active September 9, 2015 10:30
module Enumerable
def with_progress(msg, resolution=1, &blk)
return enum_for(:with_progress, msg) unless block_given? # Sparkling magic!
Logger.indentStart(msg)
pb = VlcProgressBar.new(msg, size.to_i)
each_with_index { |elem, i|
yield(elem)
pb.full_increment if i%resolution == 0
@jamiecook
jamiecook / fails.log
Created July 16, 2015 12:05
There was some serious problems running this particular report_result
jetski@ams:~/shared/log$ grep 243244 show_this_to_nkpart.log | tail -n 50 | head -n 30
SQL (2.4ms) UPDATE "report_results" SET "status" = 'Queued' WHERE "report_results"."id" = 243244
2015-07-16 11:49:50 +0000 ReportResultQueue -> Running ReportResult 243244/96595 [Sydney -> Queued], API gave accepted
SQL (2.2ms) UPDATE "report_results" SET "status" = 'Running' WHERE "report_results"."id" = 243244
SQL (2.0ms) UPDATE "report_results" SET "status" = 'Failure' WHERE "report_results"."id" = 243244
2015-07-16 11:49:58 +0000 ReportResultQueue -> Kahuna Inconsistency for ReportResult 243244/96595 [Sydney -> Failure] - marking as failed
2015-07-16 11:49:58 +0000 ReportResultQueue -> ReportResult 243244/96595 [Sydney -> Failure] was marked as failed, lets try the next one
2015-07-16 11:50:09 +0000 ReportResultQueue -> Requeuing ReportResult 243244/96595 [Sydney -> Failure]
SQL (10.8ms) UPDATE "report_results" SET "status" = 'Queued' WHERE "report_results"."id" = 243244
2015-07-16 11:50:13 +0000 ReportRes
@jamiecook
jamiecook / vimrc
Created June 17, 2015 14:02
Vim rc to run haskelly stuff
" Ruby
autocmd FileType ruby noremap <leader>r :w<cr>:!ruby % <cr>
" Functional tests
autocmd FileType scala noremap <leader>t :w<cr>:!sbt test<cr>
autocmd FileType haskell noremap <leader>r :w<cr>:!ghc % -o run_me<cr>:!./run_me<cr>
autocmd FileType haskell noremap <leader>t :w<cr>:!doctest %<cr>
autocmd FileType haskell noremap <buffer> <F2> :GhcModType<CR>
autocmd FileType haskell noremap <buffer> <silent> <F3> :GhcModTypeClear<CR>
autocmd FileType haskell noremap <leader>T :w<CR>:GhcModTypeInsert<CR>
@jamiecook
jamiecook / check_temperature.rb
Created May 15, 2015 00:58
check_temperature.rb
#!/usr/bin/env ruby
require 'date'
warn,crit=30.0,35.0
while a = ARGV.shift
if a == "-w"
warn = ARGV.shift.to_f
elsif a == "-c"
crit = ARGV.shift.to_f
end
end
changes = {# Authorised Kahuna Data Kahuna_valid Archived
Selection.status_pending => [SiteAuthorisation::ALTERED, true, false, false],
Selection.status_null_no_data_ => [SiteAuthorisation::AUTHORISED, false, false, false],
Selection.status_reject_new_ => [SiteAuthorisation::REJECTED, false, false, false],
Selection.status_reject_change_ => [SiteAuthorisation::REJECTED, true, false, false],
Selection.status_current => [SiteAuthorisation::AUTHORISED, true, true, false],
Selection.status_archived_has_data_ => [SiteAuthorisation::AUTHORISED, true, true, true],
Selection.status_archived_no_data_ => [SiteAuthorisation::ALTERED, false, false, true],
Selection.status_new => [SiteAuthorisation::ALTERED, false, false, false],
Selection.status_altered => [SiteAuthorisation::ALTERED, false, false, false],
# Note that if any data required to determine the type of person is missing then person type = :missing
if [study_type, employment_status, other_activity].all? { |e| e == :missing }
:missing
elsif study_type == :primary_school
:primary_school
elsif study_type == :secondary_school
:secondary_school
elsif employment_status == :full_time
if study_type == :no_study || study_type == :missing
white_or_blue == :white ? :full_time_white_collar_worker : :full_time_blue_collar_worker
ULONG_MAX = 4294967295
zones = (1..5).to_a
times = [1212, 1213, 1214, 1215,
1312, 1313, 1314, 1315,
1412, 1413, 1414, 1415,
1512, 1513, 1514, 1515]
purposes = (1001..1060).to_a
num_cars = [0,1,2,3]
@jamiecook
jamiecook / kml_exporter.rb
Last active August 29, 2015 14:15
How to kml export some band widths
require 'utils/gis/link_to_polygon_converter'
require 'utils/gis/tab_file_writer'
def kml_output
links_to_export = get_links_to_export('LinkType', [15,16,17,19]) # [linknr1, linknr2, ...]
links = OtSpatialReader.new.readLinks.reject { |linknr, _| !links_to_export.include?(linknr) }
polygons_by_linknr = links.map_values { |line| LinkToPolygonConverter.translate(line, $Ot.project.city) }
polygons_by_linknr_dirn = polygons_by_linknr.each_with_object({}) { |(linknr, (poly1,poly2)), memo|
memo[[linknr, 1]] = poly1
@jamiecook
jamiecook / a
Created January 19, 2015 06:21
for (int col = 0; col < numCentroids; ++col)
{
float skim_value = skim_row[col];
if (attractions.at(col) == 0 || skim_value == 99999)
{
utilities.at(col) = 99999;
continue;
}