Skip to content

Instantly share code, notes, and snippets.

View ezsi's full-sized avatar

Bela Ezsias ezsi

  • Budapest
View GitHub Profile
@ezsi
ezsi / LongSet.scala
Created March 18, 2016 10:17
LongSet impl
import java.util
class LongSet {
val buckets = scala.collection.mutable.HashMap[Int, util.BitSet]()
private def position(n: Long): (Int, Int) =
( (n / Int.MaxValue).toInt, (n % Int.MaxValue).toInt)
def set(n: Long): Unit = {
@ezsi
ezsi / ProtoBufEncoder.scala
Created May 9, 2015 13:27
ProtoBuf encoder for Kafka
class ProtoBufEncoder(props: VerifiableProperties = null) extends Encoder[com.google.protobuf.GeneratedMessage] {
override def toBytes(protoBufMessage: com.google.protobuf.GeneratedMessage): Array[Byte] = protoBufMessage.toByteArray
}
@ezsi
ezsi / js-curry
Last active August 29, 2015 14:06
JavaScript: currying function
// Currying: f(f1,...,fn) -> f(f1,...,fk)(fk+1,...,fn)
// Usage: f.curry(f1,...,fk) -> g(fk+1,...fn) == f(f1,...,fn)
Function.prototype.curry = function() { //f(f1,...,fk)
if( arguments.length == 0 )
return this;
var args = arguments;
var fn = this;
return function() { // g(fk+1,...,fn)
var prefix = Array.prototype.slice.call(args);
var suffix = Array.prototype.slice.call(arguments);
@ezsi
ezsi / ng-enter
Created September 16, 2014 18:47
AngularJS: directive for enter event
app.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
@ezsi
ezsi / show-focus
Created September 16, 2014 18:45
AngularJS: directive to auto focus input field when ng-show is triggered
app.directive('showFocus', function($timeout) {
return function(scope, element, attrs) {
scope.$watch(attrs.showFocus,
function (newValue) {
$timeout(function() {
newValue && element.focus();
});
},true);
};
});
L.Control.Button = L.Control.extend({
options: {
position: 'bottomleft'
},
initialize: function (options) {
this._button = {};
this.setButton(options);
},
@ezsi
ezsi / Tools.java
Created June 8, 2014 08:43
Function decorators using Java8 lambdas
package repl;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
public class Tools {
public static final boolean CACHE_ON = true;
public static final boolean TIMER_ON = true;
@ezsi
ezsi / gist:6204708
Last active December 20, 2015 22:19
Java: list files in a directory
Files.walkFileTree(Paths.get(dir), new SimpleFileVisitor<Path>() {
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs)
throws IOException{
// insert code here
return FileVisitResult.CONTINUE;
}
});