Skip to content

Instantly share code, notes, and snippets.

View harishvc's full-sized avatar

Harish Chakravarthy harishvc

View GitHub Profile
@harishvc
harishvc / background.js and content.js (events are added or removed)
Last active December 30, 2015 09:45
mapit - background.js (events are added or removed)
//background.js
chrome.runtime.onInstalled.addListener(
function () {
chrome.alarms.create("gcgmalarm",{when: Date.now() + 10*1000,periodInMinutes: 2});
});
function alarmcount(callback) {
var count;
chrome.alarms.getAll(function(alarms) { callback(alarms.length) });
}
@harishvc
harishvc / background.js (active and inactive tab)
Created December 30, 2015 09:32
mapit - background.js (active and inactive tab)
var match = 'https://calendar.google.com/calendar/render'
//http://stackoverflow.com/questions/18162644/adding-a-listener-that-fires-whenever-the-user-changes-tab
//When Google Calendar browser tab is active again!!!
chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function (tab) {
//chrome.tabs.sendMessage(activeInfo.tabId, {action: "tabactive", consolelog: tab.url.substring(0, match.length)},function(response) {});
if (tab.url.substring(0, match.length) === match) {
chrome.tabs.sendMessage(activeInfo.tabId, {action: "start"}, function(response) {});
}
@harishvc
harishvc / content.js (browser resize)
Last active December 30, 2015 09:34
mapit - content.js (browser resize)
var timeoutId = 0;
window.addEventListener('resize', function() {
if (DEBUG === true) { console.log("browser resizing ......");}
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(function() {
Start();
timeoutId = 0;
}, 100);
@harishvc
harishvc / background.js
Created December 30, 2015 09:07
mapit - background.js
//All content loaded in the Google Calendar browser tab!
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: "start"}, function(response) {});
});
};
});
@harishvc
harishvc / content.js
Last active January 3, 2016 14:51
mapit - content.js
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
//tab loaded
if (msg.action == 'start') {
if (DEBUG === true) { console.log("tab loaded");}
Start();
}
});
function Start(){
var today = document.getElementsByClassName('lv-location');
@harishvc
harishvc / manifest.json
Last active December 30, 2015 08:47
mapit - manifest.json
{
"manifest_version": 2,
"name": "MapIt for Google Calendar",
"version": "0.1",
"content_scripts": [
{
"matches": ["*://calendar.google.com/calendar/render*"],
"js": ["content.js"]
}
],
@harishvc
harishvc / generator-5.py
Last active November 30, 2015 04:32
Find different combinations
# Find different combinations
def combinations(n):
yield ""
for i, d in enumerate(n):
for combination in combinations(n[i+1:]):
yield d + combination
print([x for x in combinations("abc")])
#output
['', 'a', 'ab', 'abc', 'ac', 'b', 'bc', 'c']
@harishvc
harishvc / generator-4.py
Last active November 30, 2015 04:36
Find the first n number of the Fibonacci series
#Reference: http://pythoncentral.io/python-generators-and-yield-keyword/
#Find the first n number of the Fibonacci series
def fibonacci(n):
curr = 1
prev = 0
counter = 0
while counter < n:
#print("Generator invoked ..")
yield curr
@harishvc
harishvc / generator-3.py
Last active November 30, 2015 04:35
Read small chunks from big buffer
#Reference: http://pythoncentral.io/python-generators-and-yield-keyword/
#Read small chunks from big buffer
def buffered_read(input):
#Read a big chunk of data
buffer = input
#Return small chunks on demand
for small_chunk in buffer:
print("Generator invoked ..")
yield small_chunk
#Reference: http://pythoncentral.io/python-generators-and-yield-keyword/
from time import sleep
def hold_client(name):
yield 'Hello, %s! You will be connected soon' % name
yield 'Dear %s, could you please wait a bit.' % name
yield 'Sorry %s, we will play a nice music for you!' % name
yield '%s, your call is extremely important to us!' % name
yield '%s, please call back latter' % name
# putting it all together