Skip to content

Instantly share code, notes, and snippets.

View xkr47's full-sized avatar

Jonas Berlin xkr47

View GitHub Profile
@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 {
#!/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 / README.md
Last active March 30, 2018 19:57
Ceylon Web Runner: game_of_hny.ceylon
@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 / keyboard-font-zooming.el
Created December 18, 2015 09:54
Emacs keybindings for zooming font size
; For finnish keyboard layout. Uses Ctrl + the two keys to the right of non-numpad number key "0"
(define-key global-map [?\C-+] 'text-scale-increase)
(define-key global-map [?\C-'] 'text-scale-decrease)
@xkr47
xkr47 / jolla-two-way-internet-sharing.md
Last active December 16, 2015 05:16
Two-way internet sharing with Jolla/sailfishos

Figure 1

In "internet sharing" mode

  • as-is implemented now, no changes needed
  • phone has static ip configuraton for usb network interface
  • phone runs udhcpd, which
    • provides gateway & dns info as made available by e.g. cellular internet connection
  • pc runs dhcp client, gets ip, gateway & dns info from phone
@xkr47
xkr47 / autoShutdownPrevious.ceylon
Last active December 7, 2015 10:07
Automatically shut down previously running app instance on startup
import ceylon.file {
Path,
Nil,
File,
createFileIfNil,
parsePath
}
import ceylon.logging {
Logger
}
@xkr47
xkr47 / hexdump.ceylon
Created December 6, 2015 07:42
Simple singleline hexdumper
void hexdump(String s) {
value hexes = { for (ch in s) let (x = "_____" + formatInteger(ch.integer, 16)) x[x.size - 5 ...] };
log.debug(hexes.fold("")((x,y) => x + y + " ")+ s);
}
@xkr47
xkr47 / precedence1.ceylon
Last active December 3, 2015 15:04
Ceylon Web Runner: ceylon precedence fun
//$webrun_wrapped
shared void run() {
value cn = "foo.bar";
print(cn[(cn.lastIndexWhere((Character ch) => ch == '.') else 0) ...]);
// vs
print(cn[(cn.lastIndexWhere((Character ch) => ch == '.') else 0)+1 ...]);
// vs
print(cn[ cn.lastIndexWhere((Character ch) => ch == '.') else 0 ...]);
@xkr47
xkr47 / letsencrypt-jetty.sh
Last active May 4, 2025 13:59
How to use Letsencrypt certificate & private key with Jetty
# input: fullchain.pem and privkey.pem as generated by the "letsencrypt-auto" script when run with
# the "auth" aka "certonly" subcommand
# convert certificate chain + private key to the PKCS#12 file format
openssl pkcs12 -export -out keystore.pkcs12 -in fullchain.pem -inkey privkey.pem
# convert PKCS#12 file into Java keystore format
keytool -importkeystore -srckeystore keystore.pkcs12 -srcstoretype PKCS12 -destkeystore keystore.jks
# don't need the PKCS#12 file anymore