Skip to content

Instantly share code, notes, and snippets.

View retrography's full-sized avatar

Mahmood S. Zargar retrography

  • VU Amsterdam
  • Amsterdam, Netherlands
  • X @mszargar
View GitHub Profile
@retrography
retrography / rogue-killer.sh
Last active October 24, 2018 12:27
Assesses the most CPU-intensive (keeping at least one core busy at 100%) processes repetitively over a period of one second, and kills the process that comes on top.
#!/bin/bash
declare -a pids
for i in {1..10}
do
toptask=$(ps -eo pcpu=,pid= | sed 's/^ *//' | tr -s ' ' '\t' | sort -grk1 | head -1)
cpu=$(echo $toptask | tr -s ' ' '\t' | cut -f1 | cut -d. -f1)
pid=$(echo $toptask | tr -s ' ' '\t' | cut -f2)
if (( cpu > 100 )); then
@retrography
retrography / 00-intro.md
Created June 17, 2017 18:24 — forked from mdo/00-intro.md
Instructions for how to affix an Ikea Gerton table top to the Ikea Bekant sit-stand desk frame.

Ikea Bekant standing desk with Gerton table top

@retrography
retrography / class.patch
Last active March 22, 2017 12:19
Little mod in RJDBC to allow OrientDB connections
--- RJDBC0.2-6/R/class.R 2017-02-07 21:38:59.000000000 +0100
+++ RJDBC0.2-6mod/R/class.R 2017-03-22 02:39:42.000000000 +0100
@@ -37,18 +37,12 @@
setMethod("dbUnloadDriver", "JDBCDriver", def=function(drv, ...) FALSE)
setMethod("dbConnect", "JDBCDriver", def=function(drv, url, user='', password='', ...) {
- jc <- .jcall("java/sql/DriverManager","Ljava/sql/Connection;","getConnection", as.character(url)[1], as.character(user)[1], as.character(password)[1], check=FALSE)
- if (is.jnull(jc) && !is.jnull(drv@jdrv)) {
- # ok one reason for this to fail is its interaction with rJava's
- # class loader. In that case we try to load the driver directly.
@retrography
retrography / cuer.py
Last active August 2, 2019 10:33
Create cue sheet for a list of id3-tagged audio files
#!/usr/bin/env python3
from sys import argv
from mediafile import MediaFile
def main():
args = argv[1:]
first_file = True
@retrography
retrography / letterspace_export.rb
Created May 31, 2016 04:49
Exports notes from LetterSpace and imports them into SimpleNote using SimpleNote CLI (sncli)
#!/usr/bin/env ruby
require 'json'
Dir.glob(ARGV).each do |fname|
note = {}
note['createdate']=File.ctime(fname).to_f
note['modifydate']=File.mtime(fname).to_f
f=File.read(fname)
note['content']=f.gsub(/(#|@)([0-9a-zA-Z_\-]+)/,'\2')
@retrography
retrography / extract.rb
Created May 15, 2016 01:52 — forked from danlucraft/extract.rb
Extract annotations from PDFs with pdf-reader gem
require 'pdf-reader'
require './markup_receiver'
doc = PDF::Reader.new(ARGV[0])
$objects = doc.objects
def is_note?(object)
object[:Type] == :Annot && [:Text, :FreeText].include?(object[:Subtype])
end
@retrography
retrography / tree_clean.sh
Created May 9, 2016 13:49
Data conversion / cleaning for Montreal trees data: http://donnees.ville.montreal.qc.ca/dataset/arbres
#!/bin/sh
# This is an example ran on Cote des Neiges data
# Fix text encoding
iconv -f WINDOWS-1252 -t UTF-8 Cote_des_Neiges_Notre_Dame_de_Grace_Arbres_publics_2015_12_02.csv > cdn.csv
# Remove spaces
sed -i -r 's/ +/ /g' cdn.csv
# Convert to tab-delimited
q -d ";" -T "select * from cdn.csv" > cdnfinal.csv
@retrography
retrography / stackedit-csv-extension.js
Last active May 6, 2016 11:38
User custom extension for Stackedit that converts CSV/TSVs in code fences into Markdown tables
userCustom.onPagedownConfigure = function(editor) {
var converter = editor.getConverter();
function csvToMarkdown( csvContent, delimiter, hasHeader ) {
if( delimiter != "\t" ) {
csvContent = csvContent.replace(/\t/g, " ");
}
var columns = csvContent.split("\n");
var tabularData = [];
@retrography
retrography / scheme.applescript
Last active January 24, 2025 13:15
Apply a color preset to the current iTerm session from command prompt
#!/usr/bin/osascript
-- Copyright © 2016, Mahmood Shafeie Zargar all rights reserved
-- This program is released under the terms of MIT License
-- Sort routine from http://www.macosxautomation.com/applescript/sbrt/sbrt-05.html
on run argv
try
set argument to item 1 of argv
on error
import objc
import AddressBook as ab
import pprint as pp
def pythonize(objc_obj):
if isinstance(objc_obj, objc.pyobjc_unicode):
return unicode(objc_obj)
elif isinstance(objc_obj, ab.NSDate):
return objc_obj.description()