Skip to content

Instantly share code, notes, and snippets.

View asv's full-sized avatar
👨‍🦳
stay awhile and listen

Aleksei Smirnov asv

👨‍🦳
stay awhile and listen
View GitHub Profile
#! /usr/bin/env bash
set -e
if [[ $(docker inspect -f '{{ range .Mounts }}{{ if eq .Name "zk-data" }}{{ .Destination }}{{ end }}{{ end }}' zookeeper) == '/var/lib/zookeeper' ]]; then
VID1=$(docker inspect -f '{{ range .Mounts }}{{ if eq .Destination "/var/lib/zookeeper" }}{{ .Source }}{{ end }}{{ end }}' zookeeper)
VID2=$(docker inspect -f '{{ range .Mounts }}{{ if eq .Destination "/var/lib/zookeeper/data" }}{{ .Source }}{{ end }}{{ end }}' zookeeper)
rm -fr $VID1
cp -R $VID2 $VID1
fi
@asv
asv / zkcli.py
Last active March 10, 2017 12:02
#! /usr/bin/env python2
import argparse
from kazoo.client import KazooClient
from kazoo.exceptions import NoNodeError
ZK_DEFAULT_HOST = 'localhost:2181'
package helpers;
import com.google.maps.PendingResult;
import java.util.concurrent.CompletableFuture;
/**
* Helper methods for Google Maps API.
*/
public final class GoogleMapsApiHelper {
@asv
asv / DbTestBase.java
Created July 22, 2015 06:45
dbunit (springtestdbunit) postgresql truncate + reset sequences
package foo;
import com.github.springtestdbunit.TransactionDbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DbUnitConfiguration;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@asv
asv / gist:a286b8aefb972af8f62c
Last active August 29, 2015 14:16
Bash titleize / camelize (bash 4)
titleize() {
local title=$@
local title_arr=( $title )
echo "${title_arr[*]^}"
}
camelize() {
local title=`titleize $@`
echo "${title// /}"
}
# ...
location = /myip {
add_header Content-Type text/plain;
return 200 "$remote_addr\n";
}
# ...
@asv
asv / bar.rb
Created September 19, 2013 10:20
class Bar < ActiveRecord::Base
attr_accessible :name
has_many :bazs, autosave: true
end
@asv
asv / get_cert.erl
Created July 31, 2013 07:24
Extract SSL certificate from the hackney request
#! /usr/bin/escript
-include_lib("hackney/include/hackney.hrl").
-include_lib("public_key/include/public_key.hrl").
main([]) ->
ok = hackney:start(),
{ok, 200, _, C} = hackney:request(get, <<"https://friendpaste.com">>, [], <<>>, []),
{ok, Cert} = ssl:peercert(C#client.socket),
DecodedCert = public_key:pkix_decode_cert(Cert, plain),
@asv
asv / get_cert.erl
Created July 31, 2013 07:24
Extract SSL certificate from the hackney request
#! /usr/bin/escript
-include_lib("hackney/include/hackney.hrl").
-include_lib("public_key/include/public_key.hrl").
main([]) ->
ok = hackney:start(),
{ok, 200, _, C} = hackney:request(get, <<"https://friendpaste.com">>, [], <<>>, []),
{ok, Cert} = ssl:peercert(C#client.socket),
DecodedCert = public_key:pkix_decode_cert(Cert, plain),
@asv
asv / __init__.py
Created October 9, 2012 07:29
pbx mask formatter class (prototype)
class MaskFormatter(object):
def __init__(self, **variables):
self.variables = variables
self.formatter = string.Formatter()
def format(self, match_pattern, strip_length, prepend_prefix):
mask_parts = []
for literal_text, field_name, _, _ in self.formatter.parse(prepend_prefix):
if literal_text: