Skip to content

Instantly share code, notes, and snippets.

View bijayrungta's full-sized avatar

Bijay Rungta bijayrungta

View GitHub Profile
@bijayrungta
bijayrungta / yii-ar-rules.php
Last active September 24, 2015 17:37
Validation Rules for the Model.
class MyModel {
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array(
array(
'element',
@bijayrungta
bijayrungta / gist:784751
Created January 18, 2011 17:02
Check all Checkboxes in a Web page.
a = document.getElementsByTagName('input');
for (i=0;i<a.length;i++) {
if (a[i].type == 'checkbox') {
a[i].checked = true;
}
}
@bijayrungta
bijayrungta / tableDump.js
Created November 25, 2011 22:46
Get number of Rows for Tables from phpMyAdmin
o = document.getElementsByClassName('data')[0];
str = "";
for (i = 1; i < o.rows.length - 1; i++) {
str += o.rows[i].cells[1].getElementsByTagName('a')[0].innerHTML
+ ": " + o.rows[i].cells[8].innerHTML
+ "\n";
}
alert(str);
<?php
if (class_exists('Memcache')) {
$server = 'localhost';
if (!empty($_REQUEST['server'])) {
$server = $_REQUEST['server'];
}
$memcache = new Memcache;
$isMemcacheAvailable = @$memcache->connect($server);
if ($isMemcacheAvailable) {
@bijayrungta
bijayrungta / redirection-and-page-load-time.php
Last active December 18, 2015 01:48
This Snippet demonstrates how Redirection time is also counted towards User perceived Page Load time using
<?php
if (!empty($_GET['redir']) && $_GET['redir'] < 11) {
sleep(1);
$url = '?redir=' . ($_GET['redir'] + 1);
header("Location: {$url}");
exit;
}
?><!DOCTYPE html>
<html>
<head>
<?php
/**
* Get upcomming match schedule
*/
function getNextMatches($referenceTime = null)
{
$matchSchedule = array(
"2014-06-13 01:30:00" => array('team1' => 'BRA', 'team2' => 'CRO', 'date' => '2014-06-13 01:30:00', 'team1Class' => 'brazil', 'team2Class' => 'croatia'),
"2014-06-13 21:30:00" => array('team1' => 'MEX', 'team2' => 'CMR', 'date' => '2014-06-13 21:30:00', 'team1Class' => 'mexico', 'team2Class' => 'cameroon'),
@bijayrungta
bijayrungta / 0_reuse_code.js
Last active August 29, 2015 14:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bijayrungta
bijayrungta / bjMigrateMac.sh
Created June 2, 2015 10:23
Migrate to a new Mac
function bjMigrateMac()
{
# http://lowendmac.com/2009/step-by-step-guide-to-manual-mac-system-migration/#nowork
host="$1"
if [ ! "${host}" ]; then
host="mac13"
fi
declare -a aHomeFilesToSync=(
@bijayrungta
bijayrungta / jiraRefreshTickets.js
Created December 30, 2015 20:05 — forked from rtrcolin/jiraRefreshTickets.js
Super simple Google Docs integration with Jira Issues/Tickets
// URL for Jira's REST API for issues
var getIssueURL = "https://[Your Jira host]/rest/api/2/issue/";
// Personally I prefer the script to handle request failures, hence muteHTTPExceptions = true
var fetchArgs = {
contentType: "application/json",
headers: {"Authorization":"Basic [Your BASE64 Encoded user:pass]"},
muteHttpExceptions : true
};
@bijayrungta
bijayrungta / add-key.sh
Last active April 4, 2016 09:50
Add Key of a Github User into ~/.ssh/authorised_keys
#!/bin/bash
userDir=bijay
githubUser=bijayrungta
homeDir=/home/${userDir}
mkdir -p ${homeDir}/.ssh
if [ f ${homeDir}/.ssh/authorized_keys ]; then
echo "User ${userDir} exists with an 'authorized_keys' file"
else
wget https://github.com/${githubUser}.keys -O /tmp/${githubUser}.keys;