Skip to content

Instantly share code, notes, and snippets.

View cypres's full-sized avatar

Hans Arnholm cypres

View GitHub Profile
@cypres
cypres / gpoint.php
Created February 23, 2011 14:20
PHP class to convert Latitude & Longitude coordinates into UTM & Lambert Conic Conformal Northing/Easting coordinates.
<?php
/**
* PHP class to convert Latitude & Longitude coordinates into UTM & Lambert Conic Conformal Northing/Easting coordinates.
*
* This class encapsulates the methods for representing a geographic point on the earth in three different coordinate systema. Lat/Long, UTM and Lambert Conic Conformal.
*
* Code for datum and UTM conversion was converted from C++ code written by Chuck Gantz (chuck.gantz@globalstar.com) from http://www.gpsy.com/gpsinfo/geotoutm/
* This code was converted into PHP by Brenor Brophy (brenor@sbcglobal.net) and later refactored for PHP 5.3 by Hans Duedal (hd@onlinecity.dk).
*
@cypres
cypres / fix_permission.sh
Created July 1, 2011 15:10
fix permissions shell script
#!/bin/sh
/usr/bin/find /var/www -path "/var/www/*/wwwroot/*" \
\( -type f ! -perm 660 -print0 -exec chmod 660 {} \; -exec sh -c exit 1 \; \) -or \
\( -type d ! -perm 770 -print0 -exec chmod 770 {} \; -exec sh -c exit 1 \; \) -or \
\( \( ! -user ftp -or ! -group www \) -print0 -exec chown -f ftp:www {} \; \) > /dev/null
@cypres
cypres / benchmark.js
Created July 19, 2011 13:40
node js redis benchmark
var redis = require("redis"), client = redis.createClient(6379,'127.0.0.1');
// Benchmark params
var data = 'O:10:"SmsRequest":5:{s:2:"id";i:550845359;s:6:"sender";s:10:"OnlineCity";s:7:"message";s:140:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus blandit faucibus magna, vitae accumsan orci iaculis sed. Morbi cras amet.";s:10:"recipients";a:1:{i:0;i:4526159917;}s:10:"dataCoding";i:0;}';
var n = 20000;
var start;
var lastOp;
client.on("error", function (err) {
console.log("Error " + err);
@cypres
cypres / client.js
Created August 17, 2011 15:29
node.js thrift exception test
var thrift = require('thrift');
var test = require('./gen-nodejs/test.js'),
ttypes = require('./gen-nodejs/test_types');
var connection = thrift.createConnection('localhost', 9090),
client = thrift.createClient(test, connection);
connection.on('error', function(err) {
console.error(err);
@cypres
cypres / palindrome.php
Created August 25, 2011 11:32
Palindrome tester (UTF-8 compatible)
function palindromeTest($i) {
preg_match_all('/([\\x41-\\x5A\\x61-\x7A])|([\\xC0-\\xDF].)|([\\xE0-\\xEF]..)|([\\xF0-\\xFF]...)]/',$i,$m);
$a = mb_strtolower(implode('',$m[0]),'UTF-8');
$b = mb_strtolower(implode('',array_reverse($m[0])),'UTF-8');
return ($a == $b);
}
var_dump(palindromeTest('Syy hyökätä: köyhyys!')); // true
var_dump(palindromeTest('Syy hyäkötä: köyhyys!')); // false
var_dump(palindromeTest('Selmas lakserøde garagedøre skal samles')); // true
var_dump(palindromeTest('a€b€a')); // true (U+20AC test)
@cypres
cypres / iconv-test.cpp
Created September 16, 2011 11:03
iconv convert
#include <iostream>
#include <iconv.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
using namespace std;
char *
convert(const char *from_charset, const char *to_charset, const char *input) {
size_t inleft, outleft, converted = 0;
@cypres
cypres / findmyip.php
Created September 18, 2011 18:32
find ip via php
<?php
// Uses third party site ipnr.dk, thanks a lot
if (isset($_SERVER["SERVER_ADDR"])) echo "Local Address: ".$_SERVER["SERVER_ADDR"]."<br/>\nRemote: ";
if (extension_loaded('curl')) {
$c = curl_init('http://ipnr.dk/');
curl_setopt($c,CURLOPT_USERAGENT,'curl/0 (PHP) libcurl/0');
curl_exec($c);
} else {
echo "no cURL extension\n";
}
@cypres
cypres / hexdump.cpp
Created November 9, 2011 16:57
hexdump, cpp style
/*
* Copyright (C) 2011 OnlineCity
* Licensed under the MIT license, which can be read at: http://www.opensource.org/licenses/mit-license.php
* @author hd@onlinecity.dk & td@onlinecity.dk
*/
#include "hexdump.h"
void oc::tools::hexdump(std::ostream &out, const boost::shared_array<uint8_t> &bytes, size_t length)
{
@cypres
cypres / hop.cpp
Created November 13, 2011 10:45
hoppity hop
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(int argc, char** argv) {
if (argc != 2) {
cout << "Wrong number of arguments: " << argc << endl;
return 1;
Less than 80 chars
___________
< text here >
-----------
two lines
________________________________
/ text goes here text goes here \