Skip to content

Instantly share code, notes, and snippets.

View qsun's full-sized avatar
🎯
Focusing

Quan qsun

🎯
Focusing
  • open
  • Sydney NSW Australia
View GitHub Profile
@qsun
qsun / gist:1247402
Created September 28, 2011 08:49
ruby integer to/from ip address
require 'ipaddr'
IPAddr.new('1.2.3.4').to_i
IPAddr.new(16909060, Socket::AF_INET).to_s
@qsun
qsun / indexed.php
Created January 21, 2012 23:00
Check if URL is indexed by Google
<?php
function indexed($url) {
$url = 'http://webcache.googleusercontent.com/search?q=cache:' . urlencode($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Chrome 10');
# Trying to make an appointment with someone as soon as possible.
import os
from datetime import datetime
from http.cookiejar import CookieJar
import requests
from bs4 import BeautifulSoup
notification_url = os.environ['IFTTT_WEBHOOK']
import serial
import aqi
def read_frame(ser):
bs = ser.read(2)
# print(['0x{:02x}'.format(x) for x in bs])
length = bs[0]*256+bs[1]
frame = ser.read(length)
pm1_0 = frame[0]*256+frame[1]
@qsun
qsun / use.c
Created January 11, 2019 14:12
mimic poll with IRQ (using C macro)
IT_WRAP(uart6_dma_in_progress, HAL_UART_Transmit_IT(&CLI_UART, (uint8_t *)(debug_log_str + debug_log_tail), len));
@qsun
qsun / kicad-jlc-smt-convert.py
Created August 26, 2018 10:51
convert kicad .pos SMT file into the one JLC uses.
import sys
import csv
import re
for filename in sys.argv[1:]:
print("Processing %s" % (filename,))
o_filename = filename + '-jlc.csv'
with open(filename, 'r') as i:
@qsun
qsun / spin.py
Created February 6, 2012 05:40
Parse and spin spin-formatted article
import random
# Usage: parse(text).spin()
class Node:
def __init__(self):
None
def spin(self):
@qsun
qsun / deploy.sh
Created January 18, 2016 19:54
Deploy script for laravel
#!/bin/bash
set -e
set -x
/sbin/start-stop-daemon --stop --oknodo --pidfile /home/httpsreminder/queue.pid --retry=TERM/30/KILL/5
if [ -d httpsreminder.com ]; then
pushd httpsreminder.com

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

#!/usr/bin/env bash
set +x
set +e
go build -ldflags "-X main.version $(git rev-parse HEAD)"