Skip to content

Instantly share code, notes, and snippets.

View vitaliel's full-sized avatar

Vitalie Lazu vitaliel

  • Moldova, Chisinau
View GitHub Profile
#!/usr/bin/env ruby
# Copy path from rspect stack trace and execute it
# spm ./spec/models/space_spec.rb:867
path = ARGV[0]
file, number, _ = path.split ':'
number = number.to_i
line = number > 0 ? " -l #{number}" : ""
Failures:
1) Mailman ticket create with attachment
Failure/Error: Mailman.receive(str)
Encoding::UndefinedConversionError:
"\x89" from ASCII-8BIT to UTF-8
# ./lib/email_utils.rb:205:in `save_attachment'
# ./lib/tools/ticket_tool.rb:396:in `block in parse_email'
# ./lib/tools/ticket_tool.rb:396:in `each'
# ./lib/tools/ticket_tool.rb:396:in `parse_email'
module AdminHelper
def field_must_be_slug(element, separator = '-')
render :update do |page|
page << <<-rawJS
var element = $('#{element.to_s}');
new Form.Element.Observer(element, 0.02, function(){
element.value = element.getValue().toLowerCase().gsub(/[^a-z0-9\\d\\s\\s+\\#{separator}]+/, '').gsub(/\\s+/,'#{separator}');
});
rawJS
@vitaliel
vitaliel / gist:2350444
Created April 10, 2012 10:57
rake task to update TAGS
desc "create TAGS file for emacs, vim"
# sudo apt-get install exuberant-ctags
task :tags do
rm_f "TAGS"
# ctags-exuberant -a -e -f TAGS --tag-relative -R app lib vendor
cmd = RUBY_PLATFORM =~ /darwin/i ? "/usr/local/bin/ctags -e" : "etags"
dirs = %w{app lib test}
@vitaliel
vitaliel / rails_db_create.rb
Created December 2, 2012 08:51
Read database.yml file and generate sql to create databases
#!/usr/bin/env ruby
# Read database.yml file and generate sql to create databases
# ./rails_db_create.rb | mysql
require 'yaml'
config = YAML.load_file 'database.yml'
dbs = {}
# Generate logrotate conf for rails sites deployed with capistrano
# it scans current directory for rails site, it assumes that webserver is passenger
# cd /u/apps && ~/bin/gen_logrotate.rb
require 'etc'
Dir['*'].each do |entry|
next unless File.directory? entry
dir = File.expand_path entry
log_dir = dir + "/shared/log"
@vitaliel
vitaliel / clean_linux_pkg.rb
Created November 6, 2013 07:14
Remove old linux packages from ubuntu/debian
keep=%w{3.5.0-41 3.5.0-42}
versions = Dir['/boot/System.map*'].sort.map do |f|
name = File.basename(f)
if name =~ /(\d+\.\d+\.\d+-\d+)/
$1
end
end
pkgs = []
@vitaliel
vitaliel / check_dj.rb
Created November 8, 2013 14:58
Nagios plugin to monitor delayed job active record queue
#!/usr/bin/env ruby
# encoding: utf-8
#
# Nagios plugin to monitor delayed job active record queue
#
# will use mysql2 gem
# --dsn mysql2://root@localhost/portal_development
#
@vitaliel
vitaliel / run.rb
Created November 28, 2013 09:42
run rails with thin and tail -f for development.log that outputs rails logs to the console
require 'thread'
log='log/development.log'
system "truncate --size 0 #{log}"
Thread.new do
system('bundle exec thin start')
end
args = %W{tail -f #{log}} + [:err => [:child, :out]]
#!/usr/bin/env ocaml
#load "str.cma";;
let concat_file_parts l =
String.concat "." l;;
let change_ext name ext =
let old_parts = String.split_on_char '.' name in
match List.rev old_parts with