Skip to content

Instantly share code, notes, and snippets.

View santosh's full-sized avatar
:octocat:

Santosh Kumar santosh

:octocat:
View GitHub Profile
@santosh
santosh / thread_play.py
Last active January 14, 2018 10:23
Starting threads. #2
import threading
import time
def calc_square(numbers):
print("calculate square numbers")
for n in numbers:
time.sleep(0.2)
print('square', n*n)
def calc_cube(numbers):
@santosh
santosh / flaskRender.py
Created November 2, 2017 07:50
Render templates in Flask with Jinja2 template engine. #Flask #Python
from flask import Flask, request, make_response, redirect, \
render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/user/<name>')
def user(name):
@santosh
santosh / flaskCookie.py
Created November 2, 2017 07:32
Set cookies in flask. #Flask #Python
from flask import Flask, request, make_response, redirect
app = Flask(__name__)
@app.route('/')
def index():
response = make_response('<h1>This document carries a cookie!</h1>')
response.set_cookie('answer', '42')
return response
if __name__ == '__main__':
@santosh
santosh / flaskredirect.py
Created November 2, 2017 07:29
HTTP redirect in flask. #Flask #Python
from flask import Flask, request, make_response, redirect
app = Flask(__name__)
@app.route('/')
def index():
return redirect('http://www.sntsh.com/')
if __name__ == '__main__':
app.run(debug=True)
@santosh
santosh / senduseragent.py
Created November 2, 2017 07:12
Return back user agent in Flask. #Python
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def index():
user_agent = request.headers.get('User-Agent')
return '<p>Your browser is {}!</p>'.format(user_agent)
@app.route('/user/<name>')
def user(name):
@santosh
santosh / sumOfDigits.js
Created December 27, 2016 10:02
Calculate sum of digits in a number. e,g, 1234 = 10. #JavaScript
function digitSum(n) {
n = parseInt(n).toString()
var sum = 0;
for (var i = 0; i < n.length; i++) {
sum += parseInt(n[i]);
}
return sum;
}
@santosh
santosh / arrayMinimum.js
Last active December 27, 2016 10:00
Find the minimum number in an array. #JavaScript
function arrayMinimum(inputArray) {
var indexOfMinimum = 0;
for (var i = 1; i < inputArray.length; i++) {
if (inputArray[i] < inputArray[indexOfMinimum]) {
indexOfMinimum = i;
}
}
return inputArray[indexOfMinimum] ;
}
@santosh
santosh / functions.php
Created December 10, 2016 09:30
Add these line of codes to functions.php of your theme; to display thumbnail of featured image of the post. #WordPress
/*===================
ADD IMAGE TO FEED
===================*/
// display featured post thumbnails in RSS feeds
function WPGood_rss_thumbs( $content ) {
global $post;
if( has_post_thumbnail( $post->ID ) ) {
$content = '<figure>' . get_the_post_thumbnail( $post->ID, 'large' ) . '</figure>' . $content;
}
@santosh
santosh / bottom-flex-belt.html
Last active October 8, 2016 03:36
Bottom flex belt, as was done in ajneffects.com inspired from redgiant.com, but later replaced with something better. Pen here for future reference if ever needed to make one.
<!DOCTYPE html>
<html>
<head>
<title> Practicing </title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
</head>
<style type="text/css">
.thumbnail-grid {
user-select: none
@santosh
santosh / .vimrc
Created November 16, 2015 13:53
Minimal .vimrc file for Windows. Note that my dotfiles are on BitBucket. For sake of compatibility I am maintaining a different version for Windows.
" {{
se nocompatible autoindent autoread autowrite autowriteall confirm cindent expandtab foldenable gdefault hidden hlsearch ignorecase incsearch lazyredraw lbr nu ruler sm sc smd scs smartindent sta spell splitright ttyfast undofile noerrorbells wildmenu wrap equalalways splitbelow wrapscan list
" }}
se dir=~/tmp/vimswapfiles//,~/.vim/vimswapfiles// bs=eol,start,indent,start cb=unnamed cc=-1 cot=menu,longest,preview enc=utf-8 ffs=unix fdm=marker foldlevel=0 fmr={{,}} foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo formatoptions=tcqrn1 history=100 laststatus=2 matchtime=1 mouse=a nrformats=octal,hex,alpha scrolloff=5 shiftwidth=4 softtabstop=4 spl=en_us timeoutlen=300 tw=77 ts=4 undolevels=1000 udir=~/tmp/vimundo,~/.vim/vimundo uc=10 whichwrap+=<,>,[,],h,l wildchar=<tab> wig=*.o,*.obj,*.bak,*.exe,*.py[co],*.swp,*~,*.pyc,.svn guioptions-=T lcs=tab:?\ ,eol:¬,trail:·,nbsp:?
" ESSENTIALS
" ==========
" {{
filetype plugin indent on
let snips_author = 'Santosh Kumar'