Skip to content

Instantly share code, notes, and snippets.

@kixorz
kixorz / ares_document.json
Created December 6, 2012 05:01
Ares Spider
{
"Ares_odpovedi": {
"xmlns:are": "http:\/\/wwwinfo.mfcr.cz\/ares\/xml_doc\/schemas\/ares\/ares_answer_or\/v_1.0.3",
"xmlns:D": "http:\/\/wwwinfo.mfcr.cz\/ares\/xml_doc\/schemas\/ares\/ares_datatypes\/v_1.0.3",
"xmlns:U": "http:\/\/wwwinfo.mfcr.cz\/ares\/xml_doc\/schemas\/uvis_datatypes\/v_1.0.3",
"odpoved_datum_cas": "2012-12-06T06:04:46",
"odpoved_pocet": "1",
"odpoved_typ": "Vypis_OR",
"vystup_format": "XML",
"xslt": "klient",
@kixorz
kixorz / gist:5127099
Last active December 14, 2015 18:09
Globally Handling Not Found in Rails with Mongoid
class ApplicationController < ActionController::Base
rescue_from Mongoid::Errors::DocumentNotFound, :with => :rescue_not_found
protected
def rescue_not_found
render :template => 'application/not_found', :status => :not_found
end
end
@kixorz
kixorz / aws_iam_policy.json
Last active April 11, 2022 10:32
Update Route53 DNS records from your EC2 instance using this simple Ruby script. You can call it from rc.local after setting your hostname locally. First parameter is the desired <hostname>.<domain> Domain and other parameters are hardcoded. This script is useful for handling internal DNS changes in your systems after instance changes. Attached …
{
"Statement": [
{
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect": "Allow",
"Resource": [
@kixorz
kixorz / aws_autoscaling_cron.rb
Created March 20, 2013 22:41
Running cron jobs in AWS Auto Scaling group is tricky. When you deploy the same code and configuration to all instances in the group, cron job would run on all of them. You may not want that. This script detects the first instance in the group and allows only this instance to run the job. IAM user used by this script needs to have permissions to…
#!/usr/bin/env ruby
require 'syslog'
require 'net/http'
require 'aws-sdk'
Syslog.open
AWS.config({
:access_key_id => '<iam user key>',
:secret_access_key => '<iam user secret>'
@kixorz
kixorz / gist:5242651
Last active December 15, 2015 09:59
Useful commands
#mysql
#export
mysqldump -u root -p <db> > <filename>.sql
#import
mysql -u root -p <db> < <filename>.sql
#mongo
#export
@kixorz
kixorz / gist:5281510
Last active May 30, 2016 20:33
Zabbix 2.0+ temperature monitoring configuration using IPMI
#zabbix user needs to be in /etc/sudoers to be able to execute ipmitool
zabbix ALL=NOPASSWD: /usr/bin/ipmitool
#zabbix config has to collect desired UserParameters
UserParameter=ipmi.ambient_temp,sudo ipmitool sdr | grep "Ambient" | awk '{print $3}' | head -1
UserParameter=ipmi.cpu_temp,sudo ipmitool sdr | grep "CPU" | awk '{print $3}' | head -1
UserParameter=ipmi.cpu_fan,sudo ipmitool sdr | grep -i "FAN1 SYS" | awk '{print $4}' | head -1
UserParameter=ipmi.cpu_fan_status,sudo ipmitool sdr | grep -i "FAN1 SYS" | awk '{print $7}' | head -1
#after restart of zabbix_agentd, collected values can be tested via
@kixorz
kixorz / gist:5281849
Created March 31, 2013 20:15
Installing nginx with passenger for Rails on CentOS
#assuming rvm installed with Ruby 2+
#install latest passenger gem
gem install passenger --pre
#install nginx from sources with passenger module
passenger-install-nginx-module
@kixorz
kixorz / facebook_js_close_ui.js
Last active December 15, 2015 15:29
Closing Facebook JS SDK dialog window from your code.
//I found out that I’d need to close Facebook dialog that I invoke by calling:
FB.ui(<parameters>, <callback>);
//Facebook, doesn’t provide any documentation do these dialogs, with one exception - how to open them, so I had to manually trace how they close the dialog window. I found out that it’s a good practice to open all their dialogs like this
//open the dialog and save off the reference
var dialog = FB.ui(<parameters>, <callback>);
...
//force close the dialog via it's id accessible through the saved reference
@kixorz
kixorz / crontab
Last active June 18, 2017 11:14
Running Rake tasks from Cron with RVM. Place the crontab.sh file in the root of your Rails project and make it executable. Edit crontab accordingly.
#run a command every day at midnight under user ubuntu
0 0 * * * ubuntu /<path to your rails project>/crontab.sh bundle exec rake <parameters> > /dev/null 2> /dev/null
@kixorz
kixorz / create.sql
Last active December 15, 2015 19:29
Create user and db on PostgreSQL
CREATE USER <user> WITH PASSWORD '<password>';
CREATE DATABASE <db>;
CREATE SCHEMA <schema>;
GRANT ALL PRIVILEGES ON DATABASE <db> TO <user>;
GRANT ALL PRIVILEGES ON SCHEMA <schema> TO <user>;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA <schema> TO <user>;
#clone db command
createdb -O <owner> -T <db> <new db>