Skip to content

Instantly share code, notes, and snippets.

View mariusk's full-sized avatar

Marius Kjeldahl mariusk

View GitHub Profile
(defproject mkbook "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[compojure "0.5.0-beta3"]
[ring/ring-jetty-adapter "0.3.0"]
[enlive "1.0.0-SNAPSHOT"]
[org.clojars.macourtney/clj-record "1.0.1"]
[postgresql "8.4-701.jdbc4"]]
:dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]])
@mariusk
mariusk / gist:917391
Created April 13, 2011 11:39
Updated clojure-clr WPF celcius example
; A CLR port of http://bestinclass.wordpress.com/2009/09/24/chaos-theory-vs-clojure/
; Updated to use Rich Hickey's changes: http://paste.lisp.org/display/87799
;
; A WPF app is fired up in another thread. Anything you type in the REPL
; is dispatched to the WPF thread and evaluated there.
;
; Requires the following addition to ClojureCLR's GenDelegate.cs:
; public static Delegate CreateFunc(IFn fn)
; {
; Type delegateType = typeof(Func<>).MakeGenericType(new Type[] { typeof(object) });
(require '[somnium.congomongo :as mongo])
(require '[somnium.congomongo.config :as mongoconfig])
(mongo/drop-database! "congomongotest")
(mongo/mongo! :db "congomongotest")
(mongo/set-write-concern mongoconfig/*mongo-config* :strict)
(mongo/add-index! :users [:userid] :unique true)
(pr (mongo/insert! :users {:userid "aa" :pwhash "bb"}))
;; Statement below fails, i.e. no data gets written, but
;; it still returns a mongodb instance object.. How to
;; detect that an insert failed?
@mariusk
mariusk / gist:4267093
Created December 12, 2012 11:28
Postgresql resorting to scans for single term full text searches, not sure why...
alter function to_tsvector(regconfig,text) cost 1000;
set enable_indexscan=false;
explain select * from proxyrec where to_tsvector('english', cs_ua) @@ to_tsquery('mozilla') order by ts limit 1
QUERY PLAN
----------
Limit (cost=347040.40..347040.40 rows=1 width=1052)
-> Sort (cost=347040.40..347178.66 rows=55302 width=1052)
Sort Key: ts
-> Bitmap Heap Scan on proxyrec (cost=603.09..346763.89 rows=55302 width=1052)
package main
import (
"fmt"
"regexp"
)
var str string = `cpu 143074 414 36348 4569263 926 3 732 0 0 0
cpu0 54787 108 14071 1114566 490 1 285 0 0 0
cpu1 19898 16 4065 1165614 54 0 39 0 0 0
cpu2 52089 234 14503 1117793 276 1 390 0 0 0
task compile() {
source = fileTree(dir: 'src/main/kawa').include('**/*.scm')
doLast {
javaexec {
main = "kawa.repl"
classpath = files(["/usr/local/share/java/kawa.jar", "/opt/android-studio/sdk/platforms/android-15/android.jar", "build/classes/debug"])
args "-d", "build/classes/debug", "--warn-undefined-variable", "--module-static-run", "--warn-invoke-unknown-method", "--warn-as-error", "-C"
args source
}
DisplayImageOptions opts = new DisplayImageOptions.Builder()
.showStubImage(placeholderid)
.showImageForEmptyUri(placeholderid)
.showImageOnFail(placeholderid)
.resetViewBeforeLoading()
.cacheInMemory()
.cacheOnDisc()
.build();
ImageLoaderConfiguration ilconf = new ImageLoaderConfiguration.Builder(getApplicationContext())
@mariusk
mariusk / gist:6159301
Created August 5, 2013 20:26
Android Facebook SDK gradle build file (build.gradle)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project
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
Vector2 size = Scaling.fit.apply(scene_width, scene_height, scr_width, scr_height);
int viewportX = (int)(scr_width - size.x) / 2;
int viewportY = (int)(scr_height - size.y) / 2;
int viewportWidth = (int) size.x;
int viewportHeight = (int) size.y;
Gdx.gl.glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
stage.setViewport(scr_width, scr_height, true,
viewportX, viewportY, viewportWidth, viewportHeight);