Skip to content

Instantly share code, notes, and snippets.

View verma's full-sized avatar
💭
Working from home because the virus is out to get us!

Uday Verma verma

💭
Working from home because the virus is out to get us!
View GitHub Profile
(ns node-tests.core
(:require [cljs.nodejs :as nodejs]
[cljs.core.async :as async :refer [<!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(nodejs/enable-util-print!)
(defn clojureify [f]
(fn [] (js/console.log f)))
(ns node-tests.core
(:refer-clojure :exclude [exists?])
(:require [cljs.nodejs :as nodejs]
[cljs.core.async :as async :refer [<!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(nodejs/enable-util-print!)
;; Some helpers which help transform node style functions into clojurey ones
;;
;; input lines are like:
;; fs.truncate(path, len, callback)
;; fs.truncateSync(path, len)
;; fs.chown(path, uid, gid, callback)
;; fs.chownSync(path, uid, gid)
;; which are converted to:
;; (def ftruncate (core/clojureify fs.ftruncate))
;; (def ftruncate-sync (core/clojureify-sync fs.ftruncateSync))
;; ...
(defn- -single-line-input [value on-key placeholder]
(fn [value on-key placeholder]
[:input.form-control.input-lg {:type "text"
:value @value
:on-key-down on-key
:on-change #(reset! value (.. % -target -value))
:placeholder placeholder
:autoFocus true}]))
(defn- single-line-input [value on-key placeholder]
@verma
verma / message.log
Created March 14, 2012 00:41
Twisted logging problem
2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] Server Shut Down.
2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] Server Shut Down.
2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] Server Shut Down.
2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] Server Shut Down.
2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] Server Shut Down.
2012-03-13 19:39:14-0500 [-] 2012-03-13 19:39:14-0500 [-] 2012-0
@verma
verma / test.py
Created March 14, 2012 00:50
A simple program running a dummy service
# test.py
from twisted.application import internet, service
from twisted.python import log
from twisted.python.logfile import DailyLogFile
from twisted.internet.task import LoopingCall
import os
@verma
verma / gist:2304994
Created April 4, 2012 19:36
Normalize an Angle
static inline real_t NormalizeAngle(real_t rAngle) {
real_t a = std::fmod(rAngle, 2 * pd::math::PI);
if (IsGreaterOrEqual(a, pd::math::PI))
a = -2 * pd::math::PI + a;
else if (IsLessOrEqual(a, -pd::math::PI))
a = 2 * pd::math::PI + a;
return a;
}
@verma
verma / fswatcher.py
Created April 10, 2012 19:38
FileSystem Directory Watcher
# fswatcher.py
# Watches a particular directory for files with corresponding .lock files
#
from twisted.internet import reactor
import os
class DirectoryWatcher(object):
def __init__(self, dirname, interval=1.0):
self.dirname = dirname
@verma
verma / write_rtp.cpp
Created June 27, 2012 18:43
Write variable length rtp data to a file
void write_rtp(std::ostream& os, const char *rtp_data, int length) {
unsigned short len = htons((unsigned short)length);
os.write((char*)&len, sizeof(len));
os.write(rtp_data, length);
}
@verma
verma / default_call_flow.rb
Created September 11, 2012 20:22
A simple DSL example for Call-flow generation
TxIVR do
say "Hello, good morning"
play "http://s3.amazon.com/verma/company.mp3"
dialog do
play "http://s3.amazon.com/verma/menu.mp3"
option key: "1", speech: "balance" do
say do
get "http://vendor.com/newcall/balance"