Skip to content

Instantly share code, notes, and snippets.

@malithsen
malithsen / generg.py
Created June 7, 2018 07:36
Generate a random graph with random edge weights
def erdos_renyi(n, m):
g = snap.TNEANet.New()
g.AddIntAttrE("weightInt", 0)
node_ids = [x for x in range(n)]
for x in node_ids:
g.AddNode(x)
counter = 0
while counter < m:
node1 = random.choice(node_ids)
node2 = random.choice(node_ids)
@malithsen
malithsen / link_pred.py
Created June 3, 2018 09:29
link prediction
@malithsen
malithsen / cv
Created October 26, 2017 14:18
Pipes the clipboard history to fzf and copies the selection
cv() {
strings ~/.local/share/clipit/history | fzf --ansi --multi | xclip -selection clipboard
}
@malithsen
malithsen / score
Created November 16, 2014 08:47
Get livescore when Sri Lanka is playing
alias score="curl http://static.cricinfo.com/rss/livescores.xml >/dev/null 2>&1 | grep -m 1 'Sri Lanka' | grep -o -P '(?<=\>).*(?=\<)'"
@malithsen
malithsen / pb
Created November 12, 2014 17:59
Pushbullet notifications.
#!/bin/sh
curl -u KEY: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type":"note", "title": "Shell", "body": "'"$1"'"}' > /dev/null 2>&1
@malithsen
malithsen / push.py
Created November 11, 2014 16:31
A python wrapper around Pushbullet. Ideal for long running scripts in remote shells.
import os, inspect
class Push:
"""A simple wrapper around Pushbullet"""
def __init__(self, key):
self.key = key
self.title = inspect.stack()[1][1]
def post(self, msg, title=None):
@malithsen
malithsen / clean.user.js
Last active August 29, 2015 14:02
Clutter free fb
(function(){
// hide friend activities
document.getElementById('pagelet_ticker').style.display = 'None';
// hides games of friends/ recommended games
document.getElementById('pagelet_canvas_nav_content').style.display = 'None';
// reposition on the main content area
document.getElementById('contentArea').style.paddingLeft = '100px';
// hide game requests/friend request column
document.getElementById('rightCol').style.display = 'None';
})();
@malithsen
malithsen / clever.py
Last active August 29, 2015 14:01
Pipe fb chats to cleverbot
#!/usr/bin/python
import sleekxmpp
import logging
from chatterbotapi import ChatterBotFactory, ChatterBotType
factory = ChatterBotFactory()
bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()
logging.basicConfig(level=logging.DEBUG)
@malithsen
malithsen / say.py
Created May 5, 2014 14:34
text to speech
import urllib2, sys, os
text = str(sys.argv[1]).replace(' ', '%20')
url = "http://translate.google.com/translate_tts?tl=en&q=" + text
request = urllib2.Request(url)
request.add_header('User-agent', 'Mozilla/5.0')
opener = urllib2.build_opener()
f = open("/tmp/data.mp3", "wb")
@malithsen
malithsen / gesture.py
Created April 28, 2014 12:11
Basic gesture recognition with SimpleCV
from SimpleCV import Camera, Display, Color
ON_CIRCLE = False
def parm_on_obj(a, b, r, obj):
global ON_CIRCLE
x = [a - r, a + r]
y = [b - r, b + r]
if (x[0] < obj.x < x[1]) and (y[0] < obj.y < y[1]):
ON_CIRCLE = True