Skip to content

Instantly share code, notes, and snippets.

@xsawyerx
xsawyerx / remove.js
Created February 7, 2022 10:10
Remove all Twitter followers and likes
// These may take a bit to run, depending on how much you have,
// but you should be done by morning if you leave it over night with the right configuration
// Open Twitter profile likes page
// Copy paste the minified jquery straight into the console
// Adjust the interval and count as you wish
var count = 1;
var interval = setInterval( clearLikes, 600 );
function clearLikes() {
count++;
@xsawyerx
xsawyerx / With.pm
Created March 20, 2017 14:53
Dancer2::Plugin::With
package Dancer2::Plugin::With;
use strict;
use warnings;
use Dancer2::Plugin;
plugin_keywords( qw< add_with route_with > );
has 'with_reg' => (
'is' => 'ro',
@xsawyerx
xsawyerx / async-file-serving-without-send_file.pl
Last active January 5, 2017 12:47
Dancer2 asynchronous file serving without `send_file` with extra stuff
use Dancer2;
use Text::CSV_XS qw< csv >;
use Path::Tiny qw< path >;
use JSON::MaybeXS qw< encode_json >;
# Create a CSV parser
my $csv = Text::CSV_XS->new({
'binary' => 1,
'auto_diag' => 1,
});
.--------------------.
.---------| Dancer2::Core::App |-----------.------------.
| '--------------------' | |
| | | v
v | | .-----------------.
.--------------. | | | D2::C::Response |
| routes | | | '-----------------'
|--------------| | | .-----------------.
| D2::C::Route | | | | D2::C::Request |
use v5.10;
use MetaCPAN::API;
use Data::Dumper;
use List::AllUtils qw(min max);
use DateTime;
use DateTime::Format::ISO8601;
my @score_label = qw(
Abysmal
Poor
@xsawyerx
xsawyerx / MyApp.pm
Last active January 2, 2016 00:21
uri_for() with parameters
package MyApp;
use Carp;
use Dancer2;
my %routes;
sub uri_for_it {
my ( $name, $vars ) = @_;
my $route = $routes{$name};
my $route_path = $route->spec_route;
@xsawyerx
xsawyerx / recur_def_promise.pl
Last active December 14, 2015 21:39
Recursive deferred promises: sometimes you need to run a set of actions consecutively without knowing how many actions exist. An example would be running an arbitrary number of commands one after the other. You want to be able to add more commands to the array without having to add another explicit deferred promise. This code shows how to recurs…
use strict;
use warnings;
use AnyEvent;
use AnyEvent::HTTP;
use Promises 'deferred';
my @urls = ( 'https://ddg.gg', 'http://dyndns.org', 'http://metacpan.org' );
my $cv = AE::cv;
my $cb; $cb = sub {
@xsawyerx
xsawyerx / async_response.pl
Created October 31, 2012 14:31
using send_file for full non-blocking async fork w/ condvars
# this function lets you run code in a fork
# and use a condvar on it to get the data
# and return it to the client in JSON form, all non-blocking and async
# based heavily on a trick by Assaf Gordon
sub async_response (&) {
my $cb = shift;
send_file(
\'noop',
@xsawyerx
xsawyerx / datetime.pl
Created July 13, 2012 20:38
Finding Friday the 13th
use strict;
use warnings;
use DateTime;
my $dt = DateTime->new(
day => 13,
year => 2012,
);
my $count = 0;
@xsawyerx
xsawyerx / dancer1-design.txt
Created June 28, 2012 22:51
Dancer design graphs
.---------.
.----------.----------| Handler |--------.--------.
| | | '---------' | |
| | | | | |
| | | | | |
v v v '-> v v
.-----. .-----. .-----. .------------. .------. .-------.
| App | | App | | App | | Serializer | | Hook | | Route |
'-----' '-----' '-----' '------------' '------' '-------'