Skip to content

Instantly share code, notes, and snippets.

View matisojka's full-sized avatar

Mateusz Sójka matisojka

View GitHub Profile
@matisojka
matisojka / docker-cleanup-resources-centos.md
Last active June 1, 2018 19:32 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks (CentOS version)

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ sudo docker volume rm $(sudo docker volume ls -qf dangling=true)

$ sudo docker volume ls -qf dangling=true | xargs -r sudo docker volume rm

@matisojka
matisojka / singleton_spec.rb
Created March 30, 2012 09:34
Test Ruby Singleton Classes
class MySingletonClass
include Singleton
def initialize
## Do some initializing
end
## Your business logic
end
@matisojka
matisojka / enteprisifier.rb
Created September 30, 2016 13:38
Tiny helper to make your program feel more enteprisy!
class Enterprisifier
def self.enterprisify!
sleep 5
end
end
@matisojka
matisojka / Dockerfile
Created March 5, 2016 11:00
Tiny Go microservice plumbing
FROM alpine:3.2
ENV GOROOT=/usr/lib/go \
GOPATH=/gopath \
GOBIN=/gopath/bin \
PATH=$PATH:$GOROOT/bin:$GOPATH/bin
WORKDIR /gopath/src/app
ADD . /gopath/src/app
@matisojka
matisojka / Dockerfile
Last active March 5, 2016 09:23 — forked from shijuvar/main.go
A simple microservice plumbing in Go
FROM google/golang:stable
# Godep for vendoring
RUN go get github.com/tools/godep
# Recompile the standard library without CGO
RUN CGO_ENABLED=0 go install -a std
MAINTAINER mateusz.sojka@deindeal.ch
ENV APP_DIR $GOPATH/Users/mati/deindeal/moosehead/modules/newsletter_feeds
# Set the entrypoint
@matisojka
matisojka / comparison.rb
Created November 27, 2013 08:40
First string character comparison benchmark
require 'benchmark'
name = 'my_cool_string'
Benchmark.bmbm(10) do |x|
x.report('name[0] hit') do
1_000_000.times { name[0] == 'm' }
end
x.report('name[0] miss') do
1_000_000.times { name[0] == 'y' }
@matisojka
matisojka / measure_gem_loading_time.rb
Created July 4, 2012 07:05
Measure Gem loading time in your Rails APP
# Disclaimer: this solution has been taken from the post: http://stackoverflow.com/a/5071198/784270
# navigate to the bundler gem and in lib/bundler/runtime.rb,
# find the line that does Kernel.require and wrap it like this
puts Benchmark.measure("require #{file}") {
Kernel.require file
}.format("%n: %t %r")
# Add
@matisojka
matisojka / chef_solo_bootstrap.sh
Created May 13, 2012 19:08 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@matisojka
matisojka / gist:2236364
Created March 29, 2012 11:44
Change the character encoding of an existing database
alter database DATABASE_NAME charset=utf8
@matisojka
matisojka / valid_json.rb
Created March 29, 2012 11:36 — forked from carlcrott/gist:2218175
JSON validation method (without monkey patching and with proper error handling)
def valid_json?(value)
JSON.parse value
true
rescue JSON::ParserError, TypeError
false
end