Skip to content

Instantly share code, notes, and snippets.

View jcipriano's full-sized avatar

Jonathan Cipriano jcipriano

View GitHub Profile
@jcipriano
jcipriano / add-subscription.js
Last active May 9, 2019 00:36
Creates a Twitter webhook config
var request = require('request')
// twitter authentication
var twitter_oauth = {
consumer_key: 'TWITTER_CONSUMER_KEY',
consumer_secret: 'TWITTER_CONSUMER_SECRET',
token: 'TWITTER_ACCESS_TOKEN',
token_secret: 'TWITTER_ACCESS_TOKEN_SECRET'
}
@jcipriano
jcipriano / media-upload.py
Last active July 12, 2024 03:04
Async Twitter media upload example script in python. Generates media ID for use with Tweets and DMs.
import os
import sys
import time
import json
import requests
from requests_oauthlib import OAuth1
MEDIA_ENDPOINT_URL = 'https://upload.twitter.com/1.1/media/upload.json'
@jcipriano
jcipriano / challenge-response.php
Created June 29, 2017 16:08
PHP example for generating challenge response for Twitter webhooks
<?php
// Example app consumer secret found in apps.twitter.com
const APP_CONSUMER_SECRET = 'z3ZX4v7mAAUGykl3EcmkqbartmuW8VFOOzCloLx9Q45P0hLrFu';
// Example token provided by incoming GET request
$token = $_GET['crc_token'];
/**
* Creates a HMAC SHA-256 hash created from the app TOKEN and
* your app Consumer Secret.
* @param token the token provided by the incoming GET request
/*
Implement a key-value store that presents the following minimal interface:
`put(k, v)`
`get(k, timestamp=None)`
When a timestamp is specified for the `get` operation, the `get` should return
the value that was associated with the key at that point in time. (Semantically,
this should be equivalent to getting in a time machine, going back to that point
in time, and then asking the key-value store for the current value.)
@jcipriano
jcipriano / latency.sh
Created July 11, 2017 21:49
Shell script that uses curl to measure latency for a given URL.
#!/bin/bash
# parse command line options
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-u|--url)
target_url="$2"
@jcipriano
jcipriano / send-dm-options-and-buttons.js
Created July 18, 2017 22:39
Sends a Twitter DM with Quick Reply Options and Buttons.
var nconf = require('nconf')
var request = require('request')
// load config
nconf.file({ file: 'config.json' }).env()
// twitter authentication
var twitter_oauth = {
consumer_key: nconf.get('TWITTER_CONSUMER_KEY'),
@jcipriano
jcipriano / upload-gif-dm.py
Last active August 9, 2017 20:36
Upload GIF for use with Direct Message
import os
import sys
import time
import json
import requests
from requests_oauthlib import OAuth1
MEDIA_ENDPOINT_URL = 'https://upload.twitter.com/1.1/media/upload.json'
@jcipriano
jcipriano / verify-credentials.js
Created August 30, 2017 18:10
Verifies Twitter credentials.
var nconf = require('nconf')
var request = require('request')
// load config
nconf.file({ file: 'config.json' }).env()
// twitter authentication
var twitter_oauth = {
consumer_key: nconf.get('TWITTER_CONSUMER_KEY'),
@jcipriano
jcipriano / save-dm-image.js
Last active November 2, 2017 18:12
Accesses and saves to disk an image in a Twitter Direct Message.
var request = require('request')
var fs = require("fs")
// twitter authentication
var twitter_oauth = {
consumer_key: 'redacted',
consumer_secret: 'redacted',
token: 'redacted',
token_secret: 'redacted'
}
@jcipriano
jcipriano / get-subscriptions-list.js
Created November 13, 2017 19:31
Retrieves webhook subscriptions for Twitter Account Activity API.
var nconf = require('nconf')
var request = require('request')
// load config
nconf.file({ file: 'config.json' }).env()
// twitter authentication
var twitter_oauth = {
consumer_key: 'redacted',