Skip to content

Instantly share code, notes, and snippets.

View hussaintamboli's full-sized avatar

Hussain Tamboli hussaintamboli

View GitHub Profile
@hussaintamboli
hussaintamboli / Web Snippet - Basic
Last active September 14, 2018 10:51
Web Snippets for Pinn
<!-- START OF USER'S CODE -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
fetch('http://www.mocky.io/v2/5b6137303000007f006a4018').then(function(response) {
return response.json();
}).then(function(data) {
console.log(data);
}).catch(function(err) {
console.log(err.stack);
});
@hussaintamboli
hussaintamboli / Python3 Virtualenv Setup.md
Last active February 14, 2018 09:03 — forked from pandafulmanda/Python3 Virtualenv Setup.md
Setting up and using Python3 Virtualenv on Mac

Python3 Virtualenv Setup

Requirements
  • Python 3
  • Pip 3
$ brew install python3
@hussaintamboli
hussaintamboli / urlparse.py
Created June 22, 2016 05:57 — forked from zhenyi2697/urlparse.py
Python: urlparse demo
#!/usr/bin/python
# The urlparse module provides functions for breaking URLs down into their
# component parts, as defined by the relevant RFCs.
from urlparse import urlparse
# PARSING
parsed = urlparse('http://user:pass@NetLoc:80/path;parameters?query=argument#fragment')
@hussaintamboli
hussaintamboli / Custom response in Flask
Last active October 29, 2020 00:22
Return a Custom response in flask restful API
from flask import Response, jsonify
import json
from flask_restful import Resource
class Api(Resource):
def post(self):
response = Response(
response=json.dumps(dict(error='err')),
@hussaintamboli
hussaintamboli / Angularjs paginate filter
Last active August 29, 2015 14:23
A paginate filter in angularjs for maintaining pagination window with current page in the middle
.filter('paginate', function() {
return function(arr, page, END, START, WINDOW) {
if (typeof(START)==='undefined') START = 0;
if (typeof(WINDOW)==='undefined') WINDOW = 5;
var start = Math.floor(page - WINDOW/2);
var end = Math.floor(page + WINDOW/2);
if (start >= START && end <= END) {
@hussaintamboli
hussaintamboli / Python Pagination
Last active December 30, 2021 19:38
Code snippet for basic Pagination logic in python
START, END, WINDOW = 0, 15, 5
def pages(page):
start = page - WINDOW/2
end = page + WINDOW/2
if start >= START and end <= END:
return range(start, end+1)
if start <= START:
@hussaintamboli
hussaintamboli / jQueryBenchmarkingDynamicInputElementCode
Last active August 29, 2015 14:01
jQuery: adding <input> elemnts to a div. 1. by adding tags 2. by adding input elements. Which way is faster? Also This code seems to run in lesser time in Google Chrome than Firefox. Why? You can test it in jsbin.com
<html><head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function ($) {
// code1
var start = +new Date();
var html = '';
for (var i = 0; i < 1000; i++) {
$('#container1').append('<input name="text' + i + '"' + ' value="' + i + '" />');
@hussaintamboli
hussaintamboli / JQuery : Edit, Save and Cancel scenario
Created April 29, 2014 05:36
The right way of Ajax for Edit, Save and Cancel scenarios for Web
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<span id="spanId" style="float:left;"> Guest </span>&nbsp;
<input type="text" id="inputField" style="display:none;">
<input type="submit" value="Edit" name="editButton" id="editButton" onclick="editIt();" />
<input type="submit" value="Save" id="saveButton" style="display:none;" onclick="saveIt(this);">
<input type="submit" value="Cancel" id="cancelButton" style="display:none;" onclick="$('#saveButton').hide();$('#editButton').show(); $(this).hide();$('#inputField').hide(); $('#spanId').show();">
@hussaintamboli
hussaintamboli / Calendar in PHP
Created March 14, 2014 05:47
A Calendar in PHP. Kind of looks like Github's activity calendar but vertical.
<?php
$year = '2014';
$start = date("$year-01-01");
$end = date("$year-12-t");
$week = array();
$month = array();
$i = 0;
print_r("Calendar: $year\n\n");