Skip to content

Instantly share code, notes, and snippets.

@vividsnow
vividsnow / gstreamer-video-test.pl
Created Apr 28, 2014
perl gstreamer-1.0 example
View gstreamer-video-test.pl
use v5.18;
use warnings;
use Glib qw(TRUE FALSE);
use Glib::Object::Introspection;
my $loop = Glib::MainLoop->new;
map { Glib::Object::Introspection->setup(basename => $_, version => '1.0', package => 'GStreamer') } qw'Gst GstBase';
GStreamer::init([$0, @ARGV]);
say 'GStreamer ', join '.', GStreamer::version();
@vividsnow
vividsnow / fold_wrap.pl
Last active Aug 29, 2015
integer value fold wrap in interval
View fold_wrap.pl
use strict; use warnings;
use feature 'say';
use List::MoreUtils 'minmax';
# usage: fold_wrap.pl 10 4 8
say "wrap: ".wrap(@ARGV);
say "fold: ".fold(@ARGV);
sub wrap {
use integer;
@vividsnow
vividsnow / test.sh
Created Aug 18, 2014
service static w/ user/pass via plack
View test.sh
cpanm U Plack
# later
plackup -MU -MPlack::Builder -e 'builder { enable "Auth::Basic", authenticator => sub {$_[0].$_[1] eq 'a0b0'}; Plack::App::Directory->new->to_app }'
@vividsnow
vividsnow / xlsx2mysql.pl
Last active Aug 29, 2015
XLSX to MySQL converter
View xlsx2mysql.pl
use strict; use warnings;
use feature qw'say state';
use File::Basename 'basename';
use Spreadsheet::XLSX;
use DBI;
use IO::Prompt::Tiny 'prompt';
use Getopt::Std 'getopt';
getopt(my $arg = 'hPupfd', my $opts = {qw(h localhost u root)}); # host user pass file ?db_name
my ($host, $port, $user, $pass, $file, $db_name) = @$opts{split'',$arg};
@vividsnow
vividsnow / http_tiny_gzip.pl
Last active Aug 29, 2015
HTTP::Tiny w/ gzip support
View http_tiny_gzip.pl
use utf8; use strict; use warnings; use feature qw'say state';
use URI; use HTTP::Tiny;
use IO::Uncompress::Gunzip 'gunzip';
say fetch('http://some-site');
sub fetch {
my $response = (state $ua = HTTP::Tiny->new(default_headers => {qw'Accept-Encoding gzip'}))->get(URI->new($_[0]));
say join '', ($response->{success} ? 'ok' : 'fail'), ': ', $_[0];
$response->{success} && length $response->{content}
View gtk3-filechoose.pl
use strict; use warnings;
use Gtk3 -init;
my $dialog = Gtk3::FileChooserDialog->new(
'Select files..', Gtk3::Window->new('toplevel'),
qw'open OK ok');
$dialog->set_select_multiple(Gtk3::true);
$dialog->signal_connect( response => sub {
@vividsnow
vividsnow / s3sync.pl
Created Jun 18, 2009
1-way synchronization of your files with S3 storage with auto minify *.css and *.js files and gzip text/* content
View s3sync.pl
#!/usr/bin/perl
# s3sync: 1-way synchronization of your files with S3 storage with auto minify *.css and *.js files and gzip text/* content
use Modern::Perl;
use Amazon::S3;
use Path::Class ();
use IO::Compress::Gzip qw(gzip $GzipError);
use File::MMagic;
use JavaScript::Minifier::XS;
@vividsnow
vividsnow / example.pl
Created Apr 19, 2011
Draft example of Template::Semantic usage
View example.pl
sub wrap {
my ($self, $data) = @_;
return $self->engine->process($self->path.'/layout.html', {
'//head' => {
'title' => $data->{title},
'./script[last()-1]' => @{$data->{js}}?[map { './@src' => '/js/'.$_.'.js' }, @{$data->{js}}]:undef,
'./link[last()]' => @{$data->{js}}?[map { './@href' => '/css/'.$_.'.css'}, @{$data->{css}}]:undef,
'./script[last()]' => $data->{jscode}?sub { $_ =~ s/\/\*code\*\//$data->{jscode}/; \$_ }:undef,
},
'//body' => {
@vividsnow
vividsnow / chat.html
Created May 14, 2011
SocketIO <=> PocketIO test app ( reqs: WebSocketMain.swf and socket.io.min.js from github.com/LearnBoost/Socket.IO )
View chat.html
<html>
<head>
<script type="application/x-javascript">
WEB_SOCKET_SWF_LOCATION = 'WebSocketMain.swf';
</script>
<script src="socket.io.min.js"></script>
<script src="//yandex.st/prototype/1.7.0.0/prototype.min.js"></script>
<script type="application/x-javascript">
Event.observe(document, 'dom:loaded', function (){
var socket = new io.Socket(window.location.hostname, {
View gist:1536353
#perl
use v5.12;
use CDF;
use Data::Dumper qw(Dumper);
my ($id, @out);
CDF::CDFopen($ARGV[0], \$id);
CDF::CDFinquire($id, refstd([( undef, [], (undef) x 5 )])); pout();