Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
var pubsub = {};
(function (q) {
var topics = {},
subUid = -1;
q.subscribe = function (topic, func) {
if (!topics[topic]) {
topics[topic] = [];
}
var token = (++subUid).toString();
topics[topic].push({
@johnloy
johnloy / is-git-branch-clean.sh
Last active August 27, 2021 19:32
Check whether a git branch is clean
git_is_dirty() {
if [[ $(git status --porcelain 2> /dev/null | tail -n1) != "" ]]
then
echo 'ERROR: branch dirty'
exit 1
fi
}
@johnloy
johnloy / python-simple-http-server.sh
Last active August 27, 2021 14:36
Start a quick http server from any directory
python -m SimpleHTTPServer
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version