Skip to content

Instantly share code, notes, and snippets.

@janfri
janfri / gist:a3e61731864a63554ba6f32bdc7179aa
Last active October 29, 2023 22:04
Install sqlite-pcre on OSX
brew install sqlite pcre
git clone https://github.com/ralight/sqlite3-pcre.git
cd sqlite3-pcre
cc -shared -o pcre.so -I/usr/local/opt/pcre/include -fPIC -W -Werror pcre.c -L/usr/local/opt/pcre/lib -lpcre
echo ".load '`pwd`/pcre.so'" >> ~/.sqliterc
# encoding: utf-8
# frozen_string_literal: true
# Copyright (c) 2019 by Jan Friedrich <janfri26@gmail.com>
# License: Public Domain
module Ansicolor
@codes = {}
@janfri
janfri / copy-selection-coordinates.py
Created April 12, 2018 10:31 — forked from feiss/copy-selection-coordinates.py
GIMP plugin in Python for copying current selection coordinates to clipboard
#!/usr/bin/python
from gimpfu import *
import os
def plugin_main(timg, tdrawable):
non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(timg)
if (non_empty):
os.system('echo {}, {}, {}, {} | xsel --clipboard'.format(x1, y1, x2 - x1, y2 - y1))
else:
os.system('echo "no selection" | xsel --clipboard')
#!/usr/bin/env ruby
# encoding: utf-8
require 'nokogiri'
query = ARGV.shift
ARGV.each do |fn|
doc = Nokogiri::XML(File.read(fn))
puts doc.search(query)
end
require 'fileutils'
require 'tempfile'
def File.changelines filename, &blk
temp = Tempfile.new('changelines')
File.foreach(filename) do |line|
line = blk.call(line)
temp.write(line)
end
temp.close
@janfri
janfri / sun.rb
Last active April 25, 2016 09:26
Sunrise and sunset
#!/usr/bin/env ruby
# -- encoding: utf-8 --
module Astronomy
# Floor as function
def floor x
x.floor
end
@janfri
janfri / exif2csv.rb
Last active August 29, 2015 14:03
Read metadata with multi_exiftool and write it to a csv file
require 'csv'
require 'multi_exiftool'
tags = ["filename", "filesize", "make", "model", "orientation", "modifydate", "exposuretime", "fnumber", "exposureprogram", "iso", "createdate", "flash", "focallength", "quality", "canonflashmode", "continuousdrive", "focusmode", "lenstype", "cameratemperature", "cameratype", "canonimagetype", "canonfirmwareversion", "ownername", "cameraorientation", "focusdistanceupper", "focusdistancelower"]
# reading the data
reader = MultiExiftool::Reader.new
reader.tags = tags
reader.filenames = Dir['*.jpg']
results = reader.read
@janfri
janfri / l
Created March 20, 2014 12:19
A script to execute ls if $1 is a directory or less if $1 is a file.
#!/bin/sh
if [ -d $1 ]; then
ls -l $1
elif [ -f $1 ]; then
less -S $1
fi
Dir['**/*.html'].each do |filename|
puts filename
data = File.read(filename).encode('UTF-8')
File.open(filename, 'w') do |handle|
handle.write(data)
end
end; nil
def safe_assert_equal expected, actual
assert_equal expected, actual
rescue Exception=>e
puts e
end
class Testable < Test::Unit::TestCase
def test_something
safe_assert_equal 1, 2
end