Skip to content

Instantly share code, notes, and snippets.

View vibhasbhingarde's full-sized avatar

vibhasbhingarde vibhasbhingarde

View GitHub Profile
@vibhasbhingarde
vibhasbhingarde / webpack.config.js
Created October 25, 2018 05:54
webpack + boostrap snipplets
module.exports = env => {
entry:'filename.js',
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist")
},
module: {
rules: [
{
test: /\.m?js$/,
@vibhasbhingarde
vibhasbhingarde / compact.js
Created September 12, 2018 07:42
Reject undefined/Null element from array in short getting rid of conditional push
//https://triin.net/2010/01/13/Fighting_the_uglyness_of_Array.push()
var buttons = [
new OpenButton(),
isPayingCustomer() ? new ExportButton() : null,
new SaveButton(),
new DeleteButton()
].compact();
@vibhasbhingarde
vibhasbhingarde / filter values
Last active July 10, 2018 05:56
Filter array objects based on selection conditions.
var data = {"results":[{"answers":{"text":"A1"},"confidence":0.5,"name":"N1"},{"answers":{"text":"A2","type":"text"},"confidence":0.4,"name":"N2"},{"answers":{"text":"A3","type":"text"},"confidence":0.3,"name":"N3"},{"answers":{"text":"A4","type":"text"},"confidence":0.2,"name":"N4"},{"answers":{"text":"A5","type":"text"},"confidence":0.1,"name":"N5"}]};
// Version 1
var output = data.results.filter(ans => ans.confidence>0.2).map(ans => ({answer:ans.name,confidence:ans.confidence}));
// Version 2
var output = data.results.reduce((f,s)=>{
if(s.confidence > 0.2) f.push({answer:s.name,confidence:s.confidence})
return f;
},[]);
// version 3
var output = data.results.reduce((f,s)=> s.confidence > 0.2? [...f,{answer:s.name,confidence:s.confidence}] :f,[]);
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']));
// 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"
test
@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">
@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 / 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 / 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',