Skip to content

Instantly share code, notes, and snippets.

@fracai
fracai / compact.rb
Last active August 29, 2015 14:04
A nanoc filter for stripping blank lines and extraneous whitespace.
module Nanoc::Filters
class Compact < Nanoc::Filter
identifier :compact
def run(content, params={})
count_pre = 0
content.split("\n").each do |line|
line << "\n"
@fracai
fracai / strip_blank_lines.rb
Created July 19, 2014 02:44
A nanoc filter for stripping blank lines.
module Nanoc::Filters
class StripBlankLines < Nanoc::Filter
identifier :strip_blank_lines
def run(content, params={})
count_pre = 0
content.split("\n").each do |line|
line << "\n"
@fracai
fracai / dropbox-diet.pl
Created January 30, 2011 05:17
Another, slightly faster, solution to "Dropbox Diet" from http://www.dropbox.com/jobs/challenges
#!/usr/bin/env perl
use strict;
use warnings;
my %exercise = ();
my %food = ();
my $lines = 0;
foreach my $line (<>) {
@fracai
fracai / dropbox-diet.pl
Created January 30, 2011 05:15
An OK solution to "Dropbox Diet" from http://www.dropbox.com/jobs/challenges
#!/usr/bin/env perl
use strict;
use warnings;
my %options = ();
my $lines = 0;
foreach my $line (<>) {
if ($line =~ m/^(\d+)$/) {
@fracai
fracai / dropbox-diet.pl
Created January 31, 2011 02:18
A further solution to "Dropbox Diet" from http://www.dropbox.com/jobs/challenges This one performs much better with larger inputs by processing smaller combinations before larger.
#!/usr/bin/env perl
use strict;
use warnings;
my %exercise = ();
my %food = ();
my $lines = 0;
# read food and exercise options into separate lists based on positive or negative calories
@fracai
fracai / dropbox-diet.txt
Created January 31, 2011 02:27
Randomly generated input file for testing "Dropbox Diet" from http://www.dropbox.com/jobs/challenges
50
6281bcff234f72bb2bf8ebb0575bd0fc 869
787ae8bec3e969890c6ab9a2061e946d 368
63ab56237cf06355a97a5c140f98513b 381
5d8e0fee7e629219b7bacec3ea23e47f 394
768057f7fa934c62b95bb6a54f43086f -407
ecfa420b7732dfe6b0a260b5230efa83 -906
d5ff040a4be1853067ff6691f18d2c74 -919
572b27bc3adbf698c92d5598b0a2e15f -932
a75d5a4a253a379eb738e3656c3a5970 945
@fracai
fracai / obfuscate_mail.rb
Created February 17, 2011 01:24
An email obfuscation filter for nanoc. It should find and hide all links in the form of: <a href="mailto:"></a>
module Nanoc3::Filters
class ObfuscateMail < Nanoc3::Filter
identifier :obfuscate_mail
require 'digest/sha1'
def run(content, params={})
link_count=0
@fracai
fracai / mlength.pl
Created July 6, 2011 19:28
Parse the length of media files using mplayer
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
use Getopt::Long;
my ($human, $help, $sum);
my $result = GetOptions(
@fracai
fracai / gist:1102728
Created July 24, 2011 15:29
nanoc snippet for calculating "true" page parents
def output_parent(page)
nil == page and return nil
page[:x_parent] and return page[:x_parent]
(page.identifier == '/' or page.binary? or page[:is_hidden]) and return page[:x_parent] = nil
path = page.path.gsub(/[^\/]*$/,'')
@items.sort_by{ |i| i.path.count('/') }.reverse.each do |i|
(i == page or i.binary? or i[:is_hidden]) and next
if path =~ /^#{i.path.gsub(/[^\/]+$/,'')}/
@fracai
fracai / relationships.rb
Created August 8, 2011 22:05
nanoc helper for building path based relationshiips
module Nanoc3::Helpers
module Relationships
extend Nanoc3::Memoization
def output_parent(page)
nil == page and return nil
(page.identifier == '/' or page.binary? or page[:is_hidden]) and return nil