Skip to content

Instantly share code, notes, and snippets.

@juriad
juriad / cda-data.py
Created March 24, 2017 17:06
Sample data for Creditor-Debtor-Amount example
# Original data
# (Creditor, Debtor, Amount)
(James, Mary, 1300)
(Mary, Robert, 2500)
(Mary, Michael, 500)
(Barbara, Linda, 1200)
(Linda, Robert, 300)
# Mapped to two individual records
# (Person, Amount)
@juriad
juriad / Launcher.java
Created March 15, 2017 14:02
Start processing in yarn-cluster mode and await the end
public void run(String planFileOnHdfs) throws IOException, InterruptedException {
SparkLauncher sparkLauncher = new SparkLauncher();
SparkAppHandle handle = sparkLauncher
.setAppResource("cif.hadoop.boot.jar")
.setMainClass("com.ataccama.dqc.hadoop.launcher.HadoopClusterLauncher")
.setMaster("yarn-cluster")
.addAppArgs(planFileOnHdfs)
.startApplication();
CountDownLatch countDownLatch = new CountDownLatch(1);
@juriad
juriad / Histogram.java
Created March 15, 2017 13:52
Create a histogram of people's balances using Spark
class CDA {
String creditor;
String debtor;
int amount;
}
public List<Tuple2<Integer, Integer>> createHistogram(JavaRDD<CDA> inputRDD) {
return inputRDD
.flatMapToPair(cda -> Arrays.asList(
new Tuple2<>(cda.creditor, cda.amount),
@juriad
juriad / excerpt.php
Created March 30, 2016 14:47
Zvýraznění hledaného výrazu v textu s ignorováním velikosti písma a diakritiky; v PHP
<?php
class Excerpt {
# transformation rules for characters common in Central Europe
# at the end there are all [:space:] characters transforrmed to a single space
private static $transformation = [
'ä'=>'a',
'Ä'=>'A',
'á'=>'a',
'Á'=>'A',
public void test() throws TheDoctorException {
long currentTimeMillis = System.currentTimeMillis();
long lastTimeInMillis = getLastKnownTimestamp(currentTimeMillis);
long tamperedTimeInMillis = getTamperedTimestamp(currentTimeMillis);
// logger.debug("Last time: " + lastTimeInMillis + "; tampered time: " + tamperedTimeInMillis);
if (currentTimeMillis < lastTimeInMillis - TIME_OFFSET
|| tamperedTimeInMillis < lastTimeInMillis - TIME_OFFSET) {
block(tamperedTimeInMillis, lastTimeInMillis);
@juriad
juriad / loadCSV.php
Created April 13, 2015 19:18
Loader of any hierarchical data from CSV to database; created for http://djpw.cz/162555
<?php
function buildIndex($header) {
$index = array();
$i = 0;
foreach ($header as $field) {
$index[strtolower(trim($field))] = $i;
$i++;
}
return $index;
@juriad
juriad / Skript
Created March 15, 2015 17:28
Skript na Evoluční robotiku
from pylab import *
from numpy import random
from itertools import *
def matrixCreate(rows, cols, mi=-1, ma=1):
'''
Generates a matrix of size a x b filled with random numbers with uniform distribution in specified range.
'''
return rand(rows, cols) * (ma - mi) + mi
@juriad
juriad / Duplicate channels
Last active August 29, 2015 14:13
VDR - duplicate channels issue
Result of: sed 's/^[^ ]* \(...............\).*/\1/' channels | sort | uniq -c | sort -n
10 Eurosport360HD
13 DECODEUR:12402:
13 Sky Bundesliga
19 MEDIA BROADCAST
58 .;BetaDigital:1
98 CT sport HD pre
98 HBO Comedy_PREL
98 HBO HD_PRELADTE
@juriad
juriad / propagator-if-then-else.c
Created November 9, 2014 08:02
Propagator for if-then-else construct.
// the propagated constraint is:
// Z = if B then X else Y endif
// propagator for Z:
if (lb(B) < ub(B)) { // B is not fixed
setlb(Z, min(lb(X), lb(Y));
setub(Z, max(ub(X), ub(Y));
} else if (lb(B) == 1) { // B is fixed and B = 1
setlb(Z, lb(X));
setub(Z, ub(X));
@juriad
juriad / torus.cpp
Created October 17, 2014 13:43
Torus rendering - transparency working
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
// Include GLEW
#include <GL/glew.h>
// Include GLFW
#include <GLFW/glfw3.h>
GLFWwindow* window;