Skip to content

Instantly share code, notes, and snippets.

View jamiecook's full-sized avatar

Jamie Cook jamiecook

View GitHub Profile
def build_report_data
@counts_audience = Array.new(UPPER_FREQUENCY_LIMIT, 0)
@reaches = Array.new(UPPER_FREQUENCY_LIMIT, 0)
@cumulative_counts = Array.new(UPPER_FREQUENCY_LIMIT, 0)
@cumulative_reaches = Array.new(UPPER_FREQUENCY_LIMIT, 0)
@reaches_market_discrete = Array.new(UPPER_FREQUENCY_LIMIT, 0)
@total_contacts = 0
position = self.counts.length - 1
total_counts = 0
cached_potentials = potentials
// SETUP CODE
// ALPHA < 0, BETA > 0?
bool has_min_deterrence = (alpha < 0 && beta > 0);
float turn_cost, min_utility = 0.0;
if (has_min_deterrence)
{
turn_cost = -alpha / beta;
min_utility = beta * turn_cost + alpha * log(turn_cost);
}
@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;
}
@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
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]
# 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
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],
@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
@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>