Skip to content

Instantly share code, notes, and snippets.

View zygm0nt's full-sized avatar
🥑
AFK

Marcin Cylke zygm0nt

🥑
AFK
View GitHub Profile
@zygm0nt
zygm0nt / logging-monoid.scala
Created April 15, 2014 07:54
Logging via monoid
trait Monoid[A] {
def append(a1: A, a2: A): A
def empty: A
}
object Monoid {
implicit def ListMonoid[A]: Monoid[List[A]] = new Monoid[List[A]] {
def append(a1: List[A], a2: List[A]) = a1 ::: a2
def empty = Nil
}
package foo.bar
import spray.routing._
import spray.http._
import spray.http.StatusCodes.Forbidden
// See https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
case class Origin(origin: String) extends HttpHeader {

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

Results

@zygm0nt
zygm0nt / static.spray.scala
Created March 11, 2014 08:46
spray - serve static files
import spray.routing.HttpService
import spray.httpx.SprayJsonSupport
import scala.concurrent.ExecutionContext
trait StaticWebService extends HttpService with SprayJsonSupport {
implicit def executor: ExecutionContext
def staticRoute =
pathPrefix("swagger") {
@zygm0nt
zygm0nt / spray-route.scala
Created March 11, 2014 08:31
scala spray route debugging
trait AbcService with UnhandledRouteDebug {
override def receive: Actor.Receive = runRoute(logRequestResponse(myLog _) {
staticRoute ~ internalRoutes ~ routes
})
}
trait UnhandledRouteDebug {
def myLog(request: HttpRequest): Any => Option[LogEntry] = {
case x: HttpResponse => {
println (s"Normal: $request")
@zygm0nt
zygm0nt / hbaseClient.java
Created December 8, 2013 20:29
hbase-annotations example usage
SampleHBaseClient client = new SampleHBaseClient(cluster.getConfig());
SampleEntity entity = client.get(new Get(Bytes.toBytes("1")), TEST_TABLE);
@zygm0nt
zygm0nt / setlayout.c
Created December 6, 2013 10:04
Set layout to a desired geometry. Usually run with: ./setlayout 0 4 2 0
/* To compile this program, run
* gcc -o setlayout setlayout.c -lX11
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
/* orientation of pager */
@zygm0nt
zygm0nt / ConvertIniSectionToClass.java
Created September 17, 2013 09:41
Bean binding with ini4j is seriously f**ked. I've written a quick and dirty custom converter for that use case. Read more in README.md - https://gist.github.com/zygm0nt/6592208#file-readme-md
import com.google.common.base.Joiner;
import org.apache.commons.lang3.StringUtils;
import org.ini4j.Ini;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ConvertIniSectionToClass {
set terminal pngcairo size 1600,768 enhanced font 'Verdana,10'
set output output_filename
# Line style for axes
set style line 80 lt 0
set style line 80 lt rgb "#808080"
# Line style for grid
set style line 81 lt 3 # dashed
set style line 81 lt rgb "#808080" lw 0.5 # grey
@zygm0nt
zygm0nt / hive-default-1223123...xml
Last active December 14, 2015 04:29
Problems with hive-server 0.10.0 - logs for problem report.
<?xml version="1.0" encoding="UTF-8" standalone="no"?><configuration>
<property><name>hive.ppd.remove.duplicatefilters</name><value>true</value><source>programatically</source></property>
<property><name>hive.stats.jdbc.timeout</name><value>30</value><source>programatically</source></property>
<property><name>hive.skewjoin.mapjoin.map.tasks</name><value>10000</value><source>programatically</source></property>
<property><name>hadoop.bin.path</name><value>/usr/lib/hadoop/bin/hadoop</value><source>programatically</source></property>
<property><name>job.end.retry.interval</name><value>30000</value><source>mapred-default.xml</source></property>
<property><name>io.bytes.per.checksum</name><value>512</value><source>core-default.xml</source></property>
<property><name>hive.hwi.listen.port</name><value>9999</value><source>programatically</source></property>
<property><name>hive.skewjoin.key</name><value>100000</value><source>programatically</source></property>
<property><name>mapred.job.tracker.retiredjobs.cache.size<