Skip to content

Instantly share code, notes, and snippets.

View xkr47's full-sized avatar

Jonas Berlin xkr47

View GitHub Profile
@xkr47
xkr47 / JsObjectMap.ceylon
Last active December 18, 2015 21:15
A MutableMap implementation using a plain javascript object as storage.
import ceylon.collection {
MutableMap
}
object help {
shared dynamic createEmptyObj;
dynamic {
createEmptyObj = eval("(function(){return {};})");
}
}
@xkr47
xkr47 / update
Last active December 20, 2015 10:20
How to validate the files being pushed to a remote Git repository and leave repository untouched if validation failed - works with bare and non-bare repos
#!/bin/bash
# This file should be installed in the remote repository as:
# - <path-to-bare-repo.git>/hooks/update if you have a bare repository
# - <path-to-regular-repo>/.git/hooks/update if you have a regular repository
set -e
refname="$1"
oldrev="$2"
@xkr47
xkr47 / pom.xml
Created August 13, 2013 08:28
pom.xml: When using slf4j, make sure we don't accidentally depend on commons-logging
<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>ban-unwanted-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
@xkr47
xkr47 / firefox
Last active December 28, 2015 18:49
~/bin/firefox wrapper script for using custom (older) firefox version only when running Robot Framework tests
#!/bin/bash
if [ "$1" = "-profile" ]; then
exec ${HOME}/firefox-20.0/firefox "$@"
echo Failed to start Firefox
exit 1
fi
exec /usr/bin/firefox "$@"
#!/usr/bin/perl
# takes black&white xpm file on input and produces "RLE compression" integer array on output
use strict;use warnings;
for (my $i=0; $i<5; ++$i) { <>; }
my $a = "";
while(<>) {
chomp;
s!^"!!;
s!"(?:,|\};)!!;
$a .= $_;
@xkr47
xkr47 / jsutil.ceylon
Last active January 8, 2016 14:07
JsObjectMap wraps a plain javascript object and lets you access and modify the object's properties via Ceylon's MutableMap interface
import ceylon.collection {
MutableMap
}
shared object help {
// Don't create functions taking >= 1 arguments until 1.2.1 because that triggers bug 5808
shared dynamic createEmptyObj;
// could use this instead but then it limits arguments and return types to not be "dynamic"
//shared Callable<Return,Args> uncurryThis<Return,Args,ThisType>(Callable<Return,Tuple<Nothing,ThisType,Args>> f);
dynamic {
@xkr47
xkr47 / getKeyEventRawCode.ceylon
Last active January 28, 2016 19:58
How to get the private rawCode field out of a Java Swing KeyEvent
import java.awt.event {
KeyEvent
}
import java.lang {
Runnable,
JBoolean=Boolean,
JLong=Long
}
import java.lang.reflect {
Field
@xkr47
xkr47 / dressed_up.ceylon
Last active February 2, 2016 09:23
Ceylon Web Runner: dressed_up.ceylon
shared dynamic MyInterface {
shared formal String foo;
}
shared void run() {
dynamic {
console.log("-----");
dynamic dyn = eval("({foo: 'bar'})");
console.log(dyn);
MyInterface my = eval("({foo: 'bar'})");
@xkr47
xkr47 / README.md
Last active February 14, 2016 08:15
Git subcommand for moving/renaming paths using sed/perl expressions

Save file as git-mvs in your path and then:

find -name '*file' -print0 | xargs -r0 git mvs 's/foo/bar/g'

or in zsh:

git mvs 's/foo/bar/g' **/*file
@xkr47
xkr47 / README.md
Last active February 16, 2016 23:46
PHP serialized object format <-> YAML converter

These scripts convert PHP serialized object format e.g.

a:2:{i:2;a:4:{s:5:"title";s:5:"Hello";s:5:"count";i:0;s:12:"hierarchical";i:0;s:8:"dropdown";i:0;}s:12:"_multiwidget";i:1;}

to YAML format:

---
2:
  title: Hello
  count: 0