Skip to content

Instantly share code, notes, and snippets.

@omerk
omerk / spotify_playing.sh
Created October 3, 2011 16:32
Spotify 'Now Playing'
#!/bin/bash
pgrep spotify 1>/dev/null 2>&1
if [ $? != 0 ]; then
exit 1
fi
xwininfo -root -tree | grep "Spotify -" | sed 's/[ ]*0x[0-9a-f]* "Spotify - \(.*\)": ("spotify" "Spotify").*/\1/'
@omerk
omerk / gist:2385330
Created April 14, 2012 15:47
Raspberry-Pi Unixbench Score
pi@raspberrypi:~/UnixBench$ ./Run
make all
make[1]: Entering directory `/home/pi/UnixBench'
Checking distribution of files
./pgms exists
./src exists
./testdir exists
./tmp exists
./results exists
make[1]: Leaving directory `/home/pi/UnixBench'
@omerk
omerk / gist:3380077
Created August 17, 2012 15:51
C function pointer demo
#include <stdio.h>
int add(int a, int b)
{
return a + b;
}
int addtimestwo(int (*fp)(int,int), int a, int b)
{
return (*fp)(a, b) * 2;
@omerk
omerk / gist:4645120
Last active December 11, 2015 18:58
Playing with the ADC on a PIC10F222
#include <xc.h>
#include <stdint.h>
#define _XTAL_FREQ 4000000 // required for __delay_ms()
#define DELAY 1000
#define THRESHOLD 100
#pragma config MCLRE=OFF, MCPU=OFF, CP=OFF, WDTE=OFF, IOSCFS=4MHZ
void
@omerk
omerk / gist:5061474
Last active December 14, 2015 08:59
pdfextract ()
{
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] ; then
echo "Usage: pdfextract <source doc> <first page> <last page>."
else
OUTPDF=$1_p$2-$3.pdf
pdftops $1 - | psselect -p$2-$3 | ps2pdf14 - $OUTPDF
echo "Output saved as: $OUTPDF"
fi
}
#include <stdio.h>
int
main (void)
{
FILE *f;
char name[255];
if( !(f = popen("uname -n", "r")) ){
perror("Can't execute cmd");
@omerk
omerk / gist:5162182
Created March 14, 2013 15:15
strtok() example
#include <stdio.h>
#include <string.h>
int
main (void) {
char test_string[] = "machinename.local";
char* result = NULL;
result = strtok(test_string, ".");
CFLAGS=-Wall -pedantic
SRC=$(wildcard *.c)
OBJ=$(SRC:.c=.o)
BIN=$(SRC:.c=)
all: $(BIN)
clean:
$(RM) $(OBJ) $(BIN)
@omerk
omerk / program.cs
Created July 7, 2013 12:00
Detect hardware changes using WMI
using System;
using System.Management;
namespace WMIDeviceChangeDetect
{
public class WMIDeviceChangeDetect
{
private static void HandleEvent(object sender, EventArrivedEventArgs e)
{