Skip to content

Instantly share code, notes, and snippets.

View davidlevy's full-sized avatar

David Levy davidlevy

View GitHub Profile
@davidlevy
davidlevy / xiti_tag_prototype.js
Last active August 29, 2015 13:56
XITI Prototype integration
vpTrackClick = function(tag, element) {
return xt_click(element,'C', xtn2, tag,'N');
}
vpAttachClickTag = function(col, tag) {
col.each( function(element){
$(element).observe('click', function(e) {
if (element.tagName=='A') {
e.preventDefault();
return vpTrackClick(tag, element);
} else if (element.tagName=='INPUT' && element.type=="submit") {
@davidlevy
davidlevy / interactionCounts.php
Last active December 18, 2015 07:29
Get values for Schema.org interactionCount properties
/*
Example :
<?php $url = 'http' . ($_SERVER['HTTPS'] ? 's':'') .'://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>
<meta itemprop="interactionCount" content="UserTweets:<?php echo get_tweets($url);?>"/>
*/
function get_tweets($url) {
$url = urlencode($url);
@davidlevy
davidlevy / youtube_channel_extractor.py
Last active April 1, 2020 06:30
Get list of Youtube channel videos
#code from https://stackoverflow.com/questions/18953499/youtube-api-to-fetch-all-videos-on-a-channel
#1. get an API Key : https://console.developers.google.com/apis/credentials
#2. enable Youtube API : https://console.developers.google.com/apis/api/youtube.googleapis.com/
import urllib
import json
API_KEY = 'YOUR_API_KEY_HERE'
CHANNEL_ID = 'YOUR_CHANNEL_ID'
@davidlevy
davidlevy / convertGeoToPixel.php
Created July 1, 2013 07:32
Function to convert Geo coordinates To Pixels
<?php
function convertGeoToPixel($lat, $lon){
$mapWidth = 400;
$mapHeight = 260;
$mapLonLeft = -180;
$mapLonRight = 180;
$mapLonDelta = $mapLonRight - $mapLonLeft;
@davidlevy
davidlevy / scrape-stackshare-tools.js
Last active April 22, 2021 22:29
Scrape Stackshare Tools to JSON
const fetch = require("node-fetch");
const $ = require("cheerio");
const fs = require("fs");
const normalizeVote = (x) => {
if (/K$/i.test(x)) {
return +(x.replace(/K/i, '')) * 10**3
}
else if (/M$/i.test(x)) {
return +(x.replace(/M/i, '')) * 10**6