Skip to content

Instantly share code, notes, and snippets.

View nicdoye's full-sized avatar
🚲
All shall be well, and all shall be well, and all manner of thing shall be well

Nic Doye nicdoye

🚲
All shall be well, and all shall be well, and all manner of thing shall be well
View GitHub Profile
@nicdoye
nicdoye / how-many-steps.pl
Created January 30, 2016 12:15
Solution to question 9.1 in @gayle's "Cracking the Coding Interview" 5th ed. Child/stairs/combinations-of-steps.
#!/usr/bin/env perl
# Solution to a question in @gayle's "Cracking the Coding Interview" 5th ed.
# A child is running up the stairs and can take 1, 2 or 3 steps at a time.
# Count how many possible ways the child can run up the stairs.
use strict;
use warnings;
use Data::Dumper;
use feature qw/ say /;
@nicdoye
nicdoye / quicksort.pl
Created January 27, 2016 21:14
Quicksort in Perl using Sedgewick's Medians and what I thought was an original algorithm, but turns out to be called "fat partitions" and was in Version 7 UNIX's qsort
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
########################################################################
package QS;
@nicdoye
nicdoye / count-words.pl
Last active January 24, 2016 17:38
Perl (MOOSE) solution to the "find 3 most frequent words in a file"
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say switch);
######################################################################
package HashOfHash;
use Moose;
@nicdoye
nicdoye / 7z-release.sh
Created November 13, 2015 10:38
7zip but exclude .git (Simples, but I don't use it that often).
#!/bin/bash
7z a -x'!*/.git' $1.7z $1
@nicdoye
nicdoye / perl-find.sh
Created October 3, 2015 13:24
Find all .pm files (in /usr/*/perl5)
#!/bin/bash
# I know it's a bit stupid and there's better ways to do it. But who doesn't like playing.
# Written for an old CentOS 4 server where people have installed Perl modules any old how.
# Is there a way to merge the two matches together?
find /usr/*/perl5 | ruby -ne '/^(\/\w+){4}\/.*\.pm/.match($_) && puts( /^(\/\w+){4}\/[\.\d]*\/{0,1}(.*)/.match($_)[2] )'
@nicdoye
nicdoye / pidfile-checker.sh
Created June 27, 2014 16:50
Simple shell script for monit to check if a lock file (containing a pid) has been left hanging around for a process that is not a daemon.
#!/bin/bash
. /lib/lsb/init-functions
pidofproc "$@" &>> /dev/null
retval=$?
# Ignore cases such as retval=3 (Pid file doesn't exist)
if [ $retval -ne 1 ]
@nicdoye
nicdoye / csvwriter.groovy
Created November 29, 2013 17:52
Quick example of using Apache Commons CSV (1.0-Snapshot) to write to a CSV file in groovy.
import org.apache.commons.csv.CSVPrinter
import org.apache.commons.csv.CSVFormat
CSVPrinter printer = new CSVPrinter(
new PrintWriter("test.csv"),
CSVFormat.DEFAULT
)
answer = [ [5,6,"asdf",7],[9,10,"a b","z,x",12]]
@nicdoye
nicdoye / fill_disk.sh
Created September 16, 2013 12:17
Gradually (nearly) fill a disk. Using it to test monit rules. Obviously on a real box, with other users, the disk could fill up. Caveat user.
#!/bin/bash
mountpoint=/tmp
sleeper=240
# percentage of disk used
function percentage { df $1 | tail -1 | awk '{print $4}' | tr -d % ; }
# Where we'll write
tempdir=$(mktemp -d --tmpdir=${mountpoint})
@nicdoye
nicdoye / mounts2monit.rb
Created August 30, 2013 14:45
Create basic monit config files from /proc/mounts
#!/usr/bin/env ruby
# Linux only, sorry.
#
# Look for ext[34], xfs and vxfs. Alter the regexp FILESYSTEMS for others
#
# If you have /root as a separate partition, alter the value of ROOT_USABLE
# Config
@nicdoye
nicdoye / Designer.cs
Created July 26, 2013 13:06
How to open BusinessObjects Designer XI R3.1 in C#. This is if you add Interop.DesignerX12 as a reference. If you use Interop.Designer, the package namespace is "Designer" not "DesignerX12".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesignerTest
{
class Program
{