Skip to content

Instantly share code, notes, and snippets.

@bilalhusain
bilalhusain / gist:6536045
Created September 12, 2013 11:31
seconds since unix `date -R`
import time, email.utils
a = time.time() # now
b = email.utils.mktime_tz(email.utils.parsedate_tz('Thu, 12 Sep 2013 16:31:22 +0530')) # using output of `date -R`
a - b # difference in seconds
@bilalhusain
bilalhusain / :)
Created February 28, 2013 07:56
chain tweet trace
t.co/j0tbO1hReP => https://twitter.com/michaelklishin/status/306920194108956672
tweet text: Wow. https://t.co/7m0nk4e2m4
***
t.co/7m0nk4e2m4 => https://twitter.com/SeanChittenden/status/306916905325830145
tweet text: Wow. https://t.co/yy1EkCQg79
***
t.co/yy1EkCQg79 => https://twitter.com/fanf/status/306915206825656320
tweet text: Wow... https://t.co/psEXkHy4lL
***
t.co/psEXkHy4lL => https://twitter.com/JorgeO/status/306914115438379008
@bilalhusain
bilalhusain / opt.scala
Created October 10, 2012 09:44
scopt test
// mkdir /tmp/scopt_test
// cd /tmp/scopt_test
// echo 'libraryDependencies += "com.github.scopt" %% "scopt" % "2.1.0"' > build.sbt
// sbt clean compile "run --foo 7"
case class Config(foo: Int = -1)
object ScoptTest {
def main(args: Array[String]) {
val parser = new scopt.immutable.OptionParser[Config]("scopt", "2.x") {
@bilalhusain
bilalhusain / gist:2216007
Created March 27, 2012 13:45
hourly frequency plot using python matplotlib
#!/usr/bin/env python
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from datetime import datetime, tzinfo, timedelta
# a class to implement abstract tzinfo
class Zone(tzinfo):
def __init__(self, offset, isdst, name):
@bilalhusain
bilalhusain / gist:2214329
Created March 27, 2012 09:24
basic system information on a modern linux machine
#!/bin/bash -ex
#hardware
arch
grep --after 3 'model name' /proc/cpuinfo
lshw -quiet -short
# current status
vmstat -SM # unit in MB
df --human-readable
@bilalhusain
bilalhusain / gist:2006135
Created March 9, 2012 11:23
remove a particular character from the file (uses buffered streams)
fs = require 'fs'
omitCharCode = 0x00
if process.argv.length isnt 4
console.log 'insufficient arguments'
console.log "Usage: #{process.argv[0]} #{process.argv[1]} <source> <destination>"
process.exit()
source = process.argv[2]
@bilalhusain
bilalhusain / gist:2005565
Created March 9, 2012 07:51
mount network drive on linux
#!/bin/bash
USER=bilal
DOMAIN=localnetwork.com
LOCAL_LOCATION=/home/bilal/networkStorage
REMOTE_LOCATION=//{IP_ADDRESS}/{DIRECTORY}
sudo mount -t smbfs -o username=$USER,domain=$DOMAIN $REMOTE_LOCATION $LOCAL_LOCATION
echo -e "to unmount:\n\tsudo umount $LOCAL_LOCATION"
@bilalhusain
bilalhusain / gist:1977014
Created March 5, 2012 06:27
array of YYYYMMDD for last week (Sunday to Saturday)
#!/usr/bin/python
import datetime
import calendar
def getLastWeekStamps(today=datetime.date.today()):
"""Usage:
getLastWeekStamps()
getLastWeekStamps(datetime.date(2012, 1, 4))
"""
oneday = datetime.timedelta(days=1)
@bilalhusain
bilalhusain / gist:1958059
Created March 2, 2012 12:12
tsql, last week start and end date
-- fetches the last week date range (sunday to sunday)
-- for the specified time zone offset
DECLARE @OffsetMinutes AS SMALLINT = +330
DECLARE @UtcDate AS DATETIME = GETUTCDATE()
DECLARE @LocalDate AS DATETIME = DATEADD(MINUTE, @OffsetMinutes, @UTCDATE)
DECLARE @LastSunday AS DATETIME = CONVERT(VARCHAR(4), YEAR(@LocalDate))
+ '-' + CONVERT(VARCHAR(2), MONTH(@LocalDate))