Skip to content

Instantly share code, notes, and snippets.

View anishpateluk's full-sized avatar

Anish anishpateluk

  • Super Awesome
  • United Kingdom
View GitHub Profile
@anishpateluk
anishpateluk / postgres_queries_and_commands.sql
Last active November 25, 2019 17:40 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@anishpateluk
anishpateluk / retry-circuit-breaker.js
Last active February 24, 2018 22:19
basic js retry circuit breaker for async functions
function retryCircuitBreaker(attempts, limit, wait, fn) {
return new Promise((resolve, reject) => {
setTimeout(function() {
fn().then(resolve).catch(reject);
}, attempts * wait);
}).catch(function(error) {
console.log(error);
if(attempts > limit){
return Promise.reject(error);
}
ko.observableArray.fn.trackHasItems = function () {
//create a sub-observable
this.hasItems = ko.observable();
//update it when the observableArray is updated
this.subscribe(function (newValue) {
this.hasItems(newValue && newValue.length);
}, this);
//trigger change to initialize the value
@anishpateluk
anishpateluk / index.html
Last active October 27, 2015 15:50
knockoutJS rendering tests - jsbin: https://output.jsbin.com/wihola
<!DOCTYPE html>
<html>
<head>
<title>Knockout Performance Tests</title>
<meta charset="utf-8" />
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-debug.js"></script>
<script src="https://rawgit.com/brianmhunt/knockout-fast-foreach/master/dist/knockout-fast-foreach.js"></script>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css"/>
@anishpateluk
anishpateluk / gist:64ff5ae385b770532322
Created July 17, 2014 17:58
Selectize with KnockoutJS
/*
knockout-selectize.js (v0.1)
Copyright (c) Ninjacode Limited - http://ninjacode.co.uk
License: MIT (http://www.opensource.org/licenses/mit-license.php)
@auther Anish Patel, Ninjacode
*/
(function (ko, $, undefined) {