Skip to content

Instantly share code, notes, and snippets.

@niklasvincent
niklasvincent / facebook-event.php
Created August 18, 2011 11:50
Get details about Facebook event
<?php
function is_facebook_event( $url )
{
return ( preg_match("/http:\/\/www\.facebook\.com\/event.php\?eid=[0-9]*\.*/", $url) == 1 );
}
function get_facebook_event ( $url )
{
$m = explode('=', $url);
@niklasvincent
niklasvincent / FacebookEvent.php
Created August 26, 2011 10:20
Facebook Event WP Plugin
<?php
/*
Plugin Name: Facebook Event
Plugin URI: http://www.studentlund.se
Description: Detect Facebook event URL in post and update post content to match the event
Author: Niklas Lindblad
Version: 0.1
Author URI: http://niklas.lindblad.info
*/
@niklasvincent
niklasvincent / gist:2639727
Created May 8, 2012 22:00
Sammy.js + Mustache + seamless presentation of REST API data
var model = {
'/animals': {
'verb': "get",
'template': '<div id="animal-{{ID}}"> \
<a href="#/animals/{{ID}}"><h2>{{title}}</h2></a> \
<h3>{{time_added}}</h3> \
<img src="{{thumbnail.0}}" /></div>'
},
@niklasvincent
niklasvincent / geo.php
Created June 8, 2012 08:09
MongoDB really shines in this comparison
// MySQL
$sql = "SELECT all, the fields, you, want, ((ACOS(SIN(c.Latitude * PI() / 180) * SIN(" . $lat . " * PI() / 180) + COS(c.Latitude * PI() / 180) * COS(" . $lat . " * PI() / 180) * COS((c.Longitude - " . $lng . ") * PI() / 180)) * 180 / PI()) * 60 * 2) as distance FROM places ORDER BY distance DESC;";
// MongoDB
$this->places->find(array( 'loc' => array( '$near' => array($lat, $lng) ) ));
@niklasvincent
niklasvincent / gist:2894406
Created June 8, 2012 08:09
Geo comparison
// MySQL
$sql = "SELECT all, the fields, you, want, ((ACOS(SIN(c.Latitude * PI() / 180) * SIN(" . $lat . " * PI() / 180) + COS(c.Latitude * PI() / 180) * COS(" . $lat . " * PI() / 180) * COS((c.Longitude - " . $lng . ") * PI() / 180)) * 180 / PI()) * 60 * 2) as distance FROM places ORDER BY distance DESC;";
// MongoDB
$this->places->find(array( 'loc' => array( '$near' => array($lat, $lng) ) ));
@niklasvincent
niklasvincent / post-commit
Created February 19, 2013 16:00
Add the following to ./git/hooks/post-commit and change your UID and TOKEN (obtained from the user -> settings dialog). More information here https://github.com/lefnire/habitrpg/wiki/API
# Gain XP on HabitRPG
HABITRPG_UID="xxxxx"
HABITRPG_TOKEN="yyyyyy"
curl -X POST -H 'Content-Type:application/json' \
"https://habitrpg.com/v1/users/${HABITRPG_UID}/tasks/git/up" \
-d "{\"apiToken\":\"${HABITRPG_TOKEN}\", \"title\":\"Git commit\", \"service\":\"git\", \"icon\":\"https://github.com/favicon.ico\"}" 1>/dev/null 2
>&1
#!/bin/bash
# Set Graphite host
GRAPHITE="172.16.20.1"
GRAPHITE_PORT="2003"
stats() {
HOSTNAME="mediacenter"
DATE=$(date +%s)
echo "server.${HOSTNAME}.${1} ${2} ${DATE}" | nc $GRAPHITE $GRAPHITE_PORT -w 1
@niklasvincent
niklasvincent / build-nginx.sh
Last active October 11, 2019 04:44
Build script for statically compiled nginx 1.4.7 with OpenSSL 1.0.1e.
#!/bin/bash
set -e
NGINX_VERSION="1.6.0"
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
PCRE_VERSION="8.34"
PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
OPENSSL_VERSION="1.0.1g"
OPENSSL_TARBALL="openssl-${OPENSSL_VERSION}.tar.gz"
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
mQINBFHK/6cBEAC+XPwiHQ3eZ1B9OfnyITX5ADFlks06JP0icrcmMDDNEpTYSC+q
FHJ/D/uEdKM03RalVGZ8KES/TG3kjaEPUODR8adRWP8EYm/EGTozn6qO5YwiB/7q
8v9R9R+ZZwivRvM56054A/RgAgy09Qf50uLgRGryRyDuPEwyVDJEcGglCwOR+oep
FGnxi7kmO2RTVmHHEAQWoCZDbkgyQctmh++99UKdKMG7yhlX8EMOmN+iYAW4ZXS/
fFSOKTdgb26gNUhaBuKboHmCEx3JwZXnkHZ853jXFWQndb70+wcVnP9i04vM2Nsn
8ACBVg0y7zheGV6eBz9X+MD/+fSui7syINYDW9oiswQm5A9tgP/Bl+XDqI5HZIOZ
twuO7YJBQfWX5Js6Qc1qxaSl96VzlNoL1xXx+ULBqgyaEOTd0M4AcJW3V0vnaTd2
@niklasvincent
niklasvincent / gist:ed05ecdef9dd5ab60c57
Created July 14, 2014 21:00
/etc/rc.local for Utilite
echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf
echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_rmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_timestamps = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_no_metrics_save = 1' >> /etc/sysctl.conf
echo 'net.core.netdev_max_backlog = 5000' >> /etc/sysctl.conf
echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor