Skip to content

Instantly share code, notes, and snippets.

View sujeetkv's full-sized avatar
🎯
Focusing

Sujeet Kumar sujeetkv

🎯
Focusing
  • New Delhi, India
View GitHub Profile
@sujeetkv
sujeetkv / exectimelog.py
Last active July 18, 2024 11:31
Python context manager cum decorator to log execution time
import logging
from time import perf_counter
from contextlib import ContextDecorator
class exectimelog(ContextDecorator):
def __init__(self, msg='Elapsed time', logger=None):
self.msg = msg
self.logger = logger or logging.getLogger(__name__)
@sujeetkv
sujeetkv / shake.css
Created August 31, 2020 09:05
Shake effect CSS
/**
shake effect
use any of following classes on the element to shake
*/
.shake {
-webkit-animation: shake 0.45s;
-moz-animation: shake 0.45s;
animation: shake 0.45s;
}
.shake-2 {
@sujeetkv
sujeetkv / example-site.conf
Created April 23, 2020 11:38
Django Apache Server Example
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin [email protected]
DocumentRoot /path/to/example-site/app/app/web/static
Alias /robots.txt /path/to/example-site/app/app/web/static/robots.txt
Alias /favicon.ico /path/to/example-site/app/app/web/static/favicon.ico
@sujeetkv
sujeetkv / flask_menu.py
Last active July 19, 2019 11:27
Generate menu dynamically for flask application
from collections import OrderedDict
from flask import g
class FlaskMenu(object):
"""Generate menu for flask application.
Example::
# create object
app_menu = FlaskMenu(children=[
@sujeetkv
sujeetkv / dict_object.py
Last active July 6, 2019 02:29
Make a dictionary behave like an object, with attribute-style access.
class DictObject(dict):
"""Dict behaving like an object, with attribute-style access."""
__strict_attr__ = True
__attr_default__ = None
def __getattr__(self, name):
try:
return self[name]
except KeyError:
@sujeetkv
sujeetkv / template-snippet.js
Last active July 10, 2024 13:12
Basic template parser in JavaScript
/**
* Basic template parser
*/
var TemplateSnippet = function (template) {
'use strict';
// var re = /<%([^%>]+)?%>/g;
// var re = /<%(.+?)%>/g;
var re = /\{\{(.+?)\}\}/g;
var snippet = 'var snippet=[];\n', cursor = 0, match;
var add = function (line, js) {
@sujeetkv
sujeetkv / prop-state.js
Last active June 17, 2019 09:05
Simple State-Observer in JavaScript
/**
* Simple State-Observer in JavaScript
*/
var PropState = function () {
var _self = this;
var _state = {};
var _callbacks = {};
if (arguments.length) {
for (var i in arguments) {
var obj = arguments[i];
@sujeetkv
sujeetkv / url-state.js
Last active February 19, 2019 07:29
URL State manipulation utility
/**
* URL State manipulation utility
*
* Usage Example:
* //urlState.strictMode = (function() { return !this; })();
* var queryString = urlState.search();
* queryString.name = 'sujeet';
* urlState.pathname('/result-page').search(queryString).update();
*/
(function (win) {
@sujeetkv
sujeetkv / slug-regex-example.js
Created January 11, 2019 06:52
Slug Regex Example
/**
* (?!_) can not start with seperator
* (?!.*?_$) can not start with seperator
* [a-z] first letter should be alphabet
* [a-z_]+ other slug string
*
* @see https://unix.stackexchange.com/questions/78481/regex-to-match-identifiers-without-double
*/
var regex = /^(?!_)(?!.*?_$)[a-z][a-z_]+$/;
@sujeetkv
sujeetkv / npm-with-private-repo.md
Last active November 11, 2024 13:55
Use private repo as npm dependency.

Use private repo as npm dependency

Create Deploy-Token (Access-Token) for particular private repo and use it in dependency as following:

{
    "dependencies": {
        "package-name": "git+https://<username>:<access_token>@github.com/username/repository#{branch|tag}"
    }
}