Skip to content

Instantly share code, notes, and snippets.

View hiway's full-sized avatar

Harshad Sharma hiway

View GitHub Profile
@hiway
hiway / wrldata.sh
Created July 31, 2012 11:03
Scrape Indian Electrical Western Region Data
#!/bin/bash
curl -s http://www.wrldc.com/ | sed -n '/WR Grid Frequency/,/UI Rate/p' | sed -e 's#<[^>]*>##g' | sed 's/&nbsp;/ /g' | sed 's/UI Rate (Rs\/Unit)/ /g' | sed 's/ //g'
@hiway
hiway / follow_via_list.py
Created November 12, 2012 04:41
Utility to trim down your twitter following by moving users to lists and unfollowing automatically.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
try:
import tweepy
except:
raise Exception('Install tweepy library first! (pip install tweepy)')
@hiway
hiway / macosx-activity-logger-boilerplate.py
Created December 22, 2012 12:19
Boilerplate/ minimum code needed to log keyboard and mouse activity on MacOSX. Logs only whether there was any activity or not, not the actual keys/ locations.
import time
from Cocoa import *
from Foundation import *
from PyObjCTools import AppHelper
last_timestamp = time.time()
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, aNotification):
@hiway
hiway / macosx-activity-logger-menubar.py
Created December 22, 2012 13:08
Logs activity of key presses and mouse left-click, displays an icon in system menubar to depict activity mode. Can be used as boilerplate for sending activity log to server every x minutes.
import time
from Cocoa import *
from Foundation import *
from PyObjCTools import AppHelper
last_timestamp = time.time()
# put two images, 16*16px in a subdirectory called 'resources'
status_images = {
'inactive':'./resources/inactive.png',
@hiway
hiway / auth.py
Last active July 20, 2023 15:56
A bare-minimum implementation of Twitter's Streaming API using python-requests library. Prints out tweets as they come in.
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
@hiway
hiway / current_song.py
Last active December 10, 2015 11:28
Script to print currently playing track from iTunes on MacOSX — I use this to tweet out my favorite songs. (works on Snow Leopard) Bonus script: youtube_current_song.py will give you a youtube search URL for current song - again useful when tweeting. It also prints exception to stdout, useful for debugging with automation tools like TextExpander.
import appscript
itunes = appscript.app('itunes')
if itunes.isrunning():
track = itunes.current_track()
status = "#music %s by %s" %(track.name(), track.artist())
album = track.album()
if album:
status += " from %s" %(album)
@hiway
hiway / justdial_youtube_advert_block.user.js
Created January 10, 2013 06:04
Disable Autoplaying Youtube Advertisements on JustDial
// ==UserScript==
// @name Disable Autoplaying Youtube Advertisements on JustDial
// @namespace http://www.justdial.com
// @description Removes annoying advertisements.
// @include *.justdial.com/*
// ==/UserScript==
var yt_iframe = document.getElementById('adif');
var parent = yt_iframe.parentNode;
parent.removeChild(yt_iframe);
@hiway
hiway / bash_prompts.sh
Created January 15, 2013 06:38
A collection of useful bash prompts, starting with one.
export PS1="[\u] \w/\n\$ "
@hiway
hiway / models.py
Created January 22, 2013 05:52
Using Filepicker.io and Django South migrations together. South cannot introspect some fields, if you are redirected to http://south.aeracode.org/wiki/MyFieldsDontWork and looking for a solution specific to Filepicker's FPFileField, this is the code you're looking for.
from django_filepicker.models import FPFileField
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["django_filepicker\.models\.FPFileField"])
class Stuff(models.Model):
preview = FPFileField(upload_to='previews', null=True, blank=True)
@hiway
hiway / google_search.py
Last active December 12, 2015 03:28
Uses a [deprecated?] Google API to search for your query and returns URL of the first result. I use this with TextExpander to quickly put in URLs of services I'm mentioning in chats, emails or blog posts.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import sys
def get_search_results(query):
url = "http://ajax.googleapis.com/ajax/services/search/web"
payload = dict(