Skip to content

Instantly share code, notes, and snippets.

View PanJarda's full-sized avatar

Jaroslav Pernica PanJarda

  • Prague, Czech Republic
View GitHub Profile
@PanJarda
PanJarda / contract.js
Last active November 1, 2020 13:05
Contractual programming in js concept
const DEV = true;
function contract(conditions) {
if (DEV) {
return function(fn) {
return function() {
if (!conditions.pre.apply(null, arguments)) {
throw 'precondition failed on ' + fn.name
}
#!/usr/bin/awk -f
#
# csv format:
# firstname, lastname, tel
#
# ./csv2vcf.awk [filename.csv] > out.vcf
BEGIN {
FS=","
OFS=""
}
@PanJarda
PanJarda / state.js
Last active December 8, 2020 06:18
Design patterns: State
"use strict"
var DesignPatterns = {};
DesignPatterns.Utils = (function() {
function BadMethodCallException(message) {
this.message = message;
this.name = "BadMethodCallException";
}
/*
* parsecsv.js
*
* by: JP 2019
*
* example:
* res = [];
* if (err = parsecsv('1,2,3\n4,5,6', res))
* console.error(err);
* // res <-- [["1","2","3"],["4","5","6"]]
@PanJarda
PanJarda / csv2arr.js
Last active November 2, 2019 00:22
CSV RFC 4180 parser
/*
* CSV parser
*
* See RFC 4180 for CSV format specification.
*
* License MIT
* JP2019
*/
/**
@PanJarda
PanJarda / intervalmatch.js
Created October 25, 2019 18:17
detects if value belongs to set of intervals and tells you to which one.
/*
* Y-Combinator
*/
const Y = fn =>
( m => (...args) => fn(m(m))(...args))
( m => (...args) => fn(m(m))(...args));
/*
* Creates function that resolves if given value belongs
@PanJarda
PanJarda / helpers.js
Last active October 17, 2019 01:39
js helpers
const throttle = fn => timeout => id => (...e) =>
!id && (id = setTimeout(() => (id = null) || fn(...e), timeout || 100))
const Y = fn => (m => x => fn(m(m))(x))(m => x => fn(m(m))(x))
"use strict"
var LEXICAL_GRAMMAR = {
"SingleLineComment": "Comment",
"MultiLineComment": "Comment",
"/*": {
"MultilineCommentChars": {
"*/": "MultiLineComment"
},
"*/": "MultiLineComment"
"use strict"
var Lexer = (function() {
var Context = (function() {
var SPECIAL_CHARS = {
"=": "OP",
"-": "OP",
"+": "OP",
#!/usr/bin/awk -f
# transforms txt into gpx format
BEGIN {
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<gpx creator=\"jardacardapetarda\" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n <trk>\n <name></name>\n <trkseg>"
}
/^[0-9]/ {
print "<trkpt lat=\"" $1 "\" lon=\"" $2 "\"></trkpt>"
}