Skip to content

Instantly share code, notes, and snippets.

@stianl
stianl / continous-qunit.ps1
Created October 16, 2012 13:53 — forked from jfromaniello/continous-qunit.ps1
Since less doesn't include a --watch option, and the only options I found was with ruby watchr+shell scripting I modified this Powershell script that continuously watch for file changes in a directory, and compiles less file
# watch a file changes in the current directory,
# compiles bootstrap.less
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = get-location
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName
while($TRUE){
@stianl
stianl / gist:5590899
Created May 16, 2013 10:52
Debugging language detection in Play framework on Heroku
public static Result acceptedLanguages() throws IOException {
Map<String, Object> stuff = new HashMap<>();
stuff.put("profilepage.profile.button.connect", Messages.get("profilepage.profile.button.connect"));
stuff.put("acceptedLanguages header", request().headers().containsKey("Accept-Language")?request().headers().get("Accept-Language")[0]:"non-existant");
stuff.put("play.mvc.Http.Context.current().request().cookies()", Http.Context.current().request().cookies());
List<Lang> availables = Lang.availables();
Collection<Locale> transform = Collections2.transform(availables, new Function<Lang, Locale>() {
@Override
public Locale apply(Lang lang) {
return lang.toLocale();
@stianl
stianl / DirectFieldRowMapper
Created September 19, 2013 20:07
Implementation of BeanPropertyRowMapper from spring jdbc that enables the use of value objects/DTO without getters, setter, lombok and credit cards Should probably also check field level access to only allow setting public fields, maybe some other time. Unfortunately methods like underscoreName from BeanPropertyRowMapper is private so it's copie…
import org.springframework.beans.*;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
@stianl
stianl / gist:72f42e36ddc6dde2e03d
Last active August 29, 2015 14:05
Override ExtJS global ajax timeout
Ext.override(Ext.data.Connection, {
timeout:120000
})
@stianl
stianl / gist:426788abc17a4245665d
Created August 28, 2014 07:59
Get where class was loaded from
// http://stackoverflow.com/questions/1983839/determine-which-jar-file-a-class-is-from
Class klass = String.class;
URL location = klass.getResource('/'+klass.getName().replace('.', '/')+".class");
@stianl
stianl / gist:1223ec15d1817a25cbcd
Last active September 8, 2016 10:04
Fjern "salgsplakat" og tekstblurring fra Aftenposten
/**
* Bruk en extenstion som stylebot e.l. i Chrome og legg til følgende regler for aftenposten.no for å lese Magasinet-artikler
*/
.js-salesposter-blurred-element {
text-shadow: 0 0 #000;
opacity: 1;
color: #000;
}
@stianl
stianl / AutoHotkey.ahk
Created December 11, 2015 10:23
Media hotkey mapping matching Steelseries 6gv2 Raw
#F1::Send {Volume_Mute}
#F2::Send {Volume_Down 3}
#F3::Send {Volume_Up 3}
#F4::Send {Media_Play_Pause}
#F5::Send {Media_Prev}
#F6::Send {Media_Next}
@stianl
stianl / gist:ed9a114612bee0c424acaed4183d74f2
Created April 29, 2016 15:04
Fetch HTML value with curl
# TODO: Get rid of last quotation mark output
$ curl -s http://localhost:8080/|grep -oP '_csrf" value="\K.*"'`'
@stianl
stianl / 0_bash_snippets
Last active September 9, 2016 11:40
Code snippets
# add public key to dokku
cat /path/to/public_key | ssh root@yourdokkuinstance "sudo sshcommand acl-add dokku [description]"
@stianl
stianl / permgen.js
Last active September 8, 2016 10:02
OQL javascript code to count packages with most class definitions
// Count packages with most class definitions (excluding class definitions in java.lang.*)
var set = {};
top(map(unique(map(filter(heap.classes(), function(it) {
return !it.name.substr(0,it.name.lastIndexOf('.')).startsWith('java.lang');
}), function(it) {
var pName = it.name.substr(0,it.name.lastIndexOf('.'));
if (set[pName]) {
set[pName]++;
} else {