Skip to content

Instantly share code, notes, and snippets.

View christian-schulze's full-sized avatar

Christian Schulze christian-schulze

View GitHub Profile

Update

If you're OK in having a node-esm executable, please consider this solution.

#!/usr/bin/env sh
# the /usr/local/bin/node-esm executable
input_file=$1
shift
exec node --input-type=module - $@ <$input_file

Creating standalone ESM-based Node.js scripts on Unix and Windows

Approach:

  1. The file starts with shell code.
  2. That code uses Node.js to execute the file in ESM mode, after it removes the initial non-JavaScript lines.
    • Node.js does not currently have CLI flags for achieving what we do in this step. Therefore, we have to pipe to the node executable.

When editing this file, we want to use the JavaScript mode of our IDE or editor. Therefore, we try to “hide” the shell code from JavaScript as much as possible.

@christian-schulze
christian-schulze / setupFilesAfterEnv.js
Created August 24, 2021 09:57 — forked from bvaughn/setupFilesAfterEnv.js
Jest config to remove extra console location / formatting noise
import { CustomConsole } from '@jest/console';
function formatter(type, message) {
switch(type) {
case 'error':
return "\x1b[31m" + message + "\x1b[0m";
case 'warn':
return "\x1b[33m" + message + "\x1b[0m";
case 'log':
default:
@christian-schulze
christian-schulze / Hyper.md
Last active August 21, 2021 08:22 — forked from toroidal-code/Hyper.md
Mapping the Hyper key to RALT, RWIN or RCTRL

Mapping the Hyper key to RALT, RWIN or RCTRL

Gnome, Cinnamon, and KDE all use xkb to manage keyboard mappings.

For Gnome, you use gnome-tweak-tool to access all of the xkb options.

I'm working on Ubuntu 21.04 using Gnome 38.8.5, so all of my xkb files are under /usr/share/X11/xkb. Consult your distro's documentation if this is not the case for you.

The first file we're going to be working with is an addition, under symbols in that xkb folder. It should already have a bunch of files like us and dvp etc. We're going to be adding a new file called hyper. So on my computer, this is /usr/share/X11/xkb/symbols/hyper.

@christian-schulze
christian-schulze / _decimal.scss
Created February 11, 2017 10:16 — forked from terkel/_decimal.scss
Rounding decimals in Sass
// _decimal.scss | MIT License | gist.github.com/terkel/4373420
// Round a number to specified digits.
//
// @param {Number} $number A number to round
// @param {Number} [$digits:0] Digits to output
// @param {String} [$mode:round] (round|ceil|floor) How to round a number
// @return {Number} A rounded number
// @example
// decimal-round(0.333) => 0
require 'rubygems'
require 'spoon'
Spoon.spawnp 'jruby', *ARGV
@christian-schulze
christian-schulze / gist:44e0dde4e9e8d824f546
Last active February 7, 2016 07:46 — forked from spiegela/gist:4712000
JRuby & Akka Example
#!/usr/bin/env ruby
require 'java'
require 'scala-library.jar'
require 'config-1.0.0.jar'
require 'akka-actor_2.10-2.1.0.jar'
java_import 'java.io.Serializable'
java_import 'akka.actor.UntypedActor'
java_import 'akka.actor.ActorRef'