Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
jhthorsen / cloudinary.pl
Created July 14, 2012 16:17
cloudinary lite app
use Mojolicious::Lite;
# the params can be found at https://cloudinary.com/console
plugin cloudinary => {
api_key => '1234567890',
api_secret => 'your-super-s3cret',
cloud_name => 'your_cloud_name',
};
# this need to be some sort of backend database
@jhthorsen
jhthorsen / svref_2object.pl
Created March 15, 2012 11:37
figure out sub name from code ref
my $obj = B::svref_2object($code);
my $name = $obj->GV->NAME;
my $pkg = $obj->GV->STASH->NAME;
warn "The method name is $pkg\::$name";
@jhthorsen
jhthorsen / post-receive
Created March 13, 2012 20:55
post-receive hook for git
#!/bin/sh
BACKUP=$GIT_DIR; # need to be first?
GIT_DIR="path/to/my/repo/.git";
while read oldrev newrev refname; do
BRANCH=$(echo $refname | cut -f3 -d/);
echo branch $BRANCH
if [ "x$BRANCH" = "xalien" ]; then
cd $GIT_DIR;
@jhthorsen
jhthorsen / autoinstalldeps.pm
Created February 16, 2012 23:51
A pice of code which automatically will install perl dependencies
use IO::Socket::INET; use File::Basename; use File::Path; BEGIN {
our $SOURCE = $ENV{'AUTO_INSTALL_DEPS_SOURCE'} || 'http://api.metacpan.org:80/source/%s';
our $LIB = "$ENV{'HOME'}/.perl5";
push @INC, $LIB, sub {
my($module) = $_[1] =~ /(.*)\.pm$/; $module =~ s!/!::!g;
my($hostname) = $SOURCE =~ m!//([^/]+)!;
my $s = IO::Socket::INET->new(PeerAddr => $hostname) or die "Cannot download required library from $hostname: $@";
File::Path::make_path(dirname "$LIB/$_[1]");
open my $FH, '+>', "$LIB/$_[1]" or die "Write $LIB/$_[1]: $!";
printf STDERR "GET $SOURCE HTTP/1.1\n", $module if $ENV{'AUTO_INSTALL_DEPS_DEBUG'};
@jhthorsen
jhthorsen / goto_RETURN.pl
Created December 1, 2011 08:50
return from inside sub{}
#!/usr/bin/env perl
use strict;
use warnings;
sub foo {
my $res = '';
warn "foo(): @_";
(sub {
@jhthorsen
jhthorsen / SugarTree.pm
Created September 21, 2011 16:53
Example of how to export sugar
package SugarTree;
=head1 NAME
SugarTree - Create datastructures with sugar
=head1 SYNOPSIS
use SugarTree;