This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env scalas | |
/*** | |
scalaVersion := "2.11.0" | |
scalacOptions += "-language:_" | |
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.6" | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default prefix: Ctrl+b | |
start new session: tmux | |
list sessions: tmux ls | |
attach to session: tmux attach [-t <session>] | |
attach to session forcely: tmux attach -d | |
detach: prefix then d | |
Windows: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz.Reader | |
case class Configuration(hostname: String, port: Int, file: String) | |
case class ServerConnection(host: String, port: Int, file: String) | |
val config = Configuration("localhost", 8080, "index.html") | |
def configReader[A](f: Configuration => A): Reader[Configuration, A] = Reader { f } | |
val conn: scalaz.Kleisli[scalaz.Id.Id, Configuration, ServerConnection] = for { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def say_hello | |
"hello #{self}!" | |
end | |
end | |
puts "world".say_hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env scalas | |
/*** | |
scalaVersion := "2.11.0" | |
scalacOptions += "-language:_" | |
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.6" | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@results = [] | |
ActiveRecord::Base.connection.select_all( | |
ActiveRecord::Base.send(:sanitize_sql_array, | |
["select * from events where area_type = ? and area_id = ?", 'parcel', '1']) | |
).each do |record| | |
# instead of an array of hashes, you could put in a custom object with attributes | |
@results << {id: record["id"], category: record["category"]} | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with parcel_ids as (select id from parcels where ranch_id = 57), | |
zone_ids as (select id from zones where parcel_id in (select id from parcel_ids)) | |
select extract(month from date) as month, category, sub_category, count(*) from events where (area_type = 'parcel' and area_id in (select id from parcel_ids)) or (area_type = 'zone' and area_id in (select id from zone_ids)) | |
group by extract(month from date), category, sub_category; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\set p1 '\'' 'POLYGON((0 0, 0 3, 3 3, 3 0, 0 0))' '\'' | |
\set p2 '\'' 'POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))' '\'' | |
\set p3 '\'' 'POLYGON((-1 -1, -1 1, 1 1, 1 -1, -1 -1))' '\'' | |
\set p4 '\'' 'POLYGON((-2 0, -1 0, -1 -1, -2 -1, -2 0))' '\'' | |
\set p5 '\'' 'POLYGON((0 0, 0 3, 1.5 3.5, 3 3, 3 0, 0 0))' '\'' | |
\set p6 '\'' 'POLYGON((9473678.20883554 1181106.57122879,9473678.20915479 1181106.57199719,9473678.21065819 1181106.57712958,9473678.21207348 1181106.58209349,9473678.2081223 1181106.58868023,9473678.20795089 1181106.58826838,9473678.20606889 1181106.57622375,9473678.20883554 1181106.57122879))' '\'' | |
\set p7 '\'' 'SRID=3857;POLYGON ((-121.7917486242956 36.87756646920572, -121.7896991290737 36.87551268040243, -121.7864477199712 36.87768243547166, -121.7884120600693 36.87976431594564, -121.7917486242956 36.87756646920572))' '\'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def monthly_count_of_ranch_fields(ranch_id, start_date, end_date) | |
sql ="with parcel_ids as (select id from parcels where ranch_id = ?), | |
zone_ids as (select id, parcel_id from zones where parcel_id in (select id from parcel_ids)), | |
parcel_events as (select date, category, sub_category, area_id as parcel_id from events where area_type = 'parcel' and area_id in (select id from parcel_ids)), | |
zone_events as (select e.date, e.category, e.sub_category, z.parcel_id from events e, (select id, parcel_id from zone_ids) z where e.area_id = z.id and e.area_type = 'zone'), | |
all_events as (select * from parcel_events union select * from zone_events) | |
select extract(month from date) as month, category, sub_category, parcel_id, count(*) from all_events where date >= ? and date <= ? | |
group by extract(month from date), category, sub_category, parcel_id" | |
field_event_summaries = Hash.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor._ | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.ExecutionContext._ | |
import scala.concurrent.duration._ | |
import Implicits.global | |
implicit val timeout = Timeout(30.seconds) | |
val system = ActorSystem("system") |
OlderNewer