Skip to content

Instantly share code, notes, and snippets.

View srih4ri's full-sized avatar
🔥
Lighting things on fire, brb

Srihari srih4ri

🔥
Lighting things on fire, brb
View GitHub Profile
@srih4ri
srih4ri / malayalam_pdf.rb
Created February 22, 2011 18:48
Generate PDF documents containing malayalam using prawn
require 'rubygems'
gem 'prawn','=0.6.3'
require 'prawn'
words = "പോടാ മണ്ട is the new foo bar."
Prawn::Document.generate "example.pdf" do |pdf|
pdf.font 'rachana.ttf'
pdf.text words
end
@srih4ri
srih4ri / translate.rb
Created March 16, 2011 15:35
Generates a new ml.yml using the current en.yml , using old ml.yml's translated string wherever possible . This is really ugly though , there must be something that actually does this neatly
# encoding: UTF-8
require 'yaml'
sf = File.open("original_ml.yml", "r")
src = YAML::load(sf.read)
sf.close
rf = File.open("current_en.yml", "r")
ref = YAML::load(rf.read)
rf.close
@srih4ri
srih4ri / application_helper.rb
Created March 20, 2011 14:04
Call it with <%= stylesheet_link_tag(*get_stylesheets) %> in your layouts file
def get_stylesheets
styles_path = "#{Rails.root}/public/stylesheets"
controller_name = controller.controller_path
action_name = controller.action_name
if File.exists? "#{styles_path}/#{controller_name}/#{action_name}.css"
"#{controller_name}/#{action_name}"
elsif ["create","edit","update"].include? action_name and File.exists? " #{styles_path}/#{controller_name}/new.css"
"#{controller_name}/new"
end
end
@srih4ri
srih4ri / CheckPassword.rb
Created June 14, 2011 14:34
CheckPassword.rb
#!/usr/bin/env ruby
module PasswordChecker
def check_valid?
if length > 1
(length/2).times { |i|
return false if (self[(i+1..length)].start_with? self[(0..i)])
}
(self[(1..length)]).check_valid?
else
return true
@srih4ri
srih4ri / checkip
Created July 17, 2011 15:08
See what the internet calls you. Wrote for giving my IP to friends for slimevolley.
curl -s http://checkip.dyndns.com/|cut -d ":" -f 2|cut -d "<" -f 1
#You might want to alias this thing to something shorter. `checkip` in my case.
@srih4ri
srih4ri / auth_db.rb
Created September 5, 2011 18:01
A ruby script being called by mod_authnz_external
#!/usr/bin/ruby
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "myuser",
:password => "mypass",
:database => "somedatabase"
@srih4ri
srih4ri / ruby-tests.rake
Created November 2, 2012 18:52
Ruby-tests for ruby-roxml
task :test do
require 'rake/runtest'
$: << 'lib' << '.'
Rake.run_tests 'test/unit/*_test.rb'
end
namespace :test do
desc "Test ROXML under the Nokogiri parser"
task :nokogiri do
@srih4ri
srih4ri / update_plugin_assets.md
Created November 5, 2012 16:10
Script to copy fedena plugin's assets to public dir on file change ( Using inotify-tools )

Copy the following into a shell script in fedena's root folder, give it executable permissions and run as :

./update_plugin_assets.sh vendor/plugins/my_awesome_plugin
#!/bin/sh
plugin_dir=$1
while inotifywait -r -e modify $plugin_dir ; do
desc 'Run Devise tests for all ORMs.'
task :tests do
Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
orm = File.basename(file).split(".").first
system "rake test DEVISE_ORM=#{orm}"
end
end
task :default => :tests
#!/usr/bin/env ruby
file = "/home/srih4ri/code/rm_current_clem/to_delete.txt"
require "dbus"
sesbus = DBus.session_bus
clem_service = sesbus["org.mpris.clementine"]
clem_object = clem_service.object "/Player"
clem_object.introspect
clem_iface = clem_object['org.freedesktop.MediaPlayer']
meta = clem_iface.GetMetadata
file_loc = meta[0]['location'].split('file://').last