Skip to content

Instantly share code, notes, and snippets.

@macieksk
macieksk / parallelListDB.py
Created March 16, 2011 03:52
multiprocessing, threading, pool, with access to db, web2py, parallel list process with example
#import threading
from multiprocessing import Process,Queue,Pool
from gluon.shell import exec_environment
def parallelListDB(fun, lst, nthreads=2, request=None,
timeout=10, aggregate = lambda lst: it.chain(*lst)):
assert request!=None
q=Queue()
@macieksk
macieksk / dmesg_time.sh
Created July 26, 2011 12:38
dmesg messages time retrieval (hours or minutes ago)
#!/bin/bash
#Usage: dmesg | grep eth3 | dmesg_time.sh
for time in $(egrep -o '[0-9]+\.[0-9]+')
do
TIME="`echo "($(awk '{print $1}' /proc/uptime) - $time) / 60 / 60" | bc`h" # Hours
TIME="$TIME or `echo "($(awk '{print $1}' /proc/uptime) - $time) / 60" | bc`m" # Minutes
echo "$TIME ago"
done
@macieksk
macieksk / fixpaths.sh
Created January 17, 2012 15:45
Fix paths for Sage 4.7.2 binary build so that one can install new packages in R
# To be run inside main sage-4.7.2 dir or alike
# Files TOFIX are usually those:
# local/bin/R local/lib/R/bin/libtool local/lib/R/bin/R local/lib/R/etc/ldpaths local/lib/R/etc/Makeconf local/lib/R/etc/Renviron
#Change here for different versions of sage
ORGPATH="/mnt/usb1/scratch/buildbot/sage/sage-1/sage_binary/build/sage-4.7.2"
DIR=`pwd`
SED="s|$ORGPATH|$DIR|g"
TOFIX=`grep -lI $ORGPATH -R local/ | grep /R`
@macieksk
macieksk / uniquequeue.py
Last active August 5, 2023 02:54
Unique Priority Queue based on the PriorityQueue class. These priority queues accept tuples as input, where first component is a priority, second component is a key, which is used to identify unique values, third and all further component(s) is an (optional) value.
# -*- coding: utf-8 -*-
#Unique priority queues in Python
#@author: "Maciek Sykulski"<macieksk@gmail.com>
#@blog: http://breakthecircles.blogspot.com/2013/10/unique-priority-queues-in-python.html
from Queue import PriorityQueue
import heapq
class UniquePriorityQueue(PriorityQueue):
@macieksk
macieksk / 0_reuse_code.js
Created June 6, 2014 14:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@macieksk
macieksk / click_onclick_elem_extract_data.js
Created June 6, 2014 16:52
jquery onclick click, data extraction, replace, join, map
$('a').filter(function(){
return $(this).text() === 'Display Full Polymer Details';
})
.click()
$("span.se_key").filter(function(){ return $(this).text().match(' Gene Name[s]* ');})
.parent().siblings("td.mdauData")
.map(function(){return $(this).parents("tbody.query").find("a.qrb_structid").text()
+","
+$(this).text().trim().replace(/\s+/g,",");})
@macieksk
macieksk / download_reddit_saved_links.py
Created June 6, 2014 20:26
Download csv, json with your reddit saved links.
@macieksk
macieksk / kdegrid.sh
Last active December 1, 2020 14:13
Grid window placement in KDE, Plasma. To use create appropriate keyboard shortcuts to KDE and enjoy quick window placement. Originally created by Anpu and posted on KDE forum https://forum.kde.org/viewtopic.php?f=111&t=108024
#!/bin/bash
# number of monitors
MONITORS=`xrandr | grep -w connected | wc -l`
# make a gap because of top panel
GAP_TOP=0
GAP_BOTTOM=15
#find x position of active window
@macieksk
macieksk / background.multicore.r
Created June 16, 2014 09:36
R CRAN code. Parallel execution - helper functions for the "multicore" library. Run jobs (expressions) in the background without blocking. Consider using "source.gist" http://cran.r-project.org/web/packages/source.gist/index.html
################
################ Parallel execution - helper functions for multicore library
################ Run jobs (expressions) in the background without blocking
################
library(multicore) #better to be loaded last of all libraries
inpar<-function(name,expr){
#Runs named expression in parallel with main thread - non-blocking
name<-deparse(substitute(name))
@macieksk
macieksk / google_drive_util.py
Created July 2, 2014 12:26
A simple Python module to upload files to Google Drive file upload. Needs a file 'client_secrets.json' in the directory . The file can be obtained from https://console.developers.google.com/ -- under APIs&Auth/Credentials/Create Client ID for native application
## Simple Python module to upload files to Google Drive
# Needs a file 'client_secrets.json' in the directory
# The file can be obtained from https://console.developers.google.com/
# under APIs&Auth/Credentials/Create Client ID for native application
# To test usage:
# import google_drive_util
# google_drive_util.login()
# google_drive_util.test()