Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working Remotely

Puneet Pandey puneetpandey

🏠
Working Remotely
View GitHub Profile
View gist:6995045
<?PHP
session_start();
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'>
<tr>
View geminstall.txt
gem install mysql2 --platform=ruby -- '--with-mysql-include=C:\mysql-connector-c-noinstall-6.0.2\include --with-mysql-lib=C:\mysql-connector-c-noinstall-6.0.2\lib --with-mysql-dir=C:\mysql-connector-c-noinstall-6.0.2'
View success.txt
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-include=C:\mysql-connector-c-noinstall-6.0.2\include --with-mysql-lib=C:\mysql-connector-c-noinstall-6.0.2\lib --
with-mysql-dir=C:\mysql-connector-c-noinstall-6.0.2'
This could take a while...
Successfully installed mysql2-0.3.13
Parsing documentation for mysql2-0.3.13
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/mysql2/mysql2.so, skipping
Installing ri documentation for mysql2-0.3.13
1 gem installed
View block.rb
begin
# Code to be executed here
# This part will be 'protected'
raise # Use this to raise any message
rescue
# Exception Handling, like argument error, 404
retry # use this if you want the begin block to be executed again, if execption occurs.
ensure
# This part will always get executed.
end
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
end
class Community < ActiveRecord::Base
has_and_belongs_to_many :persons
end
View associations_with_where_clause
class Product < ActiveRecord::Base
has_many :suppliers, conditions: ["suppliers.status = ?", true]
end
# 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) }
end
View action_plan.rb
# app/models
class User < ActiveRecord::Base
has_many :responses, dependent: :destroy
end
class Response < ActiveRecord::Base
has_one :report
has_many :points
belongs_to :user
end
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 = Viewpoint::EWSClient.new endpoint, user, pass
View user_spec.rb
require 'spec_helper'
class User
def initialize(args = {}); end
def email
'someone@example.com'
end
def mobile