Skip to content

Instantly share code, notes, and snippets.

def timesince(d, now=Time.now)
delta = (now - d.to_time).to_i
return '0 Minuten' if delta <= 60
chunks = [
[60 * 60 * 24 * 356, 'Jahr', 'Jahre'],
[60 * 60 * 24 * 30, 'Monat', 'Monate'],
[60 * 60 * 24 * 7, 'Woche', 'Wochen'],
[60 * 60 * 24, 'Tag', 'Tage'],
[60 * 60, 'Stunde', 'Stunden'],
@dabio
dabio / gist:834429
Created February 18, 2011 21:18
force encoding for cuba
# Fixes encoding issue by defaulting to UTF-8
def force_encoding(data, encoding = 'UTF-8')
if data.respond_to? :force_encoding
data.force_encoding encoding
elsif data.respond_to? :each_value
data.each_value { |v| v.force_encoding(encoding) }
elsif data.respond_to? :each
data.each { |v| v.force_encoding(encoding) }
end
data
@dabio
dabio / gist:1681463
Created January 26, 2012 07:05
Uninstall all ruby gems
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
@dabio
dabio / configure_liblo_iphone.sh
Created February 3, 2012 12:21 — forked from mikewoz/configure_liblo_iphone.sh
Configure liblo for iOS 5.0
./configure \
--host="arm-apple-darwin" \
--enable-static \
--disable-shared \
--disable-dependency-tracking \
CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-cpp-4.2 \
CXXCPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-cpp-4.2 \
CXX=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc\
AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar \
@dabio
dabio / next-day-date.xsl
Created March 28, 2012 09:25
Get the next day from a given date
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="next-day-date">
<xsl:param name="date"/> <!-- format is YYYY-MM-DD -->
<xsl:param name="old_year" select="number(substring($date, 1, 4))"/>
<xsl:param name="old_month" select="number(substring($date, 6, 2))"/>
<xsl:param name="old_day" select="number(substring($date, 9, 2))"/>
@dabio
dabio / gist:3359894
Created August 15, 2012 12:51
Drop all tables of a database
mysql -Nse 'SHOW TABLES' [database] | while read table; do mysql -e "DROP TABLE $table;" [database]; done
@dabio
dabio / gist:3359898
Created August 15, 2012 12:52
Truncate all tables of a database
mysql -Nse 'SHOW TABLES' [database] | while read table; do mysql -e "TRUNCATE TABLE $table;" [database]; done
@dabio
dabio / gist:4239163
Created December 8, 2012 07:50 — forked from nickjenkin/gist:3175420
Golang Solr result xml parser
package solr
import (
"encoding/xml"
)
type SolrResponse struct {
Results SolrResults `xml:"result"`
}
@dabio
dabio / gist:9929590
Last active August 29, 2015 13:58
Create small Images, Thumbnails and Rename
mogrify -filter spline -adaptive-resize 1600x -unsharp 0x1 *.JPG
mogrify -filter spline -resize 616x -unsharp 0x1 -path thumbs *.JPG
for files in *.JPG
do
mv "$files" "${files%.JPG}.jpg"
done
- (void)removeOldDatabase
{
if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"parku-3.0.0"] boolValue]) {
NSURL *storeURL = [NSPersistentStore MR_defaultLocalStoreUrl];
NSError *error;
[[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"parku-3.0.0"];
}
}