Skip to content

Instantly share code, notes, and snippets.

@Makistos
Makistos / parse_change_files.sh
Created October 25, 2013 12:39
This script goes through .change files in the current directory and copies all the files listed to a different directory. It skips the _sources.change files as well. The obvious use is to copy the files so we can use "reprepro processincoming" to save packages to a repository.There are probably smarter ways to do this, but this is pretty portabl…
#/bin/sh
for CHANGEFILE in *.changes;
do
str=`echo $CHANGEFILE | grep -v "source.changes"`
if [ -z "$str" ]; then
continue
fi
found="0"
while read line
do
@Makistos
Makistos / find_alsa_devices.c
Last active December 26, 2015 12:49
This script finds out ALSA devices in Linux programatically, which can be a bit tricky. #alsa #device-driver #linux #c
/**
* Reads audio devices from ALSA interface and returns count and array of
* strings containing the devices.
*
* @param[out] count Number of devices found.
* @param[out] Array of strings containing the device names.
*
*/
static void getALSADevices(int *count, char **devices)
{
@Makistos
Makistos / unhash_gitorious_paths.rb
Created October 25, 2013 12:42
The Gitorious repository hosting service, which you can install on your own server, hashes the Git repositories which makes it hard to link to them from other services. This script creates more readable links to those repositories. #git #gitorious #ruby #scm
#!/usr/bin/ruby -d
####
#
# create_unhashed_links.rb
#
# Creates links that are unhashed to the Gitorious repositories.
# Helps link the repositories to Redmine.
#
# Spaces in project names are replaced with underscores.
@Makistos
Makistos / perl_formatter_example.pl
Created October 25, 2013 12:43
This is an example on how the Perl formatter works. #perl-format #perl
#!/usr/bin/perl
# This script takes something like this as input:
# ID WorkId Date
# 1 2 12-10-2009
# 2 16 01-01-2008</pre>
# And prints out this:
#+-----+----------+---------------+
#|ID |WorkId |Date |
@Makistos
Makistos / hex_to_int.pl
Created October 25, 2013 12:45
This small script reads a memory dump that looks like 0x00 0xAB 0xFE 0x10 ... and converts it into 16 -254 171 0 ... I needed this to verify some code as I got two different outputs. Not only was the format different, endianess was as well. Converting from hex to int wasn't the problem, it was making Perl to understand that the values were signe…
#!/usr/bin/perl
my $byte_num = 0;
my @vals;
while(<>)
{
chomp;
$vals[$byte_num] = unpack('c', pack 's', hex($_));
$byte_num++;
@Makistos
Makistos / checkIsbn.java
Created October 28, 2013 07:35
This code will check both ISBN-10 and ISBN-13 codes for validity. String length, characters and check digit are checked. Java regexp class is used, so this is an example on how to use it, too. #isbn #regexp #java
import java.util.regex.*;
/**
* @brief This class is used to verify that input is a valid ISBN (International
* Standard Book Number).
*
* @note Invalid ISBN-13 codes have been published in books! Do not assume
* that just because this returns false for an existing ISBN, there is a bug.
* Verify with e.g. Amazon that the ISBN is correct first.
*
@Makistos
Makistos / Makefile-gdb
Created October 28, 2013 07:36
This makefile script will get applications compiled in such a way that you can use the gdb debugger with them. #gdb #linux #bash
CC = gcc
CCFLAGS = -Wall -ggdb3
VPATH = /usr/include/
OBJS = file1.o file2.o file3.o
%.o: %.c
${CC} ${CCFLAGS} -c $< hwcheck: ${OBJS} ${CC} ${CCFLAGS} ${OBJS} -o myapp clean: rm -f myapp *.o
@Makistos
Makistos / run_in_order.sh
Created October 28, 2013 07:37
This bash script will handle files in a directory and it's subdirectories in the order they were created. #bash #file-handling
for line in `find $WORK_DIR -maxdepth 1 -type f -printf '%f/%A@' | sort -k 2`
do
FILE=`echo $line | sed -r 's/^(.*)\/(.*)$/\2/'`
# Do what ever you want with the file
done
@Makistos
Makistos / num_has_chars.pl
Created October 28, 2013 07:45
Checks if a string has letters in it properly, i.e. all Unicode characters are considered letters. #regexp #unicode #perl
#!/usr/bin/perl
while (<>) {
if (/[\p{L}]+/) {
print "letters\n";
} else {
print "no letters\n";
}
}
@Makistos
Makistos / web_harvest.py
Created October 28, 2013 07:42
This is an example of how to traverse through web pages using Python services. #data-mining #web-harvest #python #urllib
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
from urllib import urlopen
import re
import sys
class PlayerSeasonInfo:
team = ''
league = ''