Skip to content

Instantly share code, notes, and snippets.

@lovesh
lovesh / httpWrapper.scala
Last active August 29, 2015 14:01
Http request wrapper build with scalaj-http
import scalaj.http._
case class httpResponse(code: Int, body: String, url: String)
object httpRequest {
val options = Map(
"connTimeout" -> 5000,
"readTimeout" -> 5000
)
@lovesh
lovesh / tracker.js
Created April 23, 2014 07:46
code to integrate multiple services like kissmetrics, intercom, etc easily
/*
An array of services that you want to integrate. I didnt make it an object because these services are started and stopped in the order they appear in the array.
Here i have taken 3 examples- kissmetrcs, intercom and vero
Service properties:
enabled- Setting it to false doesnt start or track events for this service
start- This function is initialises the servcie. In this function i place the initialization code snipplet that the service provides me.
Takes an optional array which has the service names i want to start. If this parameter is ommited all services are started
stop- Some services like intercom have a shutdown function, so here goes that code
track- This is the tracking function that is used to track events with the service. Takes 2 parameters eventName and eventData
validate: Sometimes you dont want to send tracking for some accounts, maybe they are test accounts or you are logging into some account as admin.
@lovesh
lovesh / gcm_wrapper.py
Last active August 29, 2015 13:57
GCM wrapper in python using python requests. Allows sending message to multiple senders
import requests
import simplejson as json
import os
class GCMMultiRequest(object):
def __init__(self, gcm_url, headers):
self.gcm_url = gcm_url
self.headers = headers
self.session = requests.Session()
@lovesh
lovesh / mysql_wrapper.py
Created December 8, 2013 18:39
A MySQLdb wrapper class
import MySQLdb
import MySQLdb.cursors
from config import config
class Cursor(object):
def __init__(self, mysql_cursor):
self.cursor = mysql_cursor
def __iter__(self):
@lovesh
lovesh / admin.py
Last active November 7, 2019 19:37
django-admin register all models
"""
Here models are in different modules and the models.py imports them from different modules like this
from model1 import * # or the name of models you want to import
from model2 import User
or you might write all your models in models.py
"""