Skip to content

Instantly share code, notes, and snippets.

@vividsnow
vividsnow / soundcloud-term
Created Nov 30, 2021
terminal app to soundcloud personal stream (play, pause, forward, like, unlike, open in browser..). uses mpv
View soundcloud-term
#!/usr/bin/env perl
use utf8; use strict; use warnings;
use Getopt::Std 'getopt';
use HTTP::Tiny; use JSON::PP;
use IO::Uncompress::Gunzip 'gunzip';
use Socket qw'AF_UNIX SOCK_STREAM PF_UNSPEC';
use List::Util qw'min max';
use Encode::Locale;
use POSIX 'setsid';
View share-via-nginx
#!/usr/bin/env perl
use strict; use utf8; use warnings; use autodie ':all';
use File::Temp qw'tempfile tempdir';
use Getopt::Std 'getopts';
use Cwd 'cwd';
use File::Spec::Functions qw'catfile rel2abs';
my %o = (qw'l 0:4321 -d', cwd);
getopts 'l:d:u:p:h', \%o;
@vividsnow
vividsnow / debootstrap.md
Created Jun 26, 2018 — forked from tr3buchet/debootstrap.md
debian usb debootstrap
View debootstrap.md

make sure any needed utilities are installed

sudo aptitude install debootstrap coreutils util-linux e2fsprogs

get usb device

df -h
@vividsnow
vividsnow / rounded.pl
Created Jul 27, 2017
imager rounded corner mask with transparency
View rounded.pl
sub rounded_mask {
my ($img, $rad) = @_;
state $ss = 4; # subsample smooth
my $srad = int $rad*$ss;
my $corner = Imager->new(xsize => $srad, ysize => $srad, channels => 1)
->arc(qw'x 0 y 0 d1 0 d2 90', r => $srad - $ss/2)
->scale(scalefactor => 1/$ss);
my ($w, $h) = ($img->getwidth, $img->getheight);
my $mask = Imager->new(xsize => $w, ysize => $h, channels => 1);
$mask->box(box => [$rad, 0, $w - 1 - $rad, $h - 1], filled => 1);
@vividsnow
vividsnow / torium.pl
Last active Oct 9, 2017
multiple tor runner
View torium.pl
use strict; use warnings;
use File::Temp qw'tempfile tempdir'; use File::Spec::Functions 'catfile';
use Symbol 'geniosym'; use Socket; use Net::EmptyPort 'empty_port'; use Getopt::Std;
my %in = (qw'h 127.0.0.1 p 5498 n 4'); getopts('p:n:', \%in);
print "torium[$$] listens $in{p}\n";
my @children;
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 / desktop-load-theme.el
Created May 27, 2015
emacs load-theme desktop-mode
View desktop-load-theme.el
(desktop-save-mode)
(add-to-list 'desktop-globals-to-save 'custom-enabled-themes)
(defun desktop-load-theme () "load custom theme" (interactive)
(dolist (th custom-enabled-themes) (load-theme th)))
(add-hook 'desktop-after-read-hook 'desktop-load-theme)
@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}
@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 / 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 }'