Skip to content

Instantly share code, notes, and snippets.

View HemantNegi's full-sized avatar
💭
I may be slow to respond.

Hemant Negi HemantNegi

💭
I may be slow to respond.
View GitHub Profile
@HemantNegi
HemantNegi / HTML5 Placeholder fallback
Created June 3, 2014 11:48
light weight - HTML Placeholder Attribute Fallback for internet explorer
function PF(){var a=document.createElement("input");this.ips="placeholder" in a;this.init()}PF.prototype._addEvent=function(a,c,b){if(a.addEventListener){a.addEventListener(c,b,false)}else{if(a.attachEvent){a.attachEvent("on"+c,b)}else{a["on"+c]=b}}};PF.prototype.init=function(){var e=this;var b=document.getElementsByTagName("input");for(var d=0,a=b.length;d<a;d++){var c=b[d],g=c.getAttribute("placeholder");if(g&&!this.ips){e._fix(c,g)}e._addChangedProperty(c)}};PF.prototype._addChangedProperty=function(b){var a=this;b.changed=false;b.getValue=function(){return this.changed?this.value:""};if(b.addEventListener){b.addEventListener("input",function(){this.changed=!!this.value},false)}else{b.attachEvent("onpropertychange",function(c){var d=b;c=c||window.event;if(c.propertyName=="value"){d.changed=!!d.value;if(d.changed){
d.style.color="black"
}}})}};PF.prototype._setPlaceholderText=function(b,a){b.value=a;
b.style.color="#A9A9A9";
b.changed=false};PF.prototype._fix=function(c,a){var b=this;b._setPlaceholderText(
@HemantNegi
HemantNegi / fb_remove_reecnt_posts.js
Created March 12, 2015 07:53
Facebook remove your recent posts (or spam posts sent from your profile)
window.EXITEM = false;
var INTERVALID = setInterval(function() {
if (!window.EXITEM) {
var btn = document.getElementsByClassName('_42ft _42fu _4-s1 _2agf _p _42gx');
if (btn.length) {
btn[0].click();
btn[0].remove();
window.EXITEM = true;
@HemantNegi
HemantNegi / create_cirrcle
Created March 19, 2015 12:18
create a circle by radius/distance and angle
function getpoint(d,angle){
return {
x: 500 + d * Math.sin(angle * Math.PI/180),
y: 300 + d * Math.cos(angle * Math.PI/180)
}
}
for(var i = 0; i<200; i +=2){
for(var a=0; a<=360; a++){
var p = getpoint(i,a);
@HemantNegi
HemantNegi / django_html_pagination
Created May 19, 2015 13:16
Django pagination in template using django paginator ( the cool client side representation )
def make_pagination(paginator, items=4, show_arrows=True, edges=2):
"""
Returns a list by which a pagination can be prepared in template by simply
iterating over it
:param paginator: the django paginated queryset. (what you get after paginator.page(.....))
:param items: the number of items to show in center sub-list (place even numbers only)
:param show_arrows: show arrows at end and beginning.
:param edges: no of items to show at the edges including '...' (set edges=0 to hide )
:return: (sample output)
@HemantNegi
HemantNegi / compress.py
Created September 20, 2017 15:56
Cron job to compress the images on a server
# sudo apt-get install jpegoptim
# sudo apt-get install optipng
# jpegoptim -m90 04/*.jpg
# optipng 02/sharp_ps2_8x6.png
import os
import time
import glob
from subprocess import call
from datetime import datetime, timedelta
@HemantNegi
HemantNegi / compress.py
Created September 20, 2017 15:56
Cron job to compress the images on a server
# sudo apt-get install jpegoptim
# sudo apt-get install optipng
# jpegoptim -m90 04/*.jpg
# optipng 02/sharp_ps2_8x6.png
import os
import time
import glob
from subprocess import call
from datetime import datetime, timedelta
@HemantNegi
HemantNegi / compress.py
Created September 20, 2017 15:57
Cron job to compress the images on a server
# sudo apt-get install jpegoptim
# sudo apt-get install optipng
# jpegoptim -m90 04/*.jpg
# optipng 02/sharp_ps2_8x6.png
import os
import time
import glob
from subprocess import call
from datetime import datetime, timedelta
@HemantNegi
HemantNegi / special_elements.py
Created September 28, 2018 10:26
Special elements in a matrix
# Complete the countSpecialElements function below.
def countSpecialElements(matrix):
items = set()
for m, row in enumerate(matrix):
min_i, max_i, solution = min_max_in_list(row)
if not solution:
return -1
# add as row_col
items.add('%d_%d' % (m, min_i))
items.add('%d_%d' % (m, max_i))
@HemantNegi
HemantNegi / max_path_sum_game.py
Created October 24, 2018 10:01
Find max path sum
# Complete the 'maxPathSum' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. 2D_INTEGER_ARRAY board
# 2. INTEGER p
# 3. INTEGER q
# NOTE use a dict to cache the results ro improve performance.
@HemantNegi
HemantNegi / atm_machine.py
Created October 24, 2018 13:02
implement an ATM machine.
# Enter your code here. Read input from STDIN. Print output to STDOUT
# DENOMINATIONS: 5 10 20 50
# BILLS: 4 3 1 1
# withdraw(75): return the number of bills/denomination (e.g.: one bill of 5, one bills of 20, one bill of 50)
NOTES = {
# 1: 10,
5: 4,