Skip to content

Instantly share code, notes, and snippets.

@phof
phof / gist:3775466
Created September 24, 2012 11:00
PHP geolocation via maxmind
// GeoIP php modules from: http://www.maxmind.com/app/php
// GeoLiteCity.dat from: http://www.maxmind.com/app/geolite
include("lib/geo/geoipcity.inc");
include("lib/geo/geoipregionvars.php");
include("lib/geo/timezone.php");
$gi = geoip_open("lib/geo/GeoLiteCity.dat",GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,$_SERVER['REMOTE_ADDR']);
geoip_close($gi);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>TITLE</title>
<meta name="author" content="NAME">
<meta name="description" content="DESCRIPTION">
<meta name="keywords" content="KEYWORDS,HERE">
<link rel="shortcut icon" href="FAVICON.ico" type="image/vnd.microsoft.icon">
<link rel='stylesheet' href='//fonts.googleapis.com/css?family=FONT1|FONT2ETC' type='text/css'>
//1
document.getElementById('the_div').addEventListener(
'click', function(){ log('the_div!') }, true);
document.getElementById('the_list').addEventListener(
'click', function(){ log('the_list!') }, false);
document.getElementById('the_item').addEventListener(
'click', function(){ log('the_item!') }, true);
// Implement a function prototype extension that caches function results for
// the same input arguments of a function with one parameter.
//
// For example:
// Make sin(1) have the result of Math.sin(1), but use a cached value
// for future calls.
//
// Part 2.
// Use this new function to refactor the code example.
// Some good test numbers: 524287, 9369319, 2147483647 (all primes)
// 1. Write a class to support the following code:
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
// 2. Add a getName() method to all Person objects, that outputs
// the persons name.
// Exercise 1 - OO || !OO
// Define a data structure for cars (make and color), and a function
// that logs a string like "I'm a red Mercedes" to the console.
// Make two versions: a functional version, and a object-oriented version.
// Example call for functional version:
//logCar({ color: 'blue', make: 'BMW' });
// Example call for OO version:
//(new Car('Ferrari', 'red')).log();
var myVar = (function() {
var index;
function log(){
console.log(index);
}
function iterate(){
log();
function isCreditCard(CC) {
var sum = 0, mul = 1, length = CC.length, digit, tproduct;
if(length > 19) return false;
for (var i=0; i < length; i++) {
digit = CC.substring(length-i-1,length-i);
tproduct = parseInt(digit)*mul;
sum += tproduct>=10 ? (tproduct % 10) + 1 : tproduct;
mul += mul == 1 ? 1 : -1;
@phof
phof / sfdc_sessionId.js
Created February 8, 2011 16:49
set salesforce session ID
this.__sfdcSessionId = document.cookie.match(/(^|;\s*)sid=(.+?);/)[2];
@phof
phof / get_selected_options_value_from_reportsinthisfolder.js
Created February 3, 2011 15:41
Recover reports in a reports folder from Sandbox
function loadScript(url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
var done = false;
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
callback();
script.onload = script.onreadystatechange = null;