This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
import re | |
if len(sys.argv) < 3: | |
print('{} <input-file> <line-seq-file><replace-lines-file>'.format(sys.argv[0])) | |
sys.exit(1) | |
input_lines = [] | |
line_seq = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from elasticsearch import Elasticsearch | |
try: | |
es = Elasticsearch(['127.0.0.1:9200']) | |
indexes = es.indices.get_alias('*') | |
index_list = [] | |
for idx in indexes: | |
print 'Index ' + idx | |
index_list.append(idx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"github.com/go-kit/kit/log" | |
"github.com/prometheus/tsdb" | |
"github.com/prometheus/tsdb/labels" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process, Lock | |
from time import sleep | |
def f(name, l, shouldsleep): | |
i = 1 | |
while i < 30: | |
l.acquire() | |
print 'Myself', name, 'The lock', l | |
if shouldsleep: | |
print name, 'will sleep for 10 secs, others have to wait' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/md5" | |
"encoding/json" | |
"flag" | |
"fmt" | |
"github.com/hashicorp/consul/api" | |
"io/ioutil" | |
"os" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread, Lock | |
from time import sleep, time | |
from datetime import datetime | |
from pymongo import MongoClient | |
from uuid import uuid1 | |
import atexit | |
class DistLockMongo(Thread): | |
def __init__(self, host='localhost', port=27017, db='lockdb'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_binary_search(lst, val, start, end): | |
if start == end: | |
if val == lst[start]: | |
return start | |
return -1 | |
if val < lst[start] or val > lst[end]: | |
return -1 | |
if val > lst[end]: | |
if val == lst[end]: | |
return end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree(object): | |
def __init__(self, val=None): | |
self.left = None | |
self.right = None | |
self.val = val | |
def add(self, val): | |
if self.val is None: | |
self.val = val | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
''' | |
leader_takes an array of (host, port) tuples and returns leader, array-of-followers, | |
array-of-down-hosts | |
''' | |
def leader_detect(hostports): | |
sk = None | |
leader = None | |
followers = [] | |
down = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A function to climb up directory | |
# To climb up 13 levels up, issue command: $ ucd 13 | |
function ucd { | |
if [ $# -eq 0 ] | |
then | |
cd .. | |
else | |
x=$1 | |
curpwd=`pwd` | |
while [ $x -gt 0 ] |
NewerOlder