Skip to content

Instantly share code, notes, and snippets.

View biesnecker's full-sized avatar

biesnecker

  • Orlando, FL
  • 07:09 (UTC -04:00)
View GitHub Profile
@biesnecker
biesnecker / ScalaJetty.scala
Created August 17, 2011 23:17
Main method
package com.biesnecker.scalajetty
import cc.spray._
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.xml.XmlConfiguration
import org.eclipse.jetty.webapp.WebAppContext
import java.io.File
object ScalaJetty {
@biesnecker
biesnecker / akka.conf
Created August 17, 2011 23:18
Akka configuration
####################
# Akka Config File #
####################
# This is the Akka config template to be used for spray SERVLET CONTAINER deployments
akka {
version = "1.1.3" # Akka version, checked against the runtime version of Akka.
# spray requires nothing but akka-actors, which are implicitly enabled
@biesnecker
biesnecker / jetty.xml
Created August 17, 2011 23:18
Jetty configuration
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<!-- =============================================================== -->
<!-- Configure the Jetty Server -->
<!-- -->
<!-- Documentation of this file format can be found at: -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
@biesnecker
biesnecker / simple-work-queue.clj
Created January 14, 2012 08:39
A very simple set of functions create a work queue with an arbitrary number of workers attached in Clojure
(ns nadsack.utils.queue
(:import (java.util.concurrent BlockingQueue LinkedBlockingQueue)))
(defn- generic-worker [worker-function #^BlockingQueue queue switch]
(future
(let [worker-id (.toString (java.util.UUID/randomUUID))]
(while (not (realized? switch))
(let [work-item (.take queue)]
(cond
(import '(org.joda.time LocalDate))
(defn today [] (LocalDate.))
;; basic functions to increment or decrement a date
(defn inc-date [#^LocalDate ds] (.plusDays ds 1))
(defn dec-date [#^LocalDate ds] (.minusDays ds 1))
;; generate infinite streams of LocalDate objects starting with start-ds
(defn inc-date-stream [#^LocalDate start-ds] (iterate inc-date start-ds))
(def charvals (apply vector "ABCDEFGHJKMNPQRSTUVWXYZ23456789")) ; some characters weren't allowed in the codes
(defn rand-char [] (charvals (rand-int (count charvals))))
(apply str (take 10 (repeatedly rand-char)))
@biesnecker
biesnecker / good-solution.clj
Created January 20, 2012 09:38
#77: Anagram Finder
;; by inecas (http://www.4clojure.com/user/inecas)
(fn [c]
(set (map set
(filter #(< 1 (count %))
(vals (group-by sort c))))))
@biesnecker
biesnecker / shockbob-ttt.clj
Created January 22, 2012 01:07
#73 Analyze a Tic-Tac-Toe Board
#(some {[:o :o :o] :o [:x :x :x] :x}
(partition 3
(map
(vec (flatten %))
[0 1 2 3 4 5 6 7 8
0 3 6 1 4 7 2 5 8
0 4 8 2 4 6])))
@biesnecker
biesnecker / euler-1.clj
Created January 23, 2012 07:38
Snippets for Project Euler 1-3 in Clojure
(defn prog-sum
"Calculates the sum of an arithmetic progression"
([n a] (prog-sum n a a))
([n a d] (/ (* n (+ (* 2 a) (* (dec n) d))) 2)))
(defn euler-1 [n f1 f2]
(let [
b (dec n)
d1 (quot b f1)
d2 (quot b f2)
@biesnecker
biesnecker / euler-4.clj
Created January 24, 2012 22:56
Project Euler solutions in Clojure (4-6)
(defn palindrome? [n] (let [numseq (seq (str n))] (= (reverse numseq) numseq)))
(defn euler-4 []
(apply max
(for [x (range 999 900 -1) y (range x 900 -1)
:when (palindrome? (* x y))]
(* x y))))