View export_pdf_layers_as_png.py
#!/usr/bin/env python
#
# Author: helour
# Copyright: 2013-2015 helour
# Based on the cr33dog's script Export Layers as PNG (http://registry.gimp.org/node/18440)
# License: GPL v3+
#
# Version: 0.7
#
# GIMP plugin to export layers as a multiple pages PDF file
View pQuery.js
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
View fold-long-lines.c
// This was my attempt at K&R 1-22
// Though, this implementation has a bug wherein the last word of a short line is always printed on its own line. This is because
// there's currently no way for the program to know when the "split" word would fit on the current line.
// This solution is nice because it will work with arbitrarily long lines.
// The lines are read-in (80 chars or less at a time), the last space is sniffed out, then the last word is split,
// a newline is printed, and the "split" word is printed. On the next loop, the get_line function ends N chars from
// the line break, in order to acommodate the "split" word which has already been printed on the current line.
#include <stdio.h>
View copy_s3_objects_from_one_bucket_to_another.rb
# inspired by: https://gist.github.com/dje/763977
def copy(source_bucket:, destination_bucket:, files:, connection:)
files.each_with_index { |file, index|
puts "copy #{file['Key']} to #{destination_bucket}" if index % 20 == 0
connection.copy_object source_bucket,
file['Key'],
destination_bucket,
file['Key']
}
View fizzbuzz.c
#include <stdio.h>
int main(void) {
int i;
for (i = 1; i <= 100; ++i) {
if (i % 3 == 0 && i % 5 == 0) {
printf("fizzbuzz\n");
} else if (i % 3 == 0) {
printf("fizz\n");
} else if (i % 5 == 0) {
View gist:abdd5f43da4c128612a0d99f93990b77
In which I attempt to answer the question, "How/why are generics useful?"
reverse :: [a] -> [a]
-- reverse can operate on _any_ list: Int, Float, Bool, MyCustomTypeClass.
-- The alternative would be writing a reverse variant for every type:
intListReverse :: [Int] -> [Int]
charListReverse :: [Char] -> [Char]
sort :: Ord => [a] -> [a]
-- sort can operate on _any_ list which is an instance of Ord: Int, Float, Bool, MyCustomTypeClass
View csv-to-hash.rb
SOMETHING = ENV['CSV'].
split(/,/).
each_slice(2).
inject({}) { |memo, (key, value)|
memo[key] = value
memo
}
View compose.rkt
(define (count-zeros lst)
((compose length
(curry filter zero?)
flatten)
lst))
(count-zeros '(0 0 (1 (1 (0 0) 0)) (1 0 0))) ;; 7
View parser.hs
import Control.Applicative
import Data.Char
newtype Parser a = P (String -> [(a, String)])
instance Functor Parser where
fmap g p = P (\inp -> case parse p inp of
[] -> []
[(v, out)] -> [(g v, out)])