Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile

Variables

var definition default example
URL URL with variables http://nla.gov.au/nla.obj-152644715/dzi?tile={{zoomlevel}}/{{x}}_{{y}}.jpg
x0 First value of X 0
xstep increment of X between consecutive tiles 1
xend last value of X {{ceil(width/tilesize)+x0}}
y0 First value of Y 0
ystep increment of Y between consecutive tiles 1
yend last value of Y {{ceil(height/tilesize)+y0}}
@lovasoa
lovasoa / README.md
Last active December 7, 2016 09:22
Download and assemble tiles of an image
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
template <class T>
T lagrange(vector<T> xs, vector<T> ys, T x) {
T res = 0;
T mul;
@lovasoa
lovasoa / inverse.hs
Created November 8, 2016 16:17
Modular multiplicative inverse in Haskell
-- Inverses a modulo b
inverse b a =
let
next a b = zipWith (-) a $ map (*(head $ zipWith div a b)) b
l = [a,0] : [b,1] : zipWith next l (tail l)
in
head $ tail $ head $ filter ((==1).head) l
@lovasoa
lovasoa / prix.hs
Last active November 11, 2016 12:45
A shop is giving 10% of the price you pay free for the next thing you buy. You need to buy n things. In what order should you pay them in order to spend as few money as possible ?
-- A shop is giving a voucher of 10% of the price you pay for everything you buy.
-- The voucher is usable only on the next article you buy.
-- You need to buy n things. In what order should you pay them in order to spend as few money as possible ?
-- Example:
-- You need to buy 3 articles, which cost respectively $1, $10 and $100
-- Then you should buy them in the following order: $1, $100, $10
-- Thus, you will pay 1 + 100 - 1 * 10% + 10 - (100 - 1 * 10%) * 10% = 1 + 99.9 + 0.01 = 100.91
-- This is better than you would do with any other ordering.
@lovasoa
lovasoa / mergesort.hs
Created November 14, 2016 13:41
Merge sort
import Data.Function
merge :: Ord a => [a] -> [a] -> [a]
merge [] x = x
merge x [] = x
merge (x:xs) (y:ys)
| x < y = x:merge xs (y:ys)
| otherwise = y:merge (x:xs) ys
sort :: Ord a => [a] -> [a]
@lovasoa
lovasoa / 00-MapSideJoinDistCacheTextFile
Last active November 17, 2016 01:10 — forked from airawat/00-MapSideJoinDistCacheTextFile
Map-side join example- Java code for joining two datasets - one large (tsv format), and one with lookup data (text), made available through DistributedCache
This gist demonstrates how to do a map-side join, loading one small dataset from DistributedCache into a HashMap
in memory, and joining with a larger dataset.
Includes:
---------
1. Input data and script download
2. Dataset structure review
3. Expected results
4. Mapper code
5. Driver code
@lovasoa
lovasoa / spark-starjoin.py
Created November 17, 2016 12:53
Spark star JOIN with small dimension tables
# Spark star JOIN with all dimension tables in cache
# Ophir LOJKINE, 2016
from __future__ import print_function
import sys
from operator import add
from pyspark import SparkContext
@lovasoa
lovasoa / README.md
Last active December 7, 2016 17:13
Delay differential equations in Haskell

ddeint.hs

Delay differential equations in Haskell

How to use

Download

Download ddeint.hs and a haskell compiler (in ubuntu: sudo apt install ghc)

Specify your ODE

import Data.List
import qualified Data.Vec as Vec
dt = pi/100
t0 = 0
tmax = 50
dydt :: (Double -> Vec.Vec2D) -> Double -> Vec.Vec2D
dydt y t =
Vec.Vec2D