Skip to content

Instantly share code, notes, and snippets.

@maxivak
maxivak / __readme.md
Last active December 23, 2015 09:57
RabbitMQ examples using Bunny gem

RabbitMQ and Bunny examples

Publish message

Expiration

  • expiration - TTL in milliseconds

# TTL = 5 sec
exchange.publish(msg_data.to_json, :routing_key => msg_key, :expiration => 5*1000)
# find all occurrences of $name in the string
formula = "$paramname > $value && $x>0"
s = formula.gsub(/\$([a-z_\d]+)/) do
name = $1
if name=='now'
v = Time.now.utc.now
else
@maxivak
maxivak / db_script_mysql
Last active December 30, 2015 15:29
Rails Nested Forms Example - Formtastic, Cocoon. Tutorial is here - http://maxivak.com/rails-3-nested-models-in-one-form-using-formtastic-and-cocoon-gems/
CREATE TABLE IF NOT EXISTS `projects` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
CREATE TABLE IF NOT EXISTS `tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project_id` int(11) NOT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
@maxivak
maxivak / rails_new_app_generate
Last active December 31, 2015 11:39
rails create new project
# specific version of Rails, with MySQL database
rails _VERSION_ new myapp -d mysql
examples:
rails _3.2.16_ new myapp -d mysql
@maxivak
maxivak / cron_rake_task
Last active December 31, 2015 15:19
Rails. Run rake task from cron
*/10 * * * * /bin/bash -l -c 'cd /var/www/apps/appname/current/ && RAILS_ENV=production bundle exec rake sessions:cleanup >> /var/www/logs/cron.log '
@maxivak
maxivak / git_reset
Created December 24, 2013 14:45
git
# reset branch
git checkout production
git reset --hard origin/master
@maxivak
maxivak / git-hook-post-update
Created January 25, 2014 02:31
git examples
#!/bin/sh
echo
echo "**** get changes for TEST App"
echo
cd /var/www/html/testapp || exit
unset GIT_DIR
git pull origin master
@maxivak
maxivak / __readme.md
Last active January 15, 2016 09:08
Provision servers with Ansible and Vagrant

Provision servers with Ansible and Vagrant

Servers are managed by Vagrant and provisioned using Ansible scripts.

Structure

Servers (machines) are managed by Vagrant.

Files structure

@maxivak
maxivak / readme.md
Last active March 2, 2016 13:41
Rails sanitize html

Sanitize HTML, replace end lines with BR

view:

= nl2br(sanitize(message, tags: [])).html_safe

controller:

nl2br(ActionView::Base.full_sanitizer.sanitize(message)).html_safe
@maxivak
maxivak / devise.md
Last active April 3, 2016 22:42
Devise CheatSheet