Skip to content

Instantly share code, notes, and snippets.

View kalpeshhpatel's full-sized avatar

Kalpesh Patel kalpeshhpatel

View GitHub Profile
@kalpeshhpatel
kalpeshhpatel / .block
Created June 26, 2018 09:00
fresh block
license: mit
@kalpeshhpatel
kalpeshhpatel / rx-shortpoll.js
Created May 21, 2018 10:23 — forked from pchi/rx-shortpoll.js
Short polling until predicate is met with RXJS
function getWikipediaSearchResults(term) {
return Rx.Observable.create(function forEach(observer) {
var cancelled = false;
var url = 'http://en.wikipedia.org/w/api.php?action=opensearch&format=json&search='
+ encodeURIComponent(term) + '&callback=?';
$.getJSON(url, function(data) {
if (!cancelled) {
observer.onNext(data[1]);
observer.onCompleted();
}
@kalpeshhpatel
kalpeshhpatel / retina_media_querry.css
Created November 14, 2016 06:08
CSS media query to target retina displays
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1),
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi),
only screen and ( min-resolution: 2dppx) {
/* Retina-specific stuff here */
@kalpeshhpatel
kalpeshhpatel / array_chunk.js
Last active July 7, 2016 10:06
Javascript Utility Functions
function chunk(arr, size) {
if(!Array.isArray(arr)) {
throw new TypeError("Input is not an array");
}
size = size || 1; //default size
if(size > arr.length) {
return arr;
} else {
var i = 0;
var j = size;
@kalpeshhpatel
kalpeshhpatel / display.css
Last active March 30, 2016 07:04
Collection of CSS utilities classes
.dis-block {
display: block;
}
.dis-inline-block {
display: inline-block;
}
.dis-inline {
display: inline;
@kalpeshhpatel
kalpeshhpatel / sort_obj_by_keys
Created April 8, 2015 10:42
Javascript: Sort Object By Keys
function sortObject(o) {
var sorted = {}, a = [],key;
//Get array keys
a = Object.keys(o);
//Sort it
a.sort();
//Construct object by iteration
for (key = 0; key < a.length; key++) {
sorted[a[key]] = o[a[key]];
}