Skip to content

Instantly share code, notes, and snippets.

View rif's full-sized avatar

Radu Ioan Fericean rif

View GitHub Profile
#!/usr/bin/env python3
from subprocess import check_output
from re import findall, DOTALL, MULTILINE
inputs = findall(r'.*?index: (\d+).*?sink: (\d+).*?application\.process\.id = "(\d+)"',
check_output(['pacmd', 'list-sink-inputs']).decode("utf-8"), DOTALL|MULTILINE)
sinks = findall(r'index: (\d+)', check_output(['pacmd', 'list-sinks']).decode("utf-8"))
focused_window = check_output(['xdotool', 'getwindowfocus'])
focused_pid = check_output(['xdotool', 'getwindowpid', focused_window]).strip().decode("utf-8")
#!/usr/bin/env python3
from subprocess import check_output
from json import loads
from re import findall, DOTALL, MULTILINE
def find_focused(tree):
if tree["focused"] == True:
return tree["pid"]
elif 'nodes' in tree:
@rif
rif / keybase.md
Last active November 19, 2018 21:11

Keybase proof

I hereby claim:

  • I am rif on github.
  • I am rif (https://keybase.io/rif) on keybase.
  • I have a public key ASDGzWKFfj0sz-HG-rbtNhIJuaRgkkheicvFX5_AB4SSDAo

To claim this, I am signing this object:

04f3096f7f07fff50233225ecf5f7ccc76f5d2835f89dedb379a44942265fb2eae93523ddcef28ca5f71abafe2d75078c411e2af7631e4ceb9f9ac2a19e084db16 andrewallaway
package main
import (
"encoding/json"
"fmt"
"log"
"sort"
"time"
"github.com/gocolly/colly"
@rif
rif / gist:3854492
Created October 8, 2012 19:42
web2py book redis cache fix
diff --git a/sources/29-web2py-english/13.markmin b/sources/29-web2py-english/13.markmin
index 599d8b8..8e8c01e 100644
--- a/sources/29-web2py-english/13.markmin
+++ b/sources/29-web2py-english/13.markmin
@@ -1138,8 +1138,8 @@ An alternative to Memcache is use Redis. ``Redis``:inxx
Assuming we have Redis installed and running on localhost at port 6379, we can connect to it using the following code (in a model):
-``
-from gluon.contrib.redis import RedisCache
@rif
rif / gobVSjson.go
Created March 2, 2012 11:01
Go vs JSON benchmark
package main
import (
"bytes"
"encoding/gob"
"encoding/json"
"testing"
"time"
)
import json, socket, itertools
class JSONClient(object):
socket = None
def __init__(self, addr):
self.socket = socket.create_connection(addr)
self.id_counter = itertools.count()
def __del__(self):
if self.socket is not None:
self.socket.close()
@rif
rif / gist:3b98d7a18b39963a22a3
Last active August 29, 2015 14:14
Preffered tools