Skip to content

Instantly share code, notes, and snippets.

View gto76's full-sized avatar

Jure Šorn gto76

View GitHub Profile
@gto76
gto76 / js-examples.md
Last active November 10, 2015 16:57
Short javascript examples

Js Examples

short javascript examples

function testJson() {
    var aaa = '{"words":{\
    "ena": [{"id": "1","loc": "1"},{"id": "2","loc": "2"}],\
    "dva": [{"id": "4","loc": "2"},{"id": "7","loc": "3"}]\
    }}';
    var bbb = JSON.parse(aaa);
@gto76
gto76 / scala-examples.md
Last active November 10, 2015 16:57
Scala examples

Scala Examples

Sum two inputs:

println(io.Source.stdin.getLines().take(2).map(_.toInt).sum)

Repeat each element of list num times:

def f(num:Int,arr:List[Int]):List[Int] = arr.map(x => List.fill(num)(x)).flatten
@gto76
gto76 / install-scala.sh
Last active November 10, 2015 19:43
Script that installs Scala
#!/bin/bash
#
# Installs Scala.
# Install Scala:
SCALA_VERSION="2.11.1";
wget http://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.tgz
tar xvzf scala-$SCALA_VERSION.tgz
sudo sh -c 'echo "export SCALA_HOME=\"$PWD/scala-'$SCALA_VERSION'\"" >> /etc/profile; echo "export PATH=\"\$PATH:\$SCALA_HOME/bin\"" >> /etc/profile;'
sh /etc/profile
@gto76
gto76 / src-to-pdf.sh
Last active June 5, 2019 17:03
Script that converts source code to PDF
#!/usr/bin/env bash
#
# Creates pdf file from source code.
tex_file=$(mktemp) ## Random temp file name
cat<<EOF >$tex_file ## Print the tex file header
\documentclass{article}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color} %% Allow color names
@gto76
gto76 / js-tanks.html
Created November 10, 2015 19:41
Javascript game - not finished
<!DOCTYPE html>
<html>
<head>
<title>Player Movement using onkeydown/onkeyup (Enhanced version)</title>
<style type="text/css" media="screen">
canvas { border: 1px solid; }
</style>
<script type="text/javascript" charset="utf-8">
/////////////
@gto76
gto76 / bitmap-filters.scala
Created November 11, 2015 14:08
Scala bitmap filters
#!/bin/sh
exec scala "$0" "$@"
!#
import java.io.File
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import javax.imageio.ImageTypeSpecifier
import java.awt.image.DataBufferByte
import java.awt.image.DataBufferInt
@gto76
gto76 / spiral.py
Created April 14, 2018 13:40
Draws spiral of the prime numbers
#!/usr/bin/python3
#
# Usage: spiral.py [MATRIX_HEIGHT]
#
# Draws spiral of the prime numbers. Numbers are arranged in a spiral like this:
# 17 16 15 14 29
# 18 5 4 3 28
# 19 6 1 2 27
# 20 7 8 9 26
# 21 22 23 24 25
@gto76
gto76 / pub_puzzle.py
Created April 14, 2018 19:41
Tries to solve the problem of: 1 1 1 = 6, 2 2 2 = 6, ...
#!/usr/bin/env python3
#
# Usage: pub.py [NUM]
# Tries to solve the problem of:
# 1 1 1 = 6
# 2 2 2 = 6
# 3 3 3 = 6
# ...
import sys
@gto76
gto76 / mandelbrot.py
Created April 14, 2018 19:43
Draws an ASCII mandelbrot set
#!/usr/bin/python3
#
# Usage: man.py
#
import numpy as np
import sys
ASCII_GREYSCALE = " .:-=+*#%@"
@gto76
gto76 / tip.html
Created April 14, 2018 19:46
Draws a tip bubble using JS
<html>
<head>
<script src="d3.v3.min.js" charset="utf-8"></script>
<style>
.bkgrnd {
fill-opacity: 0.5
}
.temp-text {
font-family: Arial, sans-serif;
}