Skip to content

Instantly share code, notes, and snippets.

View vibhasbhingarde's full-sized avatar

vibhasbhingarde vibhasbhingarde

View GitHub Profile
@vibhasbhingarde
vibhasbhingarde / gist:faf415fbac1aa7c2bb59
Created May 30, 2014 18:53
Convert assoc array with id and title array to ci_dropdown array
function array_to_select($results, $value = 'id', $key = 'title', $add_blank=false)
{
// Converts objects to arrays
if(is_object($results)) $results = get_object_vars($results);
$options = array();
if(!empty($add_blank)) $options = array(null=>$add_blank);
// Will only run if results is an array, not a string, int, etc.
@vibhasbhingarde
vibhasbhingarde / GetSingleKeyArray
Last active August 29, 2015 14:02
Convert Single key array to dropdown array
function GetSingularValuesArray($arr)
{
$result=array();
foreach($arr as $key=>$value):
$temp=key($value);
$result[]=is_object($value)?$value->$temp:$value[$temp];
endforeach;
return $result;
}
@vibhasbhingarde
vibhasbhingarde / query.sql
Created June 4, 2014 11:49
Code to set 1 to 0 & vice versa via mysql query
mysql_query("Update awards set `active` = if(`active`=0,1,0) where `id`={$_GET['id']}");
@vibhasbhingarde
vibhasbhingarde / autocomplete.php
Created June 16, 2014 09:59
Jquery Ajax Auto Complete
HTML :
<input type="text" name="userid" />
JAVAASCRIPT :
<script>
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery('#userid').autocomplete({source:function(request,response){
jQuery.ajax({
type:'post',
@vibhasbhingarde
vibhasbhingarde / usort.php
Created June 30, 2014 09:30
Sorting Multidimesional array
function cmp($a, $b) {
if ($a['TotalEarnings'] == $b['TotalEarnings']) {
return 0;
}
if ($_GET['sortby'] == "earnings"):
$orderBy = ($_GET['order'] == 'a') ? "DESC" : "ASC";
endif;
if ($orderBy == "DESC"):
@vibhasbhingarde
vibhasbhingarde / 0_reuse_code.js
Last active August 29, 2015 14:06
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
@vibhasbhingarde
vibhasbhingarde / geolocation.html
Last active August 29, 2015 14:10
Get user's geolocation without using any paid service
<!-- need to add jquery and jquery.cookie.js-->
<body onload="loadLocation()">
<div id="container">
<div class="inner-container">
<div class="box box-50">
<div class="boxin">
<div class="header">
<h3>HTML5 Geo-Location</h3>
</div>
<div class="content">
test
// Check if nested property exists or not
var propertyexists = (objectname,path) => path.split(".").reduce((k,v) => (typeof k=="undefined")?k:k[v],objectname);
var myobject = {info:{name:"vibhas"}};
console.log(propertyexists(myobject,"info.name.jhgfdsa.asdfghj"));
// If exists it return that value or "undefined"
function reject(obj, keys) {
return Object.keys(obj)
.filter(k => !keys.includes(k))
.map(k => Object.assign({}, {[k]: obj[k]}))
.reduce((res, o) => Object.assign(res, o), {});
}
console.log(reject({a: 2, b: 3, c: 4}, ['a', 'b']));