Skip to content

Instantly share code, notes, and snippets.

@iwek
iwek / xhr.js
Last active January 24, 2017 12:32
Raw JavaScript Ajax Request
//simple XHR request in pure JavaScript
function load(url, callback) {
var xhr;
if(typeof XMLHttpRequest !== 'undefined') xhr = new XMLHttpRequest();
else {
var versions = ["MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0",
@iwek
iwek / webworkers.html
Last active March 13, 2024 02:45
Super Simple HTML5 Web Workers Example
<!--HTML file-->
<!DOCTYPE html>
<script>
//define a worker
var worker = new Worker('worker.js');
worker.addEventListener('message', function(e) {
console.log('Worker said: ', e.data);
}, false);
@iwek
iwek / geo-convert.js
Created March 18, 2013 18:43
JavaScript Geographic Coordinate Conversion
function convert(geo){
var latlonrg = /(\d+(?:\.\d+)?)[\xb0\s]?\s*(?:(\d+(?:\.\d+)?)['\u2019\u2032\s])?\s*(?:(\d+(?:\.\d+)?)["\u201d\u2033\s])?\s*([SNEW])?/i;
var m = String(geo).split(latlonrg),
lat = m && +m[1] + (m[2] || 0) / 60 + (m[3] || 0) / 3600;
if (m[4].toUpperCase() == "S") {
lat = -lat;
}
@iwek
iwek / maxmind.php
Created March 11, 2013 20:30
Retrieve Location from MaxMind Database in MySQL with PHP
<?php
//check the POST
$ips = $_POST["ips"];
if (empty($ips)) {
echo 'Please provide ips.';
} else {
//connect to mysql and select the maxmind database
@iwek
iwek / mysql-import-csv
Created March 8, 2013 17:16
Importing MaxMind GeoIP Lite CSV file into MySQL
mysql -u root -p root;
USE maxmind;
DROP TABLE IF EXISTS `blocks`;
CREATE TABLE `blocks` (
`startIPNum` int(10) unsigned NOT NULL,
`endIPNum` int(10) unsigned NOT NULL,
`locID` int(10) unsigned NOT NULL,
PRIMARY KEY (`startIPNum`,`endIPNum`)
@iwek
iwek / traceroute.php
Last active December 3, 2022 14:03
PHP Script for Traceroute Pingdom API
<?php
$host = $_GET["host"];
if (empty($host)) {
echo 'Please provide host';
} else {
//create the url for API call
$url = "https://api.pingdom.com/api/2.0/traceroute?host=".$host;
@iwek
iwek / traceroute.php
Last active April 1, 2020 15:03
PHP Curl call to get a Traceroute with Pingdom API
<?php
//initialize
$ch = curl_init();
// 2. set the options, including the url
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "https://api.pingdom.com/api/2.0/traceroute?host=techslides.com");
curl_setopt($ch, CURLOPT_USERPWD, "EMAIL:PASSWORD");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("App-Key: YOUR-KEY-HERE"));
@iwek
iwek / php-curl.php
Created March 8, 2013 15:11
PHP Curl Example with Error Checking
<?php
//initialize
$ch = curl_init();
// 2. set the options, including the url
curl_setopt($ch, CURLOPT_URL, "https://api.pingdom.com/api/2.0/traceroute?host=techslides.com");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("App-Key: YOUR-KEY-HERE"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
@iwek
iwek / lastfm-api.php
Last active January 30, 2023 21:00
Last FM API script in PHP to pull album and artist artwork.
<?php
//get artist photo
function getArtistPhoto($artist, $size) {
$artist = urlencode($artist);
$xml = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist={$artist}&api_key=YOUR_KEY";
$xml = @file_get_contents($xml);
if(!$xml) {
@iwek
iwek / pinterest-4.js
Last active December 14, 2015 13:19
Sort and Organize Pinterest Images by Likes
//cleanup for likes
$(".likes").each(function() {
var num = Number($(this).text().trim().replace("likes", "").replace("like", ""));
$(this).html(num);
});
//sort
var mylist = $('.Pin');
var listitems = mylist.find('.likes:not(:contains(0))'); //do not match on elements that have 0 likes
listitems.sort(function(a, b) {