Skip to content

Instantly share code, notes, and snippets.

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

Nikhil Gupta nikhgupta

🏠
Working from home
View GitHub Profile
@nikhgupta
nikhgupta / gitolite.conf
Created January 25, 2011 13:09
a bash script which automates creation of a local git repository, modifies gitolite.conf file as needed, and then syncs the repo with an online gitolite (and github) server you must have repos defined the way in attached gitolite.conf file
# gitolite conf
# please see conf/example.conf for details on syntax and features
# do not remove hashes from the following macros
# if you add a macro, remember to update ~/bin/init-gitolite.sh
@public-readable = #
@public-writable = testing #
@client-works = #
repo @client-works
@nikhgupta
nikhgupta / mysqlToCsv.php
Created January 25, 2011 19:59
Export MySQL table as CSV file
<?php
function exportMysqlToCsv($table,$filename = 'export.csv')
{
$csv_terminated = "\n";
$csv_separator = ",";
$csv_enclosed = '"';
$csv_escaped = "\\";
$sql_query = "select * from $table";
@nikhgupta
nikhgupta / irb-oneliners.md
Created January 26, 2011 19:26
oneliners for irb

###generate a random string of 8 characters ('a'..'z').to_a.shuffle[0..7].join

@nikhgupta
nikhgupta / cpanel-backup-script.php
Created July 8, 2011 11:02
cPanel Backup Script
<?php
// PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server.
// This script contains passwords. KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/)
// ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED *********
// Info required for cPanel access
$cpuser = "username"; // Username used to login to CPanel
$cppass = "password"; // Password used to login to CPanel
@nikhgupta
nikhgupta / rails_template.rb
Created July 17, 2011 03:39
Default template for new Rails applications
initializer 'generators.rb', <<-RUBY
Rails.application.config.generators do |g|
end
RUBY
@recipes = ["activerecord", "cucumber", "devise", "git", "haml", "heroku", "jammit", "jquery", "rails_admin", "sass", "settingslogic"]
def recipes; @recipes end
def recipe?(name); @recipes.include?(name) end
@nikhgupta
nikhgupta / rails3-devise-cucumber-rspec-mysql-template.rb
Created July 18, 2011 19:38
Rails3 Devise Cucumber Rspec MySQL template
# Application Generator Template
# Modifies a Rails app to use Devise with RSpec and Cucumber
# Usage: rails new APP_NAME -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-devise-rspec-cucumber-template.rb -T
# Information and a tutorial:
# https://github.com/RailsApps/rails3-devise-rspec-cucumber
# Generated using the rails_apps_composer gem:
# https://github.com/RailsApps/rails_apps_composer/
@nikhgupta
nikhgupta / qw498.rb
Created July 26, 2011 11:08
Errors with Update Attributes
User Model
==========
require 'digest'
class User < ActiveRecord::Base
attr_accessor :password
has_one :profile
has_many :articles, :order => 'published_at DESC, title ASC',
:dependent => :nullify
has_many :replies, :through => :articles, :source => :comments
@nikhgupta
nikhgupta / new-lang-code-file.php
Created March 10, 2012 01:20 — forked from RaVbaker/new-lang-code-file.php
How to create new programming language in PHP?
// This is written in pseudo language
class Foo {
def bar() {
ret "it Works!";
}
}
$f = Foo.new();
print $f.bar();
@nikhgupta
nikhgupta / newrails.bash
Created March 17, 2012 08:58
a bash function to create a new rails project with some defaults
# note that the database is being used with login: root/password
# make necessary changes if you are using something else or simple remove that block
function newrails() {
app="$1"; ruby="${2:-1.9.3@rails}";
if [ -n "${app}" ]; then
read -r -d '' gemfile <<-'EOF'
group :test, :development do
gem 'turn'
gem 'rspec-rails'
gem 'capybara'
@nikhgupta
nikhgupta / railscasts-episodes-list.rb
Created March 20, 2012 23:47
RailsCasts: get a list of links to MP4 Version of the Episodes
#!/usr/bin/env /Users/nikhilgupta/.rvm/wrappers/ruby-1.9.3-p0@tools/ruby
# a tiny script that crawls 'railscasts.com' and stores the path to MP4 versions
# of the episodes in the file: 'downloads.txt'
# currently, set to track only the last 3 pages of the site's free section.
# you can then run: $(for tut in `cat downloads.txt`; do wget --continue $tut; done) to download them.
require 'rubygems'
require 'nokogiri'
require 'open-uri'