Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
if [ $# -eq 0 ]; then
exit 0;
elif [ $# -eq 1 ]; then
printf "$@"
exit 0
fi
msg=${@: -1:1}
trait SourceInfo {
type NoInfoType <: this.type
val NoInfo: NoInfoType
def showMessage(msg: String): String
}
object NoPositionInfo extends PositionInfo(NoPosition) {
override def showMessage(msg: String): String = s"${pos.toString}: $msg"
}
@susisu
susisu / seq.js
Last active October 13, 2017 05:12
function* seq(a, b, delta = 1) {
let num = a;
let correction = 0;
while (num <= b) {
yield num;
const delta_ = delta - correction;
const next = num + delta_;
correction = (next - num) - delta_;
num = next;
}
package {
import flash.events.SampleDataEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.utils.ByteArray;
public class LoopPlayer extends Object{
private var sound:Sound;
private var loopStart:Number;
private var loopEnd:Number;
private var channel:SoundChannel;
type Inconsistent = { foo: string } & { foo: number };
// const obj: Inconsistent = { foo: 123 }; // error, consistently
function trick<O: {}, K: string, V>(obj: O, key: K, val: V): O & { [K]: V } {
obj[key] = val;
return obj;
}
const obj = trick({ foo: "bar" }, "foo", 123);
let rec length1 = function
| [] -> 0
| _ :: tl -> 1 + length1 tl
let length2 list =
let rec _length2 n = function
| [] -> n
| _ :: tl -> _length2 (n + 1) tl
in
_length2 0 list
function shortenWord(word) {
return word.length <= 3
? word
: word[0] + (word.length - 2).toString() + word[word.length - 1];
}
function shorten(str) {
return str.replace(/[^\d\W]+/g, shortenWord);
}
@susisu
susisu / init.coffee
Last active April 2, 2018 10:18
My Atom configs
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to make opened Markdown files always be soft wrapped:
#
# path = require 'path'
#
{
"parserOptions":{
"ecmaVersion": 8
},
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
'atom-text-editor:not(.mini):not(.autocomplete-active).markdown-table-editor-active':
'tab': 'markdown-table-editor:next-cell'