Skip to content

Instantly share code, notes, and snippets.

@genotrance
genotrance / duktape.nim
Created June 28, 2020 02:21
Nim wrapper for duktape using nimterop
# nim c -d:FLAGS duktape.nim
#
# FLAGS
# -d:duktapeStd | -d:duktapeDL | -d:duktapeConan
# -d:duktapeSetVer=2.5.0
# -d:duktapeStatic
import nimterop/[build, cimport]
static:
enum BarcodeScanner.Error {
Unkown
}
module BarcodeScanner {
fun scan : Promise(BarcodeScanner.Error, String) {
`
new Promise((resolve, reject) => {
cordova.plugins.barcodeScanner.scan((result) => {
resolve(result.text)
@cjgajard
cjgajard / app.cr
Last active September 12, 2019 08:20
Kemal controllers pattern
# src/{{app_name}}.cr
require "kemal"
require "./controllers/*"
alias Env = HTTP::Server::Context # this could be provided by Kemal
module Main
get "/", &->index(Env)
get "/:name", &->greet(Env)
end
function findTByKeyValue (element, target){
var found = true;
for(var key in target) {
if (!element.hasOwnProperty(key) || element[key] !== target[key]) {
found = false;
break;
}
}
if(found) {
@costajob
costajob / fact.cr
Last active September 20, 2022 21:15
Factorial implementation using Big numbers in Ruby, GO and Crystal
require "big_int"
def fact(n)
return 1 if n == 0
n * fact(n - 1)
end
n = BigInt.new(ARGV[0])
puts fact(n)
@wassname
wassname / permutations.js
Last active June 28, 2022 22:53
Combinatorics permutatons and product in javascript using lodash.js (like python's itertools)
/**
* Lodash mixins for combinatorics
* by: wassname & visangela
* url: https://gist.github.com/wassname/a882ac3981c8e18d2556/edit
* lodash contrib issue: https://github.com/node4good/lodash-contrib/issues/47
* lic: same as lodash
* Inspired by python itertools: https://docs.python.org/2.7/library/itertools.html
*
* Usage:
* permutations([0,1,2],2) // [[0,1],[0,2],[1,0],[1,2],[2,0],[2,1]]