Skip to content

Instantly share code, notes, and snippets.

@Arth-ur
Arth-ur / robogen-dl.js
Last active April 28, 2017 10:17
Download directory in robogen app
(function() {
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
var d = window.prompt("Please enter the name of the directory you want to download", document.querySelector("#uploader>h1").attributes["data-path"].value);
var r = window.indexedDB.open("/localStorage");
var saveData = (function() {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function(data, fileName) {
var blob = new Blob([data], {
var x = [
{ mykey: 'mykey1', myvalue: 'myvalue1' },
{ mykey: 'mykey2', myvalue: 'myvalue2' }
]
var array = x.reduce((o, c) => Object.defineProperty(o, c.mykey, {value: c.myvalue}), {})
// result: array = { mykey1: myvalue1, mykey2: myvalue2 }
// 60 bytes: x.reduce((o,c)=>Object.defineProperty(o,c.k,{value:c.v}),{})
@Arth-ur
Arth-ur / rands.py
Created January 5, 2017 19:12
A function to create a random string of given length composed of letters and digits.
import random
import string
def rands(length):
""" return a random string of given length composed of letters and digits """
return ''.join(random.choice(string.letters+string.digits) for _ in range(length))
@Arth-ur
Arth-ur / array_chunk.ijs
Created September 17, 2016 13:04
Split an array into chunks in J.
array_chunk =: ((%~#),[)$]
NB. Test #1
input =: 1 2 3 4 5 6
expected =: 3 2 $ input
result =: 2 array_chunk input
assert result = expected
NB. Test #2
input =: 1 2 3 4 5 6