Skip to content

Instantly share code, notes, and snippets.

@mitfik
mitfik / ruby_csr_example.rb
Created February 27, 2012 10:13
Ruby example of CSR with openssl
require 'openssl'
def gen_key(name)
key = OpenSSL::PKey::RSA.new 1048
file = File.new(name, "w")
file.write(key)
file.close
end
def get_key(name)
@mitfik
mitfik / theme.rb
Created April 2, 2012 10:02
Redmine specify theme per project
module ApplicationHelper
def current_theme
# path to use diffrent theme for project and subprojects
unless instance_variable_defined?(:@current_theme)
theme = Setting.ui_theme
if not @project.nil?
if @project.root?
if File.directory?("#{Rails.public_path}/themes/#{@project.identifier}")
theme = @project.identifier
end
@mitfik
mitfik / gist:2405962
Created April 17, 2012 13:26
Show memory usage on Linux for human
ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }'
@mitfik
mitfik / change_name.sh
Created June 2, 2012 19:25
Rename extension for all files in all directories
find -L . -type f -name "*.rhtml" | while read FNAME; do cp $FNAME `dirname $FNAME``echo '/'``basename $FNAME .rhtml`.html.erb; done
@mitfik
mitfik / gist:3169039
Created July 24, 2012 09:22
Helper for S3 direct upload file
def s3_form_tag(options = {})
bucket = options[:bucket]
access_key_id = options[:access_key_id]
secret_access_key = options[:secret_access_key]
key = options[:key] || ''
content_type = options[:content_type] || '' # Defaults to binary/octet-stream if blank
redirect = options[:redirect] || '/'
acl = options[:acl] || 'public-read'
expiration_date = options[:expiration_date].strftime('%Y-%m-%dT%H:%M:%S.000Z') if options[:expiration_date]
max_filesize = options[:max_filesize] || 671088640 # 5 gb
@mitfik
mitfik / gist:3402722
Created August 20, 2012 09:50
LDAP CheatSheet
# Get info about all Contexts in ldap
ldapsearch -x -H ldap://localhost -b "" -s base configContext namingContexts monitorContext
# display cn=config structures and data
ldapsearch -Y EXTERNAL -H ldapi:/// -b "cn=config"
# or
slapcat -b cn=config > config.ldiff
# modify config
@mitfik
mitfik / gist:3775800
Created September 24, 2012 12:50
Cross checking for two files
# linux is awsome
# first.csv
# A
# B
# C
# D
# second.csv
# B
@mitfik
mitfik / gist:4054558
Created November 11, 2012 10:58
OGG to mp3
for name in *.ogg; do ffmpeg -i "$name" "$name.mp3"; done;
@mitfik
mitfik / config
Created March 25, 2013 14:46
refs for pull request
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
@mitfik
mitfik / converter
Created July 29, 2013 12:27
Size converter
echo "1T" | sed -e 's/t/kg/i;s/g/km/i;s/m/kk/i;s/k/*1024/ig;s/b//i' | bc