Skip to content

Instantly share code, notes, and snippets.

@andreban
andreban / gist:eb7f1385a7c49d91bc0f
Created February 19, 2016 22:03
Setting Terminal colors on Mac
#Add this to .bash_profile or .profile
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
@andreban
andreban / gifenc.sh
Last active January 15, 2021 12:31
Using ffmpeg to transform a video to an animated gif
#!/bin/sh
#Usage: ./gifenc.sh video.mkv anim.gif
palette="/tmp/palette.png"
filters="fps=30,scale=320:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
@andreban
andreban / gist:c2e38ea4eecbfbf54adda80988506e58
Last active February 6, 2018 00:15
Setting Referer on CCT
intent.putExtra(Intent.EXTRA_REFERRER,
Uri.parse("android-app://" + context.getPackageName()));
@andreban
andreban / gist:ef9ea3adfe8117dafe16d052461892bb
Last active December 18, 2016 18:06
Adding offline analytics to a service-workers
// sw-offline-google-analytics *must* be imported and initialized before
// sw-toolbox, because its 'fetch' event handler needs to run first.
importScripts('/sw-offline-google-analytics/offline-google-analytics-import.js');
goog.offlineGoogleAnalytics.initialize();
// GA embed code
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'Your GA ID', 'auto');
// The following line sets the dimension to the pageview request.
ga('set', 'Your Dimension Name', navigator.onLine);
ga('send', 'pageview');
@andreban
andreban / gist:87cac33bd588ef217e99f86833c351ac
Last active December 18, 2016 18:05
Tracking home screen prompts
// Setup a listener to track Add to Homescreen events.
window.addEventListener('beforeinstallprompt', e => {
e.userChoice.then(choiceResult => {
ga('send', 'event', 'A2H', choiceResult.outcome);
});
});
@andreban
andreban / manifest.json
Last active December 16, 2016 17:34
Tracking home screen traffic
{
"name": "PWA Directory",
"short_name": "PWA Directory",
"description": "A Directory of PWAs",
"//": "Append tracking parameters to start_url",
"start_url": "/?utm_source=homescreen",
"..."
}
@andreban
andreban / topic-subscribe.sh
Created January 5, 2017 10:46
Subscribing to a Firebase Topic
curl -X POST -H "Authorization: key=<Firebase Auth Key>" -H "Content-Type: application/json" -d '{}' "https://iid.googleapis.com/iid/v1/<User-FCM-Token>/rel/topics/my-topic"
curl -X POST -H "Authorization: key=<Firebase-Auth-Key>" -H "Content-Type: application/json" -d '{
"to": "/topics/test",
"registration_tokens": ["User-FCM-Token"]
}' "https://iid.googleapis.com/iid/v1:batchRemove"
curl -X POST -H "Authorization: key=<Firebase Auth Key>" -H "Content-Type: application/json" -d '{
"notification": {
"title": "A Notification to My Topic",
"body": "Add more information to your notification here!",
"icon": "https://www.example.com/my-notification-icon.png",
"click_action": "https://www.example.com/url-to-open-from-notification.html"
},
"to": "/topics/my-topic"
}' "https://fcm.googleapis.com/fcm/send"