Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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) {