Skip to content

Instantly share code, notes, and snippets.

postgresql:
image: postgres-image
mem_limit: 4001000000
ports:
- "5432:5432"
volumes:
- /opt/docker/data/postgresql/9.4/main:/var/lib/postgresql/data
zookeeper:
image: wurstmeister/zookeeper
mem_limit: 256000000
A string S consisting of N characters is called properly nested if:
S is empty;
S has the form "(U)" where U is a properly nested string;
S has the form "VW" where V and W are properly nested strings.
For example, string "(()(())())" is properly nested but string "())" isn't.
Write a function:
class Solution {
@vltsu
vltsu / gist:fc5f1daeefc68b7a8067
Created December 24, 2015 16:02 — forked from lukas-vlcek/gist:5143799
Adding a new analyzer into existing index in Elasticsearch (requires close/open the index). Tested with Elasticsearch 0.19.12.
// create an index with an analyzer "myindex"
curl -X PUT localhost:9200/myindex -d '
{
"settings" : {`
"index":{
"number_of_replicas":0,
"number_of_shards":1,
"analysis":{
"analyzer":{
"first":{
vltsu@vltsu-pc:~/Desktop$ hadoop jar /usr/lib/hadoop-mapreduce/hadoop-mapreduce-examples.jar grep input output23 'dfs[a-z.]+'
15/03/21 19:46:30 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
15/03/21 19:46:30 WARN mapreduce.JobSubmitter: No job jar file set. User classes may not be found. See Job or Job#setJar(String).
15/03/21 19:46:30 INFO input.FileInputFormat: Total input paths to process : 4
15/03/21 19:46:30 INFO mapreduce.JobSubmitter: number of splits:4
15/03/21 19:46:30 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1426946641895_0004
15/03/21 19:46:30 INFO mapred.YARNRunner: Job jar is not present. Not adding any jar to the list of resources.
15/03/21 19:46:30 INFO impl.YarnClientImpl: Submitted application application_1426946641895_0004
15/03/21 19:46:30 INFO mapreduce.Job: The url to track the job: http://vltsu-pc:8088/proxy/application_1426946641895_0004/
15/03/21 19:46:30 INFO mapreduce.Job: Running job: job_1426946641895_0004
@vltsu
vltsu / tcmdumpsample
Created March 11, 2015 01:38
TCPdumpSample
sudo tcpdump -i lo0 -A -s 0 'tcp port 8081 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' // show http request and headers for localhost on port 8081
@Entity
public class Employee {
@Id long empId;
String empName;
...
}
public class DependentId {
String name; // matches name of @Id attribute
long emp; // matches name of @Id attribute and type of Employee PK
@vltsu
vltsu / java_how_to_s
Last active December 23, 2015 17:19
Java how-to's
// determine field type
if f.getType().isAssignableFrom(String.class)
if f.getType().equals(boolean.class)
if f.getType().isAssignableFrom(Date.class)
// if object is string
if (myObject instanceof String) { ... }
@vltsu
vltsu / deploy.rb
Created July 5, 2012 14:09 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn (production-ready setup)
# Capistrano configuration
#
# require 'new_relic/recipes' - Newrelic notification about deployment
# require 'capistrano/ext/multistage' - We use 2 deployment environment: staging and production.
# set :deploy_via, :remote_cache - fetch only latest changes during deployment
# set :normalize_asset_timestamps - no need to touch (date modification) every assets
# "deploy:web:disable" - traditional maintenance page (during DB migrations deployment)
# task :restart - Unicorn with preload_app should be reloaded by USR2+QUIT signals, not HUP
@vltsu
vltsu / gist:3016719
Created June 29, 2012 08:47
migration
class SetDefaultCanonicalUrlsForCollects < ActiveRecord::Migration
def change
Account.find_in_batches(:batch_size => 300) do |accounts|
execute "commit;"
accounts.each do |account|
execute "
UPDATE collects
SET is_canonical_url = true
WHERE id in (
SELECT DISTINCT ON (product_id) id FROM collects WHERE product_id IN (
@vltsu
vltsu / gist:2985053
Created June 24, 2012 21:22
import from a CSV file
require 'csv'
namespace :users do
desc "Import users from csv"
task :import => :environment do
path = ENV.fetch("CSV_FILE") {
File.join(File.dirname(__FILE__), *%w[.. .. db data users.csv])
}
CSV.foreach(path, headers: true, header_converters: :symbol) do |row|
User.create(row.to_hash)