Skip to content

Instantly share code, notes, and snippets.

View agrison's full-sized avatar

Alexandre Grison agrison

View GitHub Profile
@agrison
agrison / RedisMassInport.java
Created July 22, 2015 14:14
Simple spring boot app with Jedis inserting 1M keys in redis using pipelining and multi-threading
package me.grison.redis.foo;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;
@agrison
agrison / problems.py
Last active September 30, 2022 16:59
Five programming problems every Software Engineer should be able to solve in less than 1 hour... in Python
# This is a solution to a blog post I just found at https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
# I wrote it in Python because it shines for such challenges.
# It took me approximately 35 minutes (edit: added 5 minutes because of a bug in problem #4), so if I trust the internet, I'm definitely a Software Engineer.
# How cool is that? :-)
# Problem 1
# ---------
# Write three functions that compute the sum of the numbers in a given list
# using a for-loop, a while-loop, and recursion.
def problem1_1(l):
@agrison
agrison / foomt.go
Created July 23, 2015 08:25
Sample Go App to mass insert 1M keys in redis using goroutines and unix socket
package main
import (
"fmt"
"log"
"net"
"runtime"
"sync"
"time"
@agrison
agrison / foo.md
Last active June 25, 2020 18:38
XSLT + EDN = XDN \o/

XDN

XDN is a Clojure(script) library for transforming EDN to EDN using EDN.

I shouldn't have done that.

Quick Start

Imagine you have this

@agrison
agrison / monoid.clj
Created October 21, 2019 14:55
Write a function that takes the identity and the 2-arg case and returns a new function that implements the monoid pattern
(defn monoid [id f]
(fn
([] id)
([a] (f id a))
([a b] (f a b))
([a b & more] (reduce f (f a b) more))))
@agrison
agrison / runp-timeout.clj
Created October 14, 2019 13:41
runp! runs a given function on a given collection in parallel.
(defn runp!
"Runs the function `f` in parallel on the given collection `coll`.
It will use (by default) the same numbers of threads as there are cores available on the system.
You can set a specific number of threads using `:threads` waits maximum `:timeout` milliseconds."
([f coll {:keys [threads timeout] :or {threads (.availableProcessors (Runtime/getRuntime))}}]
(let [pool (java.util.concurrent.Executors/newFixedThreadPool threads)
tasks (map (fn [e] (fn [] (f e))) coll)]
(try
(doseq [future (.invokeAll pool tasks)]
(.get future))
@agrison
agrison / grid.h
Created May 16, 2018 08:43
Tic tac toe
#ifndef TICTACTOE_GRID_H
#define TICTACTOE_GRID_H
#define COLOR1 "\x1B[32m"
#define COLOR2 "\x1B[35m"
#define NORMAL "\x1B[0m"
#define GRID "\t\t+-------+-------+-------+\n" \
"\t\t| | | |\n" \
"\t\t| %s | %s | %s |\n" \
#define GRID "\t\t+-------+-------+-------+\n" \
"\t\t| | | |\n" \
"\t\t| %s | %s | %s |\n" \
"\t\t| 1| 2| 3|\n" \
"\t\t+-------+-------+-------+\n" \
"\t\t| | | |\n" \
"\t\t| %s | %s | %s |\n" \
"\t\t| 4| 5| 6|\n" \
"\t\t+-------+-------+-------+\n" \
"\t\t| | | |\n" \
@agrison
agrison / pom.xml
Created September 28, 2016 12:22
Monster Component in Java & Spring pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
@agrison
agrison / Spark.java
Created October 30, 2016 16:23
spark java 8 count
JavaRDD<String> textFile = sc.textFile("hdfs://...");
JavaPairRDD<String, Integer> counts = textFile
.flatMap(line -> Arrays.asList(line.split(" ")))
.mapToPair(w -> new Tuple2<>(w, 1))
.reduceByKey((x, y) -> x + y);
counts.saveAsTextFile("hdfs://...");