Skip to content

Instantly share code, notes, and snippets.

View microwaves's full-sized avatar

Stephano Zanzin Ferreira microwaves

View GitHub Profile
# To create a k8s configuration description out of whatever command you issue to kubectl, without executing the operation.
kubectl create service externalname --external-name=foo foo -o yaml --dry-run
@microwaves
microwaves / pod-reboot.sh
Created November 20, 2017 16:30
pod reboot
kubectl patch deployment mydeployment \
-p'{"spec":{"template":{"spec":{"containers":[{"name":"mycontainer","env":[{"name":"RESTART_","value":"$(date -uIseconds)"}]}]}}}}'

Keybase proof

I hereby claim:

  • I am microwaves on github.
  • I am microwaves (https://keybase.io/microwaves) on keybase.
  • I have a public key ASA9evH--svyzuLTQIzwt9c70nF-QllqHAWCalEhi3TFnwo

To claim this, I am signing this object:

@microwaves
microwaves / gist:f1344598f41552a3618bffe01785081e
Created June 14, 2016 10:33
How to retrieve a log in time ranges
sed -n "/14\/Jun\/2016:11:34/,/14\/Jun\/2016:11:44/p" /var/log/apache2/access.log
@microwaves
microwaves / moving_average.py
Created September 19, 2014 22:17
A simple class to calculate moving averages.
class MovingAverage(object):
def __init__(self):
self.mutant_range = lambda start, end: range(start, end + 1)
def exponential_moving_average(self, values, index=None, tail=None):
index, tail = self.__index_and_tail_or_defaults(values, index, tail)
alpha = 2.0 / (tail + 1)
n = sum(map(lambda x: ((1 - alpha) ** (x - 1) * values[index - x + 1]),
self.mutant_range(1, tail)))
cat -n foofile | grep "^ *30" # where *30 represents the line to be printed.
def normalize_csv(from, to)
File.open(from.path, 'r:windows-1251:utf-8').each_line do |line|
if line.count('"') > 0
line.gsub!(/,([^,]+"[^,]+),/) do
%(,"#{Regexp.last_match[1].tr('"', '')}",)
end
end
to.puts(line)
end
to.rewind
def normalize_csv(from, to)
from.rewind
File.open(from.path, 'r:windows-1251:utf-8').each_line do |line|
if line.count('"') > 0
line.gsub!(/,([^,]+"[^,]+),/) do
%(,"#{Regexp.last_match[1].tr('"', '')}",)
end
end
to.puts(line)
end
require 'json'
require 'logger'
class MatchesChecker
attr_accessor :events_file, :fingerprints_file, :data
def initialize
@data = {}
@events_file = './logs/events.log'
@fingerprints_file = './logs/fingerprints.log'
rails_root = File.expand_path('../../', __FILE__)
$LOAD_PATH.unshift(rails_root) unless $LOAD_PATH.include?(rails_root)
require 'bundler/setup'
require 'active_record'
require 'rspec/rails/extensions/active_record/base'
require 'spec/support/require_helper'
require 'spec/support/helpers'
require 'ostruct'
Bundler.require :models