Skip to content

Instantly share code, notes, and snippets.

View somic's full-sized avatar

Dmitriy Samovskiy somic

View GitHub Profile
@somic
somic / lambda.rb
Created June 5, 2019 21:55
lambda
require 'aws-xray-sdk'
def random_sleep_under_1s
r = Random.rand
sleep r
r
end
def xray(segment_name, method_name, with_subsegments: true)
parent_id = ENV['_X_AMZN_TRACE_ID'].gsub(/.*Parent=/, '').split(';').first
$ diff -u f.py f1.py
--- f.py 2016-10-19 18:31:41.000000000 -0500
+++ f1.py 2016-10-19 18:32:25.000000000 -0500
@@ -53,7 +53,7 @@
class DiscoveryServiceCached(DiscoveryService):
def __init__(self, *args, **kwargs):
- super(DiscoveryService.__class__, self).__init__(*args, **kwargs)
+ super(self.__class__, self).__init__(*args, **kwargs)
self.hit_cache = {}
#!/opt/sensu/embedded/bin/ruby
#
# Check num_occurrences_filter logic
#
# Reads sensu-server log on stdin, looks for messages that are
# marked with 'event was filtered' and runs them through this tester handler
# to make sure it would filter them as well
#
# http://github.com/yelp/sensu_handlers
#
@somic
somic / category_plugin.rb
Created March 2, 2011 23:37
How I organize posts in Jekyll (code snippets for blog post - see comments)
module Jekyll
Page.class_eval {
def clone
Page.new(@site, @base, @dir, @name)
end
}
def revenue_maximizing_spot_price(n, bids):
assert len(bids) <= n, "does not work when the number of bids exceeds n"
revenue, spot_price = max(
[ (sum([p for x in bids if x >= p]), p) for p in bids ])
return spot_price, revenue
if __name__ == '__main__':
print revenue_maximizing_spot_price(10, [ 1, 2, 5, 50 ])
# -> (50, 50)
print revenue_maximizing_spot_price(10, [ 1, 2, 5, 45, 50 ])
{"us-east-1": {"m1.large": {"Windows": [[190, 210], [214, 217], [220], [241], [250], [257], [280], [350], [450], [500], [700]], "Linux/UNIX": [[114, 126], [140], [145], [150], [180], [200], [220], [300], [320], [330], [340], [350], [500], [680]], "SUSE/Linux": [[126, 140]]}, "m2.2xlarge": {"Windows": [[523, 577], [1500]], "Linux/UNIX": [[399, 441], [1000]], "SUSE/Linux": [[335, 371]]}, "m1.small": {"Windows": [[48, 52], [70], [125]], "Linux/UNIX": [[29, 31], [40], [45], [50], [85]], "SUSE/Linux": [[41, 45]]}, "c1.medium": {"Windows": [[119, 131], [151], [170], [200], [290], [450]], "Linux/UNIX": [[57, 63], [65], [67, 68], [70], [75], [80], [85], [90], [100], [110], [120]], "SUSE/Linux": [[69, 77]]}, "m1.xlarge": {"Windows": [[380, 420], [960]], "Linux/UNIX": [[228, 252]], "SUSE/Linux": [[240, 266]]}, "m2.xlarge": {"Windows": [[228, 252], [450], [620], [650]], "Linux/UNIX": [[162, 178], [184], [200], [220], [250], [300], [350], [500], [550], [560], [600], [750]], "SUSE/Linux": [[174, 192]]}, "t1.micro": {"Wind
@somic
somic / detect_missing_icmq_seq.awk
Created November 23, 2010 17:46
AWK script to detect missing replies in Linux ping output, based on icmp_seq
#!/usr/bin/awk -f
#
# analyzes ping output on Linux and looks for missed returns
# based on icmp_seq
#
# ping output is expected on stdin
#
BEGIN { num = 0 }
$5 ~ /icmp_seq=/ {
#!/usr/bin/ruby -I/usr/local/qpid-svn/qpid/ruby
#
#
__doc__ = %q(
disttailf.rb - distributed "tail -f"
Aggregates "tail -f" output from multiple machines and multiple files
into a single RabbitMQ pubsub queue (kind of splunk's log consolidation
function)
@somic
somic / ec2dipr.py
Created August 31, 2010 17:32
Scrape AWS EC2 forums to obtain ranges of public IP addresses for each EC2 region
#!/usr/bin/env python
#
# ec2dipr.py - ec2_describe_ipaddress_ranges
#
from BeautifulSoup import BeautifulSoup
import re, urllib2, socket, boto.ec2
try:
import boto
162.0 sir-7f943c02 2010-06-21T10:30:38-0600 2010-06-21T15:33:20+0000
200.0 sir-a5909a02 2010-06-21T11:57:01-0600 2010-06-21T17:00:21+0000
136.0 sir-2d70e603 2010-06-22T09:36:54-0600 2010-06-22T14:39:10+0000
162.0 sir-837d2a02 2010-06-25T11:28:50-0600 2010-06-25T16:31:32+0000
110.0 sir-f52c8a03 2010-06-28T10:37:25-0600 2010-06-28T15:39:15+0000
120.0 sir-9a16d804 2010-06-28T10:37:16-0600 2010-06-28T15:39:16+0000
137.0 sir-72b2ea04 2010-06-28T14:03:02-0600 2010-06-28T19:05:19+0000
129.0 sir-de8b8602 2010-06-28T14:03:12-0600 2010-06-28T19:05:21+0000
105.0 sir-4ba2a402 2010-07-07T12:13:33-0600 2010-07-07T17:15:18+0000
115.0 sir-a46b6604 2010-07-08T10:29:13-0600 2010-07-08T15:31:08+0000