Skip to content

Instantly share code, notes, and snippets.

View srishanbhattarai's full-sized avatar
💭
Make software fast again

Srishan srishanbhattarai

💭
Make software fast again
View GitHub Profile
@srishanbhattarai
srishanbhattarai / javascript.snippets
Last active July 9, 2019 01:45
JavaScript/React/Redux/React-native snippets for Vim (UltiSnips)
###########################################################################
# REACT SNIPPETS #
###########################################################################
snippet ccom "Class React Component" bA
class $1 extends Component {
render() {
return (
<$2>
$0
</$2>
@srishanbhattarai
srishanbhattarai / setup.py
Last active August 14, 2017 17:34
A setup.py sample for Python projects
from setuptools import setup
with open('README.md') as f:
long_description = f.read()
setup(
name='package name',
version='0.0',
license='MIT',
description='Short description',
@srishanbhattarai
srishanbhattarai / commits.py
Created January 18, 2018 06:53
Get GitHub commits for a user using GitHub Events API
import os
import sys
import requests
from pprint import pprint
EVENTS_URL = "https://api.github.com/users/{username}/events"
class Github():
def __init__(self, token):
self.token = token
@srishanbhattarai
srishanbhattarai / oauth-github.go
Last active January 21, 2018 17:08
Proof of concept OAuth flow in RESTful Go servers
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
@srishanbhattarai
srishanbhattarai / adapter.go
Last active January 22, 2018 19:59
Adapters for middleware in Go
package main
// Adapter takes in a http.Handler, enhances it,
// and returns another http.Handler
type Adapter func(http.Handler) http.Handler
// Composes variadic adapters and returns a final
// adapter to be applied to the http.Handler
func Compose(adapters ...Adapter) Adapter {
return func(h http.Handler) http.Handler {
@srishanbhattarai
srishanbhattarai / interpolate.go
Created February 4, 2018 04:49
Interpolate strings in curly braces with a map.
package util
import "strings"
// Interpolate replaces the values in the input string
// inside parentheses with the params supplied.
// Example:
// Interpolate("/{owner}/{repo}", map[string]string{"owner: "golang", "repo": "go"})
// Returns:
// "/golang/go"
@srishanbhattarai
srishanbhattarai / .tmux.conf
Last active February 22, 2018 14:41
Sane copy pasta - tmux 2.5 + neovim + terminal (tested on Alacritty/iTerm2)
# References:
# https://github.com/tmux/tmux/issues/543
# https://github.com/tmux/tmux/issues/543#issuecomment-298193820
#
# PREREQUISITE:
# ❯ brew install reattach-to-user-namespace --wrap-pbcopy-and-pbpaste
# Add the following snippet to your .tmux.conf -
setw -g mode-keys vi
set -g default-shell $SHELL
@srishanbhattarai
srishanbhattarai / init.vim
Created February 24, 2018 07:12
Cross platform Python paths for Neovim
if (has('nvim'))
" Path to Python2 and Python3 binaries which are required by some plugins.
" A function that runs the shell `which` command and sanitizes the output.
function! Which(cmd)
return substitute(system("which " . a:cmd), "\n", "", "")
endfunction
let g:python_host_prog = Which("python2")
let g:python3_host_prog = Which("python3")
@srishanbhattarai
srishanbhattarai / spotify.applescript
Last active January 18, 2021 11:39
Get currently playing track on Spotify desktop - MacOS and Linux
on escape_quotes(string_to_escape)
set AppleScript's text item delimiters to the "\""
set the item_list to every text item of string_to_escape
set AppleScript's text item delimiters to the "\\\""
set string_to_escape to the item_list as string
set AppleScript's text item delimiters to ""
return string_to_escape
end escape_quotes
tell application "Spotify"
@srishanbhattarai
srishanbhattarai / prune.go
Last active March 29, 2018 07:30
Prune files matching a pattern in the current working dir
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"sync"