Skip to content

Instantly share code, notes, and snippets.

View dentarg's full-sized avatar
🌦️
=:D><!

Patrik Ragnarsson dentarg

🌦️
=:D><!
View GitHub Profile
@dentarg
dentarg / mk_symlinks.sh
Created June 19, 2012 20:42
Symlink stuff from home.git
#!/bin/sh
add_dir_link() {
DIR=$1
cd $HOME
if [ -L $DIR ]; then
echo "Link exists: $DIR"
elif [ -d $DIR ]; then
echo "Dir exists: $DIR"
else
:javascript
$(function() {
// Helpers for deleting stuff
$( "input.delete" ).click(function(evt) {
return confirm("Är du säker?");
});
$( "button.delete" ).click(function(evt) {
return confirm("Är du säker?");
});
$( "a.btn-danger" ).click(function(evt) {
@dentarg
dentarg / gist:3019580
Created June 29, 2012 17:49
Problem with dm-do-adapter
$ irb
1.9.3-p125 :001 > require 'dm-core'
=> true
1.9.3-p125 :003 > url = "postgres:alarmo?host=localhost&port=4321&user=deploy"
=> "postgres:alarmo?host=localhost&port=4321&user=deploy"
1.9.3-p125 :004 > adapter = DataMapper.setup(:default, url)
NoMethodError: undefined method `to_int' for "4321":String
from /Users/dentarg/.rvm/gems/ruby-1.9.3-p125/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:229:in `normalized_uri'
from /Users/dentarg/.rvm/gems/ruby-1.9.3-p125/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:269:in `initialize'
from /Users/dentarg/.rvm/gems/ruby-1.9.3-p125/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:13:in `new'
@dentarg
dentarg / gist:3082390
Created July 10, 2012 09:53
$ pip freeze
$ pip freeze
PyRSS2Gen==1.0.0
Twisted==11.0.0
altgraph==0.7.1
bdist-mpkg==0.4.4
bonjour-py==0.3
cssselect==0.7.1
include-server==3.1-toolwhip.1
lxml==2.3.4
macholib==1.3
@dentarg
dentarg / pdf-reader.rb
Created July 11, 2012 13:39
Convert a PDF to text, HTML and XML with various tools
#!/usr/bin/env ruby
require 'pdf-reader'
infile=ARGV[0]
outfile=ARGV[1]
reader = PDF::Reader.new(infile)
text = ""
reader.pages.each do |page|
@dentarg
dentarg / pdf.tree.write.xml
Created July 12, 2012 15:04
pdf.tree.write() dump
<pdfxml Producer="Acrobat Distiller 8.1.0 (Windows)" Author="SE:W:CAR:MP" Creator="OneForm Designer Plus" Title="2007 Form 1040A" ModDate="D:20080215140604-05'00'" Keywords="Fillable" CreationDate="D:20080215110608-05'00'" Subject="U.S. Individual Income Tax Return"><LTPage rotate="0" pageid="1" height="1043" width="648" bbox="[0, 0, 648, 1043]" y1="1043" y0="0" x0="0" x1="648" page_index="0" page_label="1"><LTTextLineHorizontal word_margin="0.1" height="8.128" width="14.588" bbox="[89.119, 913.467, 103.707, 921.595]" y1="921.595" y0="913.467" x0="89.119" x1="103.707"><LTTextBoxHorizontal index="1" height="8.128" width="14.588" bbox="[89.119, 913.467, 103.707, 921.595]" y1="921.595" y0="913.467" x0="89.119" x1="103.707">Date </LTTextBoxHorizontal></LTTextLineHorizontal><LTTextLineHorizontal word_margin="0.1" height="11.612" width="28.397" bbox="[431.054, 960.806, 459.45, 972.418]" y1="972.418" y0="960.806" x0="431.054" x1="459.45"><LTTextBoxHorizontal index="4" height="11.612" width="28.397" bbox="[431.054, 9
@dentarg
dentarg / gist:3129240
Created July 17, 2012 12:52
Why do pdfseparate exit with status code 99?
$ mkdir /tmp/pdfs
$ pdfseparate
pdfseparate version 0.20.0
Copyright 2005-2012 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011 Glyph & Cog, LLC
Usage: pdfseparate [options] <PDF-sourcefile> <PDF-pattern-destfile>
-f <int> : first page to extract
-l <int> : last page to extract
-v : print copyright and version info
-h : print usage information
@dentarg
dentarg / gist:3313907
Created August 10, 2012 12:33
caching
def nummer
if @nummer
@nummer
else
@nummer = process_nummer
end
end
def attributes
if @attributes
This file has been truncated, but you can view the full file.
root@linux:~# cd pdftohtml-0.40a/
root@linux:~/pdftohtml-0.40a# ls
aconf.h AUTHORS CHANGES CHANGES~ fofi goo Makefile Makefile~ splash src xpdf
root@linux:~/pdftohtml-0.40a# make
cd goo; make
make[1]: Entering directory `/root/pdftohtml-0.40a/goo'
g++ -O2 -DHAVE_CONFIG_H -I.. -I. -c GHash.cc
g++ -O2 -DHAVE_CONFIG_H -I.. -I. -c GList.cc
g++ -O2 -DHAVE_CONFIG_H -I.. -I. -c GString.cc
g++ -O2 -DHAVE_CONFIG_H -I.. -I. -c gmempp.cc
class StringExtension
def self.formattera_summa(summa)
tusenavskiljare = " "
decimalseparator = ","
summa = "%.2f" % summa
# From ActionPack ActionView::Helpers::NumberHelper.number_with_delimiter
parts = summa.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{tusenavskiljare}")
parts.join(decimalseparator)
end