Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 - [email protected])
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 / 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 / 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 / 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
#