Skip to content

Instantly share code, notes, and snippets.

@pgrm
pgrm / save-vms.sh
Created December 4, 2013 11:45
Automatically saves the state of all running KVM guests when the system is shut down put into /etc/init.d and reference from /etc/rc0.d and name it with a prefix which makes it execute before any of the other scripts (for instance K01)
#! /bin/sh
suspend_vms () {
for output in $(virsh list --state-running --uuid)
do
exec virsh managedsave $output --bypass-cache
done
}
case "$1" in
@pgrm
pgrm / HandlingBookmarksWithOpenXML.cs
Created February 26, 2013 00:42
How to work with bookmarks in Word OpenXML
/*** EXTENSTION METHODS START ***/
public static T GetFirstDescendant<T>(this OpenXmlElement parent) where T : OpenXmlElement
{
var descendants = parent.Descendants<T>();
if (descendants != null)
return descendants.FirstOrDefault();
else
return null;
@pgrm
pgrm / gist:4263803
Created December 12, 2012 00:37
MPI Error
[root@CentOS src]# make run_mpi
mpicc -o sw.o smith_waterman.c
mpiexec -np 1 ./sw.o ../input_data/sequence1.dat ../input_data/sequence2.dat ../input_data/data.score -1
argv[0] = ./sw.o
argv[1] = ../input_data/sequence1.dat
argv[2] = ../input_data/sequence2.dat
argv[3] = ../input_data/data.score
argv[4] = -1
./sw.o: invalid option -- '1'
PAM file empty
@pgrm
pgrm / smithWaterman.c
Created November 22, 2012 11:34
AMPP Full Code
/*-------------------------------------------------------------
Copyright (C) 2000 Peter Clote.
All Rights Reserved.
Permission to use, copy, modify, and distribute this
software and its documentation for NON-COMMERCIAL purposes
and without fee is hereby granted provided that this
copyright notice appears in all copies.
@pgrm
pgrm / gist:4130686
Created November 22, 2012 11:29
AMPP - weired max
max=MAX3(diag,down,right);
if (max <= 0) {
h[i][j]=0;
xTraceback[i][j]=-1;
yTraceback[i][j]=-1;
// these values already -1
}
else if (max == diag) {
h[i][j]=diag;
xTraceback[i][j]=i-1;
@pgrm
pgrm / gist:4130672
Created November 22, 2012 11:25
AMPP - crappy loop
do {
ch = fgetc(in1);
if ( ch == EOF ) break;
LOOP1: if ( ch == 10 || ch == 13 ) {
// newline or carriage return
ch = fgetc(in1);
if ( ch == EOF ) break;
goto LOOP1;
}
// Bad style with 'goto', but then
@pgrm
pgrm / SimpleCsvLoader.cs
Created October 20, 2012 15:03
Simple CSV Loader first version
using System;
using System.Collections.Generic;
using System.IO;
namespace SimpleCsvLoader
{
public class CsvLoader
{
private char _delimiter;
private string _fileName;
@pgrm
pgrm / Sudoku.hs
Created October 20, 2012 01:56
Haskell Sudoku Solver
import Data.List
--2)
type Row = [Integer]
type Sudoku = [Row]
data Variant = Basic | Cross | Color deriving (Eq,Show)
isRowValid :: Row -> Bool