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 / standalone-capybara.rb
Created March 23, 2012 21:12
Standalone Capybara Test
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
module MyCapybaraTest
class Test
@nikhgupta
nikhgupta / center-element.js
Created March 22, 2012 21:26
jQuery - center an element
// center an element
$(element).center
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) +
$(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) +
@nikhgupta
nikhgupta / renderjsonp-cakephp.php
Created March 22, 2012 19:50
Render as JSONP inside CakePHP
public function someController()
{
// $callback is retrieved from the params
$message = "some message";
$this->autoRender = false;
$this->RequestHandler->respondAs('json');
if ($cb) echo $callback."(".json_encode(array("message" => $message)).");";
}
@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'
@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 / 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 / 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 / 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 / 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 / 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