Skip to content

Instantly share code, notes, and snippets.

View yayitswei's full-sized avatar

Wei Hsu yayitswei

  • San Francisco, CA
View GitHub Profile
(ns versaltest.core-test
(:require [cemerick.yonder :as yonder]
[clojure.java.browse :refer (browse-url)]
[compojure.handler :as handler]
[ring.adapter.jetty :as jetty]
[cljs.repl.browser]
[cljs.closure :as closure]
[clojure.tools.nrepl :as nrepl]
(clojure.tools.nrepl [server :as server]))
(:use clojure.test
(defproject testtest "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[jayq "2.0.0"]
[compojure "1.1.5"]
[yayitswei/yonder "0.0.1-SNAPSHOT"]
[ring-middleware-format "0.2.4"]
wei:itest wei$ lein run
**************** Started webserver. ****************
2013-01-25 12:14:37.640:INFO::Logging to STDERR via org.mortbay.log.StdErrLogStarted web server on port 3000
**************** Starting JVM REPL. ****************
2013-01-25 12:14:37.644:INFO::jetty-6.1.25
2013-01-25 12:14:37.708:INFO::Started SocketConnector@0.0.0.0:3000
**************** Upgrading the REPL to a browser-REPL. ****************
()
nil
(ns itest.core
(:use [compojure.core]
[clojure.java.shell :only [sh]]
[clojure.java.browse :only [browse-url]])
(:require [clojure.tools.nrepl.server :as nrepl-server]
[clojure.tools.nrepl :as repl]
[cljs.repl.browser]
[clj-http.client :as http]
[clojure.pprint]
[ring.util.serve :as ring-serve]
@yayitswei
yayitswei / project.clj
Created January 11, 2013 12:01
lein cljsbuild once runs slowly
(def cljs-files ["main" "template"])
(defn keyword-dasherize [& words]
(keyword (clojure.string/join "-" words)))
(defn name-to-build-opts [name]
{(keyword-dasherize name "dev")
{:source-path (str "src/cljs-" name)
:compiler
{:output-to (str "resources/public/js/bin-debug-" name "/" name ".js")
@yayitswei
yayitswei / project.clj
Created December 18, 2012 08:13
cljsbuild compile options getting long. 3 compile targets, 2 environments for each. to run the compile: "lein cljsbuild once prod prod-edit prod-new" is there a more DRY way to do it?
(defproject advent "0.1.0-SNAPSHOT"
:plugins [[lein-cljsbuild "0.2.9"]
[yayitswei/lein-deploy-app "0.1.0-SNAPSHOT"]]
:description "advent calendar for dawn"
:dependencies [[org.clojure/clojure "1.4.0"]
[jayq "0.2.3"]
[cc.qbits/fetch "0.1.0-alpha2"]
[com.cemerick/friend "0.1.2"]
[crate "0.2.1"]
[clj-time "0.4.4"]
@yayitswei
yayitswei / problem compiling
Created October 14, 2012 08:25
externs not being loaded?
wei:routes wei$ ls
README.md doc externs newrelic out project.clj resources src target test-data
wei:routes wei$ head -n 30 externs/google_maps_api_v3.js
/*
* Copyright 2010 The Closure Compiler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@yayitswei
yayitswei / gist:3660803
Created September 6, 2012 22:16
adjacent
(defn two->one [[x y] [w h]]
{:pre [(< x w) (< y h)]}
(+ x (* y w)))
(defn one->two [i [w h]]
{:pre [(< i (* w h))]}
[(mod i w) (int (/ i w))])
(defn valid-space [[x y] [w h]]
(and (<= 0 x) (<= 0 y) (< x h) (< y w)))
(defn cost-comparator [x y]
(if (= x y)
0
(let [[f1 _ h1] x
[f2 _ h2] y]
(if (= f1 f2)
(if (< h1 h2) -1 1)
(if (< f1 f2) -1 1)))))
(def p (priority-map-by cost-comparator [3 6] [18 9 9 [4 5]], [2 7] [18 9 9 [3 8]], [1 8] [18 9 9 [2 9]], [3 5] [18 8 10 [4 4]], [5 3] [18 8 10 [4 4]], [2 6] [18 8 10 [3 7]], [1 7] [18 8 10 [2 8]], [4 3] [18 7 11 [3 3]], [3 4] [18 7 11 [3 3]], [2 5] [18 7 11 [3 6]], [2 4] [18 6 12 [3 3]], [4 2] [18 6 12 [3 3]], [3 2] [18 5 13 [2 2]], [2 3] [18 5 13 [2 2]], [1 3] [18 4 14 [2 2]], [3 1] [18 4 14 [2 2]], [2 1] [18 3 15 [1 1]], [1 2] [18 3 15 [1 1]], [1 0] [18 1 17 [0 0]]))
@yayitswei
yayitswei / gist:3310911
Created August 10, 2012 03:58
mrjob with parameters
from mrjob.job import MRJob
from mrjob.protocol import JSONValueProtocol
class MRConversions(MRJob):
def __init__(self, duration=1, offset=0):
self.duration = duration
self.offset = offset
self.now = datetime.date.today()