Skip to content

Instantly share code, notes, and snippets.

@semifor
semifor / anniversaries-query.md
Last active July 19, 2024 15:01
Selecting anniversary dates in a query given the original event date

Selecting anniversary dates in a query given the original event date

I wrote a dataview query to display upcoming birthdays and another for upcoming event anniversaries. Selecting anniversary dates within a range is an interesting problem.

  1. subtract event date from today to get the difference in years.
  2. Take the ceiling to get whole years.
  3. Add it to the event date to get the next anniversary that is on or after the current date.
  4. Test that date to see if it is in range.

Here's a snippet in dataview's query language.

@semifor
semifor / chunked-media-upload.pl
Created June 3, 2021 21:10
Chunked media upload with Twitter::API
#!/usr/bin/env perl
use 5.14.1;
use warnings;
# Usage:
#
# chunked-media-upload [ --type=TYPE ] [ --category=CATEGORY ] FILENAME
use File::stat;
use Getopt::Long;
@semifor
semifor / gist:22e04b7dbe6e9ed16eabea7bfd6c5d37
Created April 23, 2021 15:30
Behold! The new and improved Twitter API v2 404: a 200 OK with errors in the response body.
200 OK
Cache-Control: no-cache, no-store, max-age=0
Date: Fri, 23 Apr 2021 15:01:18 GMT
Server: tsa_a
Content-Length: 263
Content-Type: application/json; charset=utf-8
Content-Disposition: attachment; filename=json.json
Set-Cookie: personalization_id="v1_JE0Wf+QnkgraRUU2FloMsw=="; Max-Age=63072000; Expires=Sun, 23 Apr 2023 15:01:18 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
Set-Cookie: guest_id=v1%3A161919007878889378; Max-Age=63072000; Expires=Sun, 23 Apr 2023 15:01:18 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
Strict-Transport-Security: max-age=631138519
@semifor
semifor / gist:a99a7180c881fb59a9219df4917cea33
Created April 19, 2021 22:54
How do you enable postderef in the debugger?
$ perl -d
Loading DB routines from perl5db.pl version 1.49
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
use 5.22.1;
use warnings;
use feature 'postderef';
# Snippet demonstrating how to post a direct message with an attached image
# using the new Twitter direct message API
# First upload the image
my $media = $client->upload_media({
media => [ $image_path_name ],
media_category => 'dm_image'
});
# Attach the image in message_data
#!/usr/bin/env perl -d
use 5.22.0;
use Getopt::Long;
use Twitter::API;
use open qw/:std :utf8/;
my @traits = qw/Enchilada/;
my $traits = '';
GetOptions(
@semifor
semifor / twitter-split-brain.md
Created March 1, 2017 17:57
Twitter split brain problem: @fellythemozzer / @WhiteHouse relationship

tsa_b request/response: @fellythemozzer follows @WhiteHouse

GET https://api.twitter.com/1.1/friendships/show.json?source_screen_name=fellythemozzer&target_screen_name=WhiteHouse
Accept: application/json
Authorization: OAuth <elided>
User-Agent: Twitter-API/0.0109 (Perl)
Content-Type: application/json;charset=utf8
X-Twitter-Client: Twitter-API/0.0109 (Perl)
X-Twitter-Client-Url: https://github.com/semifor/Twitter-API

@realdDonaldTrump's un-follows

This is a least of accounts Donald Trump has un-followed since 2016-01-15 when I started tracking his account. Recently, he has re-followed. The final column shows whether or not he is currently following the account (as of 2017-02-14).

Data from Followerwonk.

screen name un-followed currently following
Reince 2017-02-02 yes
#!/usr/bin/env perl
# ABSTRACT: Post a tweet storm to Twitter
#
# Copyright (c) 2017 by Marc Mims
# This is free software, licensed under The MIT (X11) License
use 5.14.0;
use warnings;
use open qw/:utf8 :std/;
use Data::Dump qw/dump/;
use Getopt::Long;
#!/usr/bin/env perl
# ABSTRACT: Twitter API CLI
# Examples:
#
# twitter-api verify_credentials
# twitter-api --screen_name=semifor show_user
# twitter-api update 'current status: hackking'
#
# You can use get and post, to: