Skip to content

Instantly share code, notes, and snippets.

View MichalBryxi's full-sized avatar
⛰️
Vacationing

Michal Bryxí MichalBryxi

⛰️
Vacationing
View GitHub Profile
@MichalBryxi
MichalBryxi / sorted_hash.rb
Last active December 16, 2015 02:19
In ruby 1.8 you don't have option to serialize hashes sorted. You can find many monkey patches on the internet which allows this. Unfortunatelly there are numerous errors in them. I would like to keep here most bug-free version.
class Hash # :nodoc:
undef_method :to_yaml
# Replacing the to_yaml function so it'll serialize hashes sorted (by their keys)
#
# Original function is in /usr/lib/ruby/1.8/yaml/rubytypes.rb
def to_yaml( opts = {} )
YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
keys.sort_by do |k|
@MichalBryxi
MichalBryxi / activerecord_php_migration.rb
Last active December 16, 2015 22:39
Rails ActiveRecord migrations enhanced by possibility to run PHP migrations. Useful when you use ActiveRecord migrations for your (PHP) application, but you also need to use your application sources code classes in the migration process.
##### Our Migration class db/iw_migration.rb ######
# IW_Migration adds possibility to run PHP migrations in classic
# rails ActiveRecord stack. It will receive PHP class name which will be
# executed instead of regular AR migration.
class IW_Migration < ActiveRecord::Migration
# This will hold for us PHP class name
@migration_class = nil
# This will hold for us caller stamp from it's filename
@migration_stamp = nil
@MichalBryxi
MichalBryxi / logstash_postfix_indexer.conf
Last active December 17, 2015 14:39 — forked from tkorkunckaya/postfix_patterns
Logstash indexer config for parsing postfix logs
# We will focus only on how to parse the records
filter {
# Split postfix record to basic parts
grok {
type => 'postfix'
pattern => '%{SYSLOGBASE}'
named_captures_only => true
}
@MichalBryxi
MichalBryxi / grok_tester.rb
Last active December 17, 2015 22:39 — forked from wigsy/test_patterns.rb
Ever wanted to know why your grok patterns does not work? This might help a little.
require 'rubygems'
require 'pp'
# gem install jsl-grok
require 'grok-pure'
# Variable just to DRY it
BASE_PATH = '/home/michal/iw/puppet/modules/logstash/files'
# Set where are your grok patterns stored
PATTERN_GLOB = [
"#{BASE_PATH}/grok_patterns/*",
@MichalBryxi
MichalBryxi / logstash_grep_fields.rb
Last active December 19, 2015 01:28
Logstash @fields.anything usage example. Documentation is not very explicit in this topic.
# I want to add tag => 'nagios' to every record where:
# @fields.severity == "PHP Fatal"
filter {
# Does not work
grep {
match => [ "@fields.severity", "PHP Fatal" ]
add_tag => [ "nagios" ]
drop => false
}
@MichalBryxi
MichalBryxi / transfer_lvm_volume.rb
Created January 25, 2014 20:14
Ever wanted to transfer multiple LVM volumes from one machine to other? Ever tried it? It's not hard, but it requires a lot of (manual) steps.
#!/usr/bin/env ruby
#
# == History
# Ever wanted to transfer multiple LVM volumes from one machine to other?
# Ever tried it? It's not hard, but it requires a lot of (manual) steps.
# Things get especially annoying if you want to test it first and than
# transfer everything ASAP. If you like to automate things, you can try
# this script. It uses LVM2 snapshot mechanism, so in theory you don't
# need to stop any service using the volume. Of course this will ensure
# only LVM/filesystem-level consistency, not application-level sonsistency!
#!/usr/bin/env ruby
#
# == History
# Transfers multiple *.img files from one machine to corresponding
# LVM volumes on other machine.
#
# == Requirements
# 1) This script
# 2) Passwords-less sudo on destination machine
# 3) Sudo rights on source machine
@MichalBryxi
MichalBryxi / ember_transition_problem.js
Last active August 29, 2015 13:58
Ember transition problem
///// Problematic code
{{#each module in controller}}
{{#link-to 'forge-module.show' module}} // <-- here "is" my problem
{{module.name}}
{{/link-to}}
{{/each}}
// Created HTML:
@MichalBryxi
MichalBryxi / ic.ajax.js
Last active August 29, 2015 13:59
ic.ajax problem
// This works:
return ic.ajax(url).then(function (response) {});
// This throws following error:
return ic.ajax.request({
type: "PUT",
url: url
}).then(function (response) {});
// TypeError: undefined is not a function
[06/05/14 23:49:20] Filip Rut: 000-default.conf ******<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com