Simple scripts

Run code in a code block.

Create an array of the past seven days, inclusive

let array = [...Array(7).keys()].map(days => new Date( - 86400000 * days));
console.log( array );

Generate a random alphanumerical string of length 11.

let id = Math.random().toString(36).substring(2);

Return a shuffled copy of an Array-like.

let fnShuffle = (arr) => arr.slice().sort(() => Math.random() - 0.5)
console.log( fnShuffle([1,2,3,4,5,6,7,8,9,10]) );

Generate random color.

let randomHex = '#' + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, '0');
console.log( randomHex );

Remove duplicates.

let arr = [1,2,3,3];
console.log( [ Set(arr)] );

This only works with primitives but it’s still nifty. Set takes any iterable object, like an array [1,2,3,3], and removes duplicates. The spread operator makes that set [1,2,3].

Fizz buzz


Print keyboard.

let keyboard = (_=>[..."`1234567890-=~~QWERTYUIOP[]\\~ASDFGHJKL;'~~ZXCVBNM,./~"].map(x=>(o+=`/${b='_'.repeat(w=x<y?2:' 667699'[x=["BS","TAB","CAPS","ENTER"][p++]||'SHIFT',p])}\\|`,m+=y+(x+'    ').slice(0,w)+y+y,n+=y+b+y+y,l+=' __'+b)[73]&&(k.push(l,m,n,o),l='',m=n=o=y),m=n=o=y='|',p=l=k=[])&&k.join`


Other languages

In the section above you saw examples of script cells and JavaScript language. Here are more examples for Python, Ruby, and Java. Feel free to modify the cell and run your snippet:


print("hello world!");


class HelloWorld {
    public static void main(String[] args) {
        System.out.println("hello world!");


print 'hello world!'