Skip to content

Instantly share code, notes, and snippets.

View laczoka's full-sized avatar

Laszlo (@laczoka on Twitter) laczoka

View GitHub Profile
============== project.clj ================
(defproject sampleweb "1.0.0-SNAPSHOT"
:description "sample application"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[compojure "0.6.0-RC1"]]
:dev-dependencies [[lein-ring "0.2.6"]]
:ring { :handler sampleweb.core/app-routes }
)
============== src/sampleweb/core.clj ======
@laczoka
laczoka / snippet.js
Created July 21, 2011 14:31
String.replace
function markMicrodata(str) {
var re = new RegExp('(itemprop="[^"]+")');
alert("!");
var marked = str.replace(re, "{{$1}}");
return marked;
}
// if you place the alert after str.replace it doesn't show up, and the extension silently fails
@laczoka
laczoka / acm-mai-p1-solution.clj
Created July 11, 2012 20:39
Solution to first puzzle published in the Communications of the ACM May 2012 issue
(ns acmcom-mai-puzzle.alt
(:require [clojure.math.combinatorics :refer [subsets]]
[clojure.set :refer [subset?]]))
(def puzzle-pieces (set (map set (reverse (subsets [:h :v :d1 :d2])))))
(def default-path (range 0 16))
@laczoka
laczoka / core.clj
Created November 27, 2012 18:49
Log4j vs. datomic-free
(ns logtest.core
(:use [clojure.tools.logging]
[clojure.tools.logging.impl :only [log4j-factory]]))
(defn foo
"I don't do a whole lot."
[]
(binding [*logger-factory* (log4j-factory)] (info "!")))
@laczoka
laczoka / dydra-load-triples.sh
Created February 14, 2013 09:47
Troubleshooting Dydra.com by using Stardog as reference. (Stardog 1.1 Community Edition) After loading the data into dydra, export doesn't work as expected. It results in 20+ triples whereas exporting from Stardog works just fine. There seems to be a difference in the total number of loaded triples as well: 5595 (Dydra) vs. 5572 (Stardog) See ht…
#!/bin/bash
DB=test2
# drop database
dydra drop test2
# seed data
array=(blurayplayer.n3 blurayplayer_example.n3 mobilephone.n3 mobilephone_example.n3 tablet.n3 tablet_example.n3 digitalcamera.owl digitalcamera_example.owl)
# create db and load seed data
dydra create test2
@laczoka
laczoka / how_to_import_data_to_stardog
Created February 20, 2013 15:15
How to load triples into Stardog Convenience script for running SPARQL queries against Stardog
+You should almost always import data when you create a new database.
+I could load 40k triples/sec, 10M triples under 4 minutes
+
+Follow the quickstart guide at http://stardog.com/docs/quick-start/.
+
+If you have triples in multiple files (.rdf,.n3,.nt, etc.) just use
+
+zip alltriples.zip file1 file2 ....
+
+to compress it, it will speedup the load.
@laczoka
laczoka / testCORS.js
Created March 1, 2013 15:12
Show how to implement proper CORS support in Stardog (stardog.com) using a Node.js example
/* ISSUE: Stardog (up to v1.1.3) does not properly support CORS[1] interaction.
The issue is two-fold:
1) Stardog tries to authenticated the OPTIONS "pre-flight" request.
2) Stardog doesn't return CORS headers, hence can only be accessed
by browser web apps running in a different domain via a proxy.
Effected browsers: Firefox and IE*. Safari and Chrome work due to a bug in webkit (see [2]).
Expected behavior: Stardog MUST NOT try to authenticate the pre-flight request, it SHOULD rather return
proper CORS headers. [4]
brew install php53
==> Downloading http://www.php.net/get/php-5.3.23.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php53-5.3.23
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file Makefile.global
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 18 (offset -2 lines).
Warning: Backing up all known pear.conf and .pearrc files
@laczoka
laczoka / jqasync.js
Last active December 22, 2015 21:09
Mini library that fell out as a by product while experimenting with $.Deferred and underscorejs.
/**
* Extend underscore.js with support for asynchronous computation using jQuery's Deferred implementation
* License:
The MIT License (MIT)
Copyright (c) 2013 Laszlo Török
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
(ns blocking.core
(:require [org.httpkit.server :refer [run-server] :as http]))
(def c (atom 0))
(defn app-blocking [req]
(println "Serving blocking connect " (swap! c inc))
(Thread/sleep 3000)
{:status 200
:headers {"Content-Type" "text/plain"}