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 / 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 / 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:27d400705e2299c0cf8aa4f52e1fd6aa
Created March 3, 2017 15:25 — forked from debasishg/gist:8172796
A collection of links for streaming algorithms and data structures
  1. General Background and Overview
@IgorBerman
IgorBerman / visualvmEc2Jmx.txt
Last active April 9, 2017 07:32
visualvm ec2 jmx
1. Setup your process java properties
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1098 -Dcom.sun.management.jmxremote.rmi.port=1098 -Djava.rmi.server.hostname=127.0.0.1
2. ssh to your server on ec2 with a) port forwarding of 1098(jmx port) and b) with socks server on 10003
ssh -L 1098:127.0.0.1:1098 -D 10003 my.ec2.instance.com
3. Open visualvm with socks proxy on on same proxy port
jvisualvm -J-DsocksProxyHost=localhost -J-DsocksProxyPort=10003
4. create local jmx connection on localhost:1098 in visualvm