Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am rywall on github.
  • I am rywall (https://keybase.io/rywall) on keybase.
  • I have a public key ASBA1dWlR7lwE7osmOivioSsalsiwSjvKerE4QakDLPH2go

To claim this, I am signing this object:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rywall
rywall / blinder.command
Last active May 17, 2018 13:08
Ruby Script to randomize filenames
#!/usr/bin/env ruby
require 'csv'
Dir.chdir File.dirname(__FILE__)
class String
def green; "\e[32m#{self}\e[0m" end
def yellow; "\e[33m#{self}\e[0m" end
end
class CreateModels < ActiveRecord::Migration
def change
create_table :items do |t|
end
end
end
class Item < ActiveRecord::Base
end
# Calculate the intake fraction where iF = SUM(popDensN * DispN)
# where popDensN is the population density in an N meter buffer minus the previous buffer
def intake_fraction
fraction = 0
inner_pop = 0
inner_area = 0
DISPERSION_FACTORS.each do |buffer, value|
pop_in_buffer = send("pop#{buffer}m").to_i
area_in_buffer = send("area#{buffer}m").to_i
DISPERSION_FACTORS = {50 => 0.5341, 100 => 0.3610, 200 => 0.5145, 500 => 0.9159, 1000 => 0.9088, 5000 => 4.662}
# Calculate the intake fraction where iF = SUM(popN * DispN) / 1000
# where popN is the population in an N meter buffer minus the previous population buffer
def intake_fraction
fraction = 0
inner_pop = 0
DISPERSION_FACTORS.each do |buffer, value|
pop_in_buffer = send("pop#{buffer}m").to_i
fraction += (pop_in_buffer - inner_pop) * value * 0.62 * 14.5
[50, 100, 200, 500, 1000, 5000].each do |buffer|
puts "Calculating population within #{buffer} m of each shape_geometry"
Shape.find_each do |s|
execute "UPDATE shapes SET pop#{buffer}m =
(SELECT SUM((ST_SummaryStats(ST_Clip(rast,1,ST_Buffer(geom::geography, #{buffer})::geometry))).sum)
FROM shapes, population_tiles
WHERE id = #{s.id} AND ST_Intersects(ST_Buffer(geom::geography, #{buffer})::geometry,rast)
GROUP BY id)
WHERE id = #{s.id}"
end
@rywall
rywall / gist:2130349
Created March 20, 2012 02:35
Only store in IM if all attributes are present
gem 'rails', :git => 'git://github.com/rails/rails.git', :ref => 'c1f397f82c7b3f352500832a399b5dbdc500b9c8'# change as required
require 'active_record'
require 'logger'
# Show ActiveRecord log output
ActiveRecord::Base.logger = Logger.new(STDOUT)
# Print out what version we're running
puts "Active Record #{ActiveRecord::VERSION::STRING}"
@rywall
rywall / gist:2039089
Created March 14, 2012 19:59
Identity Map Bug Fix
gem 'rails', :git => 'git://github.com/rails/rails.git', :ref => 'c1f397f82c7b3f352500832a399b5dbdc500b9c8'# change as required
require 'active_record'
require 'logger'
# Show ActiveRecord log output
ActiveRecord::Base.logger = Logger.new(STDOUT)
# Print out what version we're running
puts "Active Record #{ActiveRecord::VERSION::STRING}"