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 java.io.*; | |
import org.apache.hadoop.conf.*; | |
import org.apache.hadoop.hbase.*; | |
import org.apache.hadoop.hbase.client.*; | |
import org.apache.hadoop.hbase.util.*; | |
public class ExampleClient { | |
public static void main(String[] args) throws IOException { | |
Configuration config = HBaseConfiguration.create(); | |
// Create table |
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
var util = require('util'); | |
var fs = require('fs'); | |
var systemConfig = (function() { | |
var configFilePath = __dirname + '/config.js'; | |
var configSource = fs.readFileSync(configFilePath); | |
var configData = new Array(); | |
configData = JSON.parse(configSource); |
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 java.util.Random | |
import akka.dispatch.Future | |
import akka.actor._ | |
import Commands._ | |
import collection.mutable.ListBuffer | |
object Commands { | |
trait Command | |
case class GetRandom() extends Command |
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
> db.searches.save( | |
{_id: 1, | |
"searches" : [ | |
{"site" : "google", "q": "restaurants"}, | |
{"site" : "yahoo", "q" : "shoes"}, | |
{"site" : "bing", "q" : "cheap flights"} | |
] | |
} | |
) | |
> db.searches.update( |
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
db.searches.update( | |
{ _id : 1 }, | |
{ $push : { "searches" : { "site" : "blekko.com", "q" : "mongodb" } } } | |
); | |
db.searches.update( | |
{ _id : 1 }, | |
{ $pop : { "searches" : -1 } } | |
) |
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
db.searches.remove() | |
db.searches.save( | |
{_id: 1, | |
"searches-size" : 3, | |
"searches" : [ | |
{"site" : "google", "q": "restaurants"}, | |
{"site" : "yahoo", "q" : "shoes"}, | |
{"site" : "bing", "q" : "cheap flights"} | |
] | |
} |
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
; Given a map where the values are numeric types contained in a string | |
; Convert the values to the type defined in a map of field types. | |
(mapv #(case ({"one" :int, "point-two" :float} (key %)) | |
:int {(key %) (Integer/parseInt (val %))} | |
:float {(key %) (Float/parseFloat (val %))} | |
{(key %) (val %)}) ; For strings, just return the original values if there was no type defined | |
{"one" "1", "point-two" ".2", "three" "three"}) |
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
; Thanks to http://stackoverflow.com/questions/18202661/casting-values-of-a-map-to-their-proper-types-in-clojure | |
; for the basis for this, I needed to also support cases where a value in `input` was empty when the cast occured. | |
(def input {:a "1" :b "2.5" :c "more" :d "string" :e "keys" :f ""}) | |
(def typetrans {:a #(Long/parseLong %) :b #(Double/parseDouble %) :f #(Integer/parseInt %)}) | |
(defn cast-fields [csvmap] | |
(reduce-kv | |
(fn [acc k v] |
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
(let [qparams {"cat" "meow"} | |
parammap {"cat" #(println "feline says" %), "dog" #(println "canine says" %)} | |
foundparam (into {} (filter #(contains? parammap (key %)) qparams))] | |
((get parammap (key (first foundparam))) (val (first foundparam)))) | |
;> feline says meow | |
; Cleaner? | |
(let [queryparams {:cat "meow", :cheese "nonsense"} | |
functionmap {:cat #(println "feline says" %), :dog #(println "canine says" %)} | |
selectedkey (first (select-keys functionmap (keys queryparams)))] |
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
(defn search-weather [qparams remote-addr] | |
; three search methods are supported: | |
; zipcode=XXXXX return airports within proximity to zipcode | |
; geo=lat,lon return airports within proximity of coords | |
; ip=XXX.XXX.XXX.XXX airports within geolocation of IP address | |
; ip=@detect airports within geolocation of client IP | |
(when (= (get qparams :ip) "@detect") (assoc qparams :ip remote-addr)) | |
(let? [geoloc (get-location qparams) :is-not nil? :else (error-response "could not find location") | |
stations (db/find-stations (qparams :type) geoloc) :is-not nil? :else (error-response "no stations found for location") | |
reports (if |
OlderNewer