Skip to content

Instantly share code, notes, and snippets.

const lookupUser = (tweet) => {
const authorId = tweet.data.author_id;
let author = {};
for (const user of tweet.includes.users) {
if (user.id === authorId) {
author = user;
return user;
}
}
@iamdaniele
iamdaniele / Tweet functions.gs
Last active February 12, 2023 05:40
Add public metrics
const BearerTokenKey = 'twitterBearerToken';
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Twitter')
.addItem('Set Bearer token', 'helpers.requestBearerToken')
.addItem('Sign out', 'helpers.logout')
.addToUi();
}
@iamdaniele
iamdaniele / get_oauth1_access_token.js
Created February 20, 2020 20:30
Get OAuth 1.0a access tokens for your user
const qs = require('querystring');
const request = require('request');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const util = require('util');
const get = util.promisify(request.get);
const post = util.promisify(request.post);
@iamdaniele
iamdaniele / bearer_token.sh
Created August 29, 2019 22:53
Get Bearer Token (shell function)
function bearer_token () {
local CONSUMER_API=$1
local CONSUMER_SECRET=$2
if [ -z "$CONSUMER_API" ] || [ -z "$CONSUMER_SECRET" ] ; then
echo "Usage: ${FUNCNAME[0]} <consumer_api_key> <consumer_secret>"
return 1
fi
curl -s -XPOST -H "Authorization: Basic $(echo -n $CONSUMER_API:$CONSUMER_SECRET | base64)" -H "Content-type: application/x-www-form-urlencoded; charset: utf-8" -d "grant_type=client_credentials" https://api.twitter.com/oauth2/token | jq -r .access_token
@iamdaniele
iamdaniele / AverageController.hh
Created August 29, 2018 00:38
An Average Base Controller
<?hh
class AverageController extends BaseController {
// Use this if the user needs a valid login
use AuthenticationTrait;
protected function init() {
// The constructor
}
// Validate request parameters. For example, if the route is
@iamdaniele
iamdaniele / CartAbandonment.java
Last active August 25, 2017 20:30
Suggested implementation for Cart Abandonment
/* Implement and call when the user adds an item to the cart */
protected void addedItemToCart() {
Carnival.logEvent("Add To Cart");
AttributeMap attributes = new AttributeMap();
attributes.putBoolean("add_to_cart", true);
attributes.putBoolean("checkout_complete", false);
Carnival.setAttributes(attributes, new Carnival.AttributesHandler() {
@Override
public void onSuccess() {
// Success
We can't make this file beautiful and searchable because it's too large.
ISO Code,Name
AU,Australia
CN,China
AU,Australia
CN,China
JP,Japan
CN,China
JP,Japan
TH,Thailand
CN,China
@iamdaniele
iamdaniele / index.html
Last active December 2, 2016 19:15
iOS release
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<style>
body {font-family: "Open Sans"}
span {font-size: 11px; color: #474a54;}
</style>
<div><span class="version"></span><span class="release-date"></span></div>
<script>
$.get('https://api.github.com/repos/carnivalmobile/carnival-ios-sdk/releases/latest', function(r) {