Skip to content

Instantly share code, notes, and snippets.

View torbjornvatn's full-sized avatar
🤷‍♂️

Torbjørn Vatn torbjornvatn

🤷‍♂️
View GitHub Profile
@ibdknox
ibdknox / socket.clj
Created October 31, 2010 06:48
compojure with websockets
(ns wl.core
(:use compojure.core, aleph.core, aleph.http, hiccup.core, hiccup.page-helpers)
(:require [compojure.route :as route])
(:gen-class))
(def broadcast-channel (channel))
(defn chat-handler [ch handshake]
(receive ch
(fn [name]
@steren
steren / Application.java
Created November 3, 2010 10:22
Upload and store image with Play! Framework
public class Application extends Controller {
public static void index() {
render();
}
public static void uploadPicture(Picture picture) {
picture.save();
index();
}
@dcsobral
dcsobral / prompt.sbt
Created May 28, 2011 01:04
SBT prompt with project name and current git branch
shellPrompt <<= name(name => { state: State =>
object devnull extends ProcessLogger {
def info(s: => String) {}
def error(s: => String) { }
def buffer[T](f: => T): T = f
}
val current = """\*\s+(\w+)""".r
def gitBranches = ("git branch --no-color" lines_! devnull mkString)
"%s:%s>" format (
name,
@stuartsierra
stuartsierra / phone_code.clj
Created July 25, 2011 23:46
Phone number coding program in Clojure
;; Adapted from "An empirical comparison of C, C++, Java, Perl,
;; Python, Rexx, and Tcl for a search/string-processing program"
;; by Lutz Prechelt
;; This was a 15-minute effort while listening to a talk. It's *not*
;; well thought-out or designed.
;; By Stuart Sierra,
;; @stuartsierra on Twitter
@xaviershay
xaviershay / ocr.main
Created August 7, 2011 06:34
OCR with Clojure. See the blog post at rhnh.net.
(ns ocr.main
(:use [clojure.string :only (split trim)])
(:use [clojure.contrib.duck-streams :only (write-lines read-lines)])
(:use [clojure.contrib.shell-out :only (sh)])
(:use [clojure.contrib.math :only (sqrt)]))
; Input handling
(defn read-text-image-line [line]
(if (= "white" (last (split line #"[,:\s]+"))) "0" "1"))
@brianleroux
brianleroux / index.html
Created September 15, 2011 13:54
ghetto-photoshare app logic
<!DOCTYPE html>
<html>
<body>
<script src="phonegap-1.0.0.js"></script>
<script>
function uploadPhoto(imageURI) {
function win(r) {
package com.fmpwizard.weyesowl.code
package snippet
/**
* Created by IntelliJ IDEA.
* User: Diego Medina
* Date: 11/20/11
@viktorklang
viktorklang / minscalaactors.scala
Last active March 25, 2024 19:01
Minimalist Scala Actors
/*
Copyright 2012-2021 Viktor Klang
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@scalatron
scalatron / Example Bot 2 - The Tag Team
Created April 23, 2012 04:54
Rough draft of a framework for simpler, more elegant Scalatron bot coding
// Example Bot #2: The Tag Team
/** This bot spawns a collection of companion mini-bots which strive to remain at a configurable
* offset relative to their master bot. The master bot runs in large circles.
*
* The master bot uses the following state parameters:
* - heading = direction it is currently traveling
* - lastRotationTime = simulation the time when the bot last rotated its heading
* - lastSpawnTime = simulation time when the last mini-bot was spawned
* The mini-bots use the following state parameters:
@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);