Skip to content

Instantly share code, notes, and snippets.

@IgorBerman
IgorBerman / double_locking_ar
Created August 12, 2014 12:22
double locking on atomic reference(is it correct?)
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
public class Test {
private AtomicReference<Config> configHolder = new AtomicReference<Config>();
private static final class Config {
private final Map<String, Double> factorsMap;
Config(Map<String, Double> factorsMap) {
@IgorBerman
IgorBerman / concurrentMapsOneOnlyInitialization
Created August 18, 2014 11:21
ConcurrentMap inside another ConcurrentMap with 1 only initialization
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Provider;
public class Test {
//it's safe to read from it concurrently, however we don't want that same bean will be created twice
private ConcurrentHashMap<String, ConcurrentMap<String, Object>> scopes
= new ConcurrentHashMap<String, ConcurrentMap<String, Object>>(50);
@IgorBerman
IgorBerman / cleanup_custom_not_used_workspaces.groovy
Last active February 16, 2017 09:30
cleanup custom not used workspaces on all jenkins slaves
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
def DRY_RUN = false
def DIRS_FILTER = ['.hg', 'production','logs','apache', 'projects', 'qlickview']
def JOBS_WS_ROOT = 'path-to-your-workspaces-root-dir'
def JOBS_IRRELEVANT_SYMBOLS = "[_,-]|\\s"
def allJobs = Jenkins.instance.items.findAll { it instanceof hudson.model.Job }.collect { it.name };
@IgorBerman
IgorBerman / gist:8a9b06fff891eb038b51
Created November 23, 2014 22:09
some usefull queries from pg_hero
require "pghero/version"
require "active_record"
require "pghero/engine" if defined?(Rails)
module PgHero
# hack for connection
class Connection < ActiveRecord::Base
establish_connection ENV["PGHERO_DATABASE_URL"] if ENV["PGHERO_DATABASE_URL"]
end
@IgorBerman
IgorBerman / register-citext
Created December 10, 2014 15:56
citext registration
def register_citext_type(conn, con_record):
from psycopg2.extensions import new_type, register_type
from contextlib import closing
def cast_citext(in_str, cursor):
if in_str == None:
return None
return unicode(in_str, cursor.connection.encoding)
citext_oid = None
with closing(conn.cursor()) as c:
@IgorBerman
IgorBerman / spark-twitter-streaming-window
Last active August 29, 2015 14:14
spark-twitter-streaming-windows
download twitter core, stream and spark-streaming-twitter from maven central and place them into spark/lib
run from bin directory:
spark-shell --jars ../lib/twitter4j-core-3.0.3.jar,../lib/twitter4j-stream-3.0.3.jar,../lib/spark-streaming-twitter_2.10-1.2.0.jar
--------------------------------------------------------------
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.streaming.twitter._
import java.io.FileWriter
val filters = List("postgres", "timeseries")
@IgorBerman
IgorBerman / multithreaded-bulk-loader
Created February 10, 2015 13:36
cassandra multithreaded bulk load
package com.myproject.cassandraloading;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
@IgorBerman
IgorBerman / AvroSinkWriter.java
Created April 27, 2016 16:22
Avro writer for flink rolling sink
package org.apache.flink.streaming.connectors.fs.avro;
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
@IgorBerman
IgorBerman / find-ip-with-knife-search.sh
Created November 21, 2016 09:03
find ip address with knife search
knife search "recipes:xxx*" -a ipaddress | grep ipaddress | awk '{print $2}'
@IgorBerman
IgorBerman / ExceptionHandlingExample.java
Created January 26, 2017 10:22
akka streams in java with kill switch, shutdown hook and error handling
package com.example;
import java.util.concurrent.CompletionStage;
import scala.concurrent.Await;
import scala.concurrent.duration.Duration;
import akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.japi.Pair;