Skip to content

Instantly share code, notes, and snippets.

View kapilreddy's full-sized avatar

Kapil Reddy kapilreddy

View GitHub Profile
@kapilreddy
kapilreddy / Munin Redis plugin
Created April 15, 2011 14:00
A Munin plugin for Redis
#!/usr/bin/env python
## Copyright (c) 2011, Kapil Reddy
## All rights reserved.
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
@kapilreddy
kapilreddy / gist:1180721
Created August 30, 2011 11:42
generate query string from map
(defn [query-map]
(str "?" (apply str (map name (flatten (interpose :& (map #(interpose "=" %) (seq query-map))))))))
@kapilreddy
kapilreddy / gist:1259881
Created October 3, 2011 18:42
php config for emacs
(require 'flymake)
(defun flymake-php-init ()
"Use php to check the syntax of the current file."
(let* ((temp (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace))
(local (file-relative-name temp (file-name-directory buffer-file-name))))
(list "php" (list "-f" local "-l"))))
(add-to-list 'flymake-err-line-patterns
'("\\(Parse\\|Fatal\\) error: +\\(.*?\\) in \\(.*?\\) on line \\([0-9]+\\)$" 3 4 nil 2))
@kapilreddy
kapilreddy / gist:2867328
Created June 4, 2012 08:57
Precommit hook for js and clojure
#!/bin/sh
# A pre-commit hook for js and clojure
# It runs jshint on js files.
# and runs lein2 midje.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
@kapilreddy
kapilreddy / gist:2868737
Created June 4, 2012 14:32
A precommit hook for js
#!/bin/sh
# A pre-commit hook for js
# It runs jshint on js files.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
@kapilreddy
kapilreddy / gist:2868961
Created June 4, 2012 15:10
Midje emacs functions
(remove-hook 'clojure-mode-hook 'clojure-test-maybe-enable)
(defun clojure-in-tests-p ()
(or (string-match-p "test\." (clojure-find-ns))
(string-match-p "/test" (buffer-file-name))))
(defun midje-test-for (namespace)
(let* ((namespace (clojure-underscores-for-hyphens namespace))
(segments (split-string namespace "\\."))
@kapilreddy
kapilreddy / gist:3865597
Created October 10, 2012 13:18
OSX .bash_profile
##
# Prints terminal codes.
#
# Thanks to: http://github.com/wayneeseguin/rvm/blob/master/scripts/color
#
# @param [String] terminal code keyword (usually a color)
bput() {
case "$1" in
# regular colors
black) tput setaf 0 ;;
@kapilreddy
kapilreddy / application-tags.xml
Last active October 13, 2015 12:27 — forked from nayansuthar/application-tags.xml
helpshift initialization android
<activity android:name="com.helpshift.HelpshiftActivity" android:theme="@style/HSBottomAnimTheme" />
<activity android:name="com.helpshift.HSAddIssue" android:theme="@style/HSRightAnimTheme" />
<activity android:name="com.helpshift.HSAddProfile" android:theme="@style/HSRightAnimTheme" />
<activity android:name="com.helpshift.HSMessages" android:theme="@style/HSRightAnimTheme" />
<activity android:name="com.helpshift.HSQuestionsList" android:theme="@style/HSRightAnimTheme" />
<activity android:name="com.helpshift.HSQuestion" android:configChanges="orientation|screenSize" android:theme="@style/HSRightAnimTheme" />
@kapilreddy
kapilreddy / josephus.clj
Created February 27, 2013 08:27
A simple solution to Josephus problem with kill rate of 2.
(defn find-surviver*
[in]
(loop [[f s & coll] in]
(if (and f s)
(recur (concat coll [f]))
f)))
(defn find-surviver
[population]
@kapilreddy
kapilreddy / pubsub.clj
Last active December 15, 2015 05:49
A simple PubSub system written in Clojure.
(defn publish
([a & ch-vals]
(let [key-vals (mapcat (fn [[channel val]]
[channel {:val val
:id (java.util.UUID/randomUUID)}])
(partition 2 ch-vals))]
(apply swap! a assoc key-vals))))
(defn subscribe