Skip to content

Instantly share code, notes, and snippets.

@laurynas
laurynas / tomtom_helper.rb
Created August 11, 2010 18:59
Generate "Add to TomTom" button
module TomTomHelper
# Generate Add To TomTom button
# You can pass following options hash:
# name - place name
# latitude - decimal latitude
# longitude - decimal longitude
# attribution - your attribution
# logo - link to your logo
#
@laurynas
laurynas / float.rb
Created August 11, 2010 20:52
Convert decimal to degrees, minutes, seconds sexagesimal (used for GPS coordinates)
class Float
# Convert decimal to degrees, minutes, seconds sexagesimal
# (used for GPS coordinates)
def to_sexagesimal
degrees = abs.floor
x = (abs - degrees) * 60
minutes = x.floor
seconds = (((x - minutes) * 60) * 100).round.to_f / 100
sign = self < 0 ? '-' : ''
@laurynas
laurynas / array_to_rows.php
Created August 12, 2010 13:51
PHP: array_to_rows
<?php
function array_to_rows($array, $cols, $complete = true)
{
$rows = array_chunk($array, $cols);
$last = count($rows) - 1;
if (!$complete || $last < 0)
return $rows;
@laurynas
laurynas / html_entity_decode_utf8.php
Created August 30, 2010 10:10
Convert escaped html to utf8
<?php
// Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv)
function code2utf($num)
{
if ($num < 128) return chr($num);
if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
return '';
@laurynas
laurynas / break_nonbreaking_space.php
Created August 31, 2010 09:56
Breaks long non-breaking string
<?php
/**
* Breaks long non-breaking string
*/
function break_nonbreaking($str, $max_length = 20, $breaker = ' ')
{
$max_length = (int)$max_length;
preg_match_all("/[^\s]{{$max_length},}/", $str, $m);
@laurynas
laurynas / rename_photos_by_date.rb
Created October 1, 2010 21:07
Renames all pictures in the folder using EXIF date/time
require 'rubygems'
require 'exifr'
data = Dir.glob("photos/*.jpg").collect do |file|
{
:file => file,
:time => EXIFR::JPEG.new(file).date_time,
}
end
@laurynas
laurynas / Blynai su bulviu padazu
Created October 25, 2010 12:53
Blynai su bulviu padazu
blynus tai reikia kepti is miltu, vandens, truputi pieno ir 1-2 kiausiniu
tesla turi buti gana skysta, kad dideli blynai iseitu
o padazui reikia isvirti bulviu
jas sutrinti
pakepti spirguciu
ir tada ta bulviu kose su gana nemazai pieno ir tais spirguciais pakepinti keptuveje
pieno reikia ipilti tiek, kad padazas butu ne sausas
@laurynas
laurynas / gist:658139
Created November 1, 2010 13:12
Berlin (nuo Dončiaus)
Usualy we hang out in Kreuzberg, Friedrichshein and Prenzlauerberg areas as well as Mitte (center).
http://berlin.unlike.net/locations/39-Club-der-Visionaere
Club der Visionaere - an outside bar/club/place to hang out in Kreuzberg. It's IN one of the canals, on some sort of floating rafts.
Schlesische str., leading to the club is also worth noticing with one of the best indian food restaurants and lots of small watering holes. L.U.X .with live bands and Vendel with experimental poetry in german are my favourites:)
Bar 25 - another outside bar on the bank of river. 3 day parties or just to sit back and spend a warm afternoon. Also has circus, motel and restaurant.
http://berlin.unlike.net/locations/272-Bar-25
Hops & Barley brewery pub (Friedrichshain) - locally brewed beer in one of my favourite neighbourhoods. The whole area between Boxhander str and Simon Dach str. is dense with pubs, thai food restaurants and Kieze-kiosks (small shops with astounishing variety of beers).
@laurynas
laurynas / update_geolite_cities.sh
Created November 4, 2010 12:15
Fetch GeoLite Cities database from MaxMind
#!/bin/sh
#
# Update GeoLite Cities database from MaxMind
# (C) 2010 Laurynas Butkus laurynas.butkus at gmail.com
#
TMP=/tmp
TARGET_DIR=/usr/local/share/GeoIP
cd $TMP
@laurynas
laurynas / form_builder_helper.rb
Created November 15, 2010 21:20
Add multi_locale_field helper to form builer
module FormBuilderHelper
def multi_locale_field(method, opts = {})
opts = {
:type => :text_field
}.merge(opts)
type = opts.delete(:type)
html = []