Skip to content

Instantly share code, notes, and snippets.

View vinzenzweber's full-sized avatar
👋
I may be slow to respond.

Vinzenz Weber vinzenzweber

👋
I may be slow to respond.
View GitHub Profile
@vinzenzweber
vinzenzweber / sshtunnel.rb
Last active March 3, 2020 10:25
Connect to a private PostgreSQL database through an SSH tunnel using Ruby
require 'active_record'
require 'net/ssh/gateway'
class CombinedHCP < ActiveRecord::Base
self.table_name = 'schema.tablename'
self.primary_key = 'uuid'
end
# set password nil to use public key authentication
# as an alternative to using the local ~/.ssh/config, you can also supply all host parameters directly
@vinzenzweber
vinzenzweber / Gemfile
Last active March 3, 2020 10:25
Connect to hidden PostgreSQL database through SSH tunnel using Ruby
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.7'
gem 'activerecord'
gem 'net-ssh-gateway'
@vinzenzweber
vinzenzweber / slack.rb
Last active August 5, 2019 14:35
Post text notifications to a Slack channel using a webhook https://api.slack.com/incoming-webhooks
# frozen_string_literal: true
# 1. Manage your Slack apps at https://your_slack_team_name.slack.com/apps/manage
# 2. Create an 'Incoming WebHooks' configuration
require 'net/http'
require 'json'
class Slack
def self.post(text, channel = '#channel', username = 'default username')
@vinzenzweber
vinzenzweber / create_uzn.rb
Last active June 22, 2019 20:47
Extract text from an image called filename.jpeg using tesseract within a docker container. The image contains german text, therefore `-l deu`. The text regions or zones are defined by `filename.uzn`. The image filename and the .uzn filename have to be identical for this to work!
Dir['./books/*/*/*.jpeg'].each do |file_path|
next if File.directory? file_path
file_name = file_path.sub('.jpeg', '.uzn')
puts "OCR #{file_name}"
uzn_content = """2385 1059 273 201 Energie
2634 1080 372 210 Kohlenhydrate
2961 1062 294 234 Fett
3204 1080 321 186 Eiweiss
2030 1500 800 960 Zutaten
@vinzenzweber
vinzenzweber / j.sh
Last active March 16, 2019 20:30
arch
#!/bin/sh
cd /
umount /sys/firmware/efi/efivars/
mount -t efivarfs rw /sys/firmware/efi/efivars/
cd /sys/firmware/efi/efivars/
chattr -i "gpu-power-prefs-*"
rm gpu-power-prefs-*
printf "\x07\x00\x00\x00\x01\x00\x00\x00" > /sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9
@vinzenzweber
vinzenzweber / mup.json
Last active July 19, 2016 08:55
Meteor mupx settings for EC2 using SSL certificates
{
"servers": [
{
"host": "myapplication.com",
"username": "ubuntu",
"pem": "~/.ssh/keypair.pem"
}
],
"setupMongo": true,
"setupNode": true,
Process: GitX [53299]
Path: /Applications/GitX.app/Contents/MacOS/GitX
Identifier: nl.frim.GitX
Version: 0.8.4 (0.8.4)
Code Type: X86-64 (Native)
Parent Process: launchd [314]
User ID: 502
Date/Time: 2012-03-21 15:27:23.377 +0100
OS Version: Mac OS X 10.8 (12A128p)
@vinzenzweber
vinzenzweber / AppDelegate.m
Created March 9, 2012 14:47
RestKit mapping using primary key
///////////////////////////////////////
// Categories - Exercises
NSArray *categoriesMap = [NSArray arrayWithObjects:@"uid", @"text_de", @"text_en", nil];
RKManagedObjectMapping *exerciseLevelMapping = [RKManagedObjectMapping mappingForClass:[ExerciseLevel class]];
@vinzenzweber
vinzenzweber / gist:1751941
Created February 6, 2012 13:01
CoreData - One method to conquer them all! Create fetch reeuests from string predicates.
/**
* Return an array with objects found in the local database for the given predicate.
*/
-(NSArray *)fetchEntity:(NSString *)entityName withPredicateFormat:(NSString *)format, ... {
NSManagedObjectContext *managedObjectContext = [RKObjectManager sharedManager].objectStore.managedObjectContext;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName
inManagedObjectContext:managedObjectContext];
@vinzenzweber
vinzenzweber / git-version
Created January 16, 2012 08:45
Get the latest git tag and git commit count for automated build scripts.
git=`which git`
gittag=`git describe --abbrev=0 --tags` #`$git describe --tags --always`
gitcount=`$git rev-list --all | wc -l | tr -cd '[[:digit:]]'`