Skip to content

Instantly share code, notes, and snippets.

View iMagesh's full-sized avatar
🏠
Working from home

Magesh iMagesh

🏠
Working from home
View GitHub Profile
task :migrate_wp => :environment do
wp = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "root", :database => "mageshblog")
results = wp.query("select * from wp_zxdasg_posts;")
results.each do |r|
Post.create(
:user_id => r["author"],
:date => r["post_date"],
:content => r["post_content"],
:title => r["post_title"],
@iMagesh
iMagesh / emacs.el
Created November 1, 2012 08:43
shopo laptop .emacs config
(setq inhibit-startup-message t) ;; Removes startup message
(setq-default indent-tabs-mode nil)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-save-default t)
@iMagesh
iMagesh / ubuntu-lucid-setup-rails.md
Created July 30, 2012 11:31 — forked from lakim/ubuntu-lucid-setup-rails.md
Ubuntu Lucid Setup Guide for Rails

This note will walk you though setting up and securing a Ubuntu 10.04 LTS then deploying a Rails application with mulit-stage deployment.

TODO:

  • Add section for NGINX setup

Server Setup

@iMagesh
iMagesh / gist:2899879
Created June 9, 2012 06:53 — forked from rtdp/gist:742461
Importing Gmail Contacts list to Rails Application.
class ImportedContactsController << ApplicationController
require 'net/http'
require 'net/https'
require 'uri'
#THIS METHOD TO SEND USER TO THE GOOGLE AUTHENTICATION PAGE.
def authenticate
# initiate authentication w/ gmail
# create url with url-encoded params to initiate connection with contacts api
# next - The URL of the page that Google should redirect the user to after authentication.
# scope - Indicates that the application is requesting a token to access contacts feeds.
@iMagesh
iMagesh / application_controller.rb
Created February 27, 2012 06:38
A rough who to connect suggestion based on mutual interests, code needs to be optimized
def who_to_connect
@sent_invitations = current_user.sent_inv.where(:is_pending => 1).collect(&:friend_id)
@friends = friends_list
@friends = @friends + @sent_invitations
options = %w(majors careers)
@sug_list = []
options.each do |option|
@my_majors = eval("current_user.#{option}")
@iMagesh
iMagesh / rake_strip_whitespace.rb
Created February 24, 2012 13:37 — forked from ashmoran/rake_strip_whitespace.rb
Simple Rake task to use sed to strip trailing whitespace from Ruby source
desc "Remove trailing whitespace for source files"
task :strip_whitespace do
files = %w[ .autotest .rspec .rvmrc Gemfile ]
globs = %w[ lib/**/*.rb spec/**/*.rb ]
files_from_globs = globs.map { |glob| Dir[glob] }
files_to_strip = (files + files_from_globs).flatten
system "sed -e 's/[ \t]*$//' -i '' #{files_to_strip.join(" ")}"
end
@iMagesh
iMagesh / rmws
Created February 24, 2012 13:36 — forked from artgillespie/rmws
Remove trailing whitespace from all source files under the current dir
#!/bin/sh
#
# Removes trailing whitespace from all source files in the current directory and its children.
# Note the `-i .bak` switch to sed. This will create a backup copy alongside any modified files
# like `Somefile.cpp.bak` Simply remove the `.bak` argument to `-i` to prevent the backup
# files from being generated
#
/usr/bin/find . -type f -and \( -name '*.m' -or -name '*.h' -or -name '*.mm' -or -name '*.cpp' -or -name '*.c' \) -and -print0 | xargs -0 sed -i .bak -E "s/[[:space:]]+$//"
@iMagesh
iMagesh / weekly_report.rake
Created February 24, 2012 09:54
Weekly report task to managers about the project timeline
task :weekly_report => [:environment] do
@start_date=Date.today.beginning_of_week
start_date=@start_date.to_date
@end_date=6.days.since(@start_date)
end_date=@end_date.to_date
@project=Project.find_all_by_isactive(true)
@proj=[]
@project.each do |project|
@proj << {:name => project.projectname,:billable => project.timeentries.sum(:hours_taken, :conditions=>['DATE(task_date)>=? and DATE(task_date)<=? and status=?',start_date,end_date, "Billable"]),:nonbillable => project.timeentries.sum(:hours_taken, :conditions=>['DATE(task_date)>=? and DATE(task_date)<=? and status=?',start_date,end_date, "NonBillable"]) ,:hours =>project.timeentries.sum(:hours_taken, :conditions=>['DATE(task_date)>=? and DATE(task_date)<=?',start_date,end_date])}
end
@iMagesh
iMagesh / mail-task.rake
Created February 24, 2012 09:53
Reminder email for timesheet defaulters
task :reminder_mail => [:environment] do
@users = User.active
@holidays = Holiday.all
@holiday_dates = []
@dates_to_check = []
@holidays.each {|h| @holiday_dates << h.holiday.to_s}
(Date.new(Time.now.year, Time.now.month, 1)..Date.yesterday).each { |date| @dates_to_check << date.to_s}
@users.each do |user|