Skip to content

Instantly share code, notes, and snippets.

@naiquevin
naiquevin / backup-git-stashes.md
Last active December 31, 2024 06:15
Script to backup stashes in a git repository

Usage

find . -name '.git' | xargs dirname | xargs -P 4 -n 1 -I % ./backup-stashes.sh % /tmp/stash-backups

Note

Much of the code is generated by Claude Sonnet 3.5. Exercise caution by going through it before executing.

@naiquevin
naiquevin / mysql.py
Created February 5, 2012 15:10
Examples of Mysql programming in Python
#!/usr/bin/env python
## Mysql-Python basic examples.
## All code is taken from [here](http://zetcode.com/databases/mysqlpythontutorial/)
## Gist created only for quick reference purpose
import sys
import _mysql
import MySQLdb as mdb
@naiquevin
naiquevin / clj-fn-usages
Last active March 8, 2023 17:22
A crude way to find clojure functions usages in a codebase using ripgrep (false positives possible)
#!/usr/bin/env bash
## Script for searching for all references to a particular function in
## a clojure project (A crude implementation of "Find usage"
## functionality commonly found in IDEs such as Intellij) False
## positives are possible.
##
## Usage:
##
## $ clj-fn-usages NAMESPACE_QUALIFIED_FN [ paths ... ]
@naiquevin
naiquevin / thankyou.py
Last active September 16, 2020 16:09
Python script to thank people who sent birthday wishes on facebook
import sys
from urllib import urlencode
import requests
from urlparse import urlparse, parse_qs
from random import choice
import re
self_id = None # your facebook id here
utc_bday = None # utc timestamp of your birthday
@naiquevin
naiquevin / currencies.json
Created September 1, 2012 06:48
Various currencies in json format and code for scraping data and using it in KodeCRM
[
{
"symbol": "Lek",
"code": "ALL",
"uhex": [
"4c",
"65",
"6b"
],
"name": "Albania Lek"
@naiquevin
naiquevin / comp.py
Last active April 13, 2019 15:09
Function composition in Python inspired by Clojure's `comp` function
## Update! Found an alternative approach that's concise and feels much more idiomatic
def compose (f, g):
return lambda x: f(g(x))
def comp(*args):
return reduce(compose, args[1:], args[0])
def comp1(*args):
@naiquevin
naiquevin / mirrors.sh
Created June 16, 2012 08:33
Setting up and maintaining Git repository mirrors
#!/bin/bash
## This shell script will read all names from repos.txt
## which are names of git repositories located at
## git@main-reposerver:/path/to/repos
## if a mirror is not created, it will create
##
## other wise it will try to update the mirror
##
## Main purpose of having mirrors is backup so pushing
@naiquevin
naiquevin / inclojure_mocks.clj
Last active January 13, 2018 11:54
Generative mocking using circleci/bond and core.spec (IN/Clojure 2018 lightning talk)
(ns inclojure-mocks)
;; IN/Clojure 2018 lightning talk :: 13/01/2018
;;
;; Topic: Mocking code (mainly for writing tests)
;;
;; Will be covered:
;;
;; 1. Mocking code using circleci/bond library
@naiquevin
naiquevin / tw.py
Created September 14, 2013 07:55
Twython wrapper for app authenticated requests to twitter api
from twython import Twython
## Defining access_token as a function so that the token may be cached
## using a decorator as follows,
##
## get_access_token = cache_textfile('.twython-token')(access_token)
##
def access_token(auth_client):
return auth_client.obtain_access_token()
@naiquevin
naiquevin / middleware.py
Created November 3, 2012 07:01
Examples for i18n using Django middleware blog post
class ChatLocaleMiddleware(object):
def process_request(self, request):
if request.path in ['/jsi18n/']:
return None
match = SHOPPER_CHAT_PATH.match(request.path)
if match is not None:
appid = match.groups()[0]
try:
store = Store.objects.get(appid=appid)