Skip to content

Instantly share code, notes, and snippets.

Working Remotely

Puneet Pandey puneetpandey

Working Remotely
View GitHub Profile
View my-habtm.rb
#{PATH_TO_APP}$ rails g model Person name:string email:string
#{PATH_TO_APP}$ rails g model Community name:string description:text
class Person < ActiveRecord::Base
has_and_belongs_to_many :communities
class Community < ActiveRecord::Base
has_and_belongs_to_many :persons
View associations_with_where_clause
class Product < ActiveRecord::Base
has_many :suppliers, conditions: ["suppliers.status = ?", true]
# In Rails4, if you wish to use the same, you can use the below syntax:
class Product < ActiveRecord::Base
has_many :suppliers, -> { where("suppliers.status = ?", true) }
View action_plan.rb
# app/models
class User < ActiveRecord::Base
has_many :responses, dependent: :destroy
class Response < ActiveRecord::Base
has_one :report
has_many :points
belongs_to :user
View outlook.rb
require 'rubygems'
require 'viewpoint' # Library for MS Outlook
require 'viewpoint/logging/config' # For Debugging
include Viewpoint::EWS
endpoint = 'YOUR MS EXACHANGE URL COMES HERE' # E.g. https://OUTLOOKSERVER_URL/ews/exchange.asmx
user = 'USERNAME'
pass = 'PASSWORD'
cli = endpoint, user, pass
View user_spec.rb
require 'spec_helper'
class User
def initialize(args = {}); end
def email
def mobile
View acts.rb
class ActsController < ActionController::Base
before_filter :get_user
def new
@act =
def create
@act = params[:act]
View h_to_a_mapping.rb
class MyLittleProgram
def execute
h = { h1: 'value1', h2: 'value2', h3: 'value3', h4: 'value4' }
a = [ '1', '2', '3', '4' ]
h.each_with_index do |(k, v), i|
break if a.size > h.keys.size
a.each_with_index { |val, index|
if i == index
View controller_spec.rb
# Controller /app/controllers/posts_controller.rb
def index
@posts = Post.all
# Spec /spec/controllers/posts_controller_spec.rb
describe "GET #index" do
it "responds successfully with a HTTP 200 status code" do
get :index
expect(response).to be_success
View gist:6995045
if (!isset($_SESSION['username'])) {
header("Location: login.php");
View file1.php
<?php$con = mysql_connect("localhost", "USERNAME", "PASSWORD");
if (!$con) {
die('Could Not Connect: ' . mysql_error());
mysql_select_db("DB_NAME", $con);
$result = mysql_query("SELECT firstname, lastname, email, phone, mobile, address_1, address_2, city, zipcode, country, state FROM TABLE_NAME");
echo "
<table border='1'>