Skip to content

Instantly share code, notes, and snippets.

View matisojka's full-sized avatar

Mateusz Sójka matisojka

View GitHub Profile
#!/bin/bash
set -e
CONTENTS=$(tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/tessdata/ "$1" stdout -l eng | xml esc)
hex=$((cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@voondo
voondo / scaleway-inventory.rb
Created February 19, 2016 11:11
Scaleway ansible dynamic inventory
#!/bin/ruby
require 'json'
require 'optparse'
require 'net/http'
require 'pry'
require 'yaml'
auth_token = ENV['SCALEWAY_AUTH_TOKEN']
uri = URI('https://api.scaleway.com/servers')
@kristopolous
kristopolous / hn_seach.js
Last active July 24, 2023 04:12
hn job query search
// Usage:
// Copy and paste all of this into a debug console window of the "Who is Hiring?" comment thread
// then use as follows:
//
// query(term | [term, term, ...], term | [term, term, ...], ...)
//
// When arguments are in an array then that means an "or" and when they are seperate that means "and"
//
// Term is of the format:
// ((-)text/RegExp) ( '-' means negation )
@matisojka
matisojka / memory_cache.rb
Last active August 29, 2015 14:11
In-memory cache with key limit
class MemoryCache
DEFAULT_MAX_KEYS = 5000
attr_reader :data, :max_keys
def initialize(config)
@data = {}
@max_keys = config[:max_cache_keys] || DEFAULT_MAX_KEYS
@lock = Mutex.new
@podlech
podlech / yosemite_ruby_libv8_therubyracer.sh
Last active November 1, 2016 11:02
OS X Yosemite ruby (1.9.3p484) libv8 (3.11.8.17) therubyracer (0.11.4)
brew install homebrew/dupes/apple-gcc42
rbenv install 1.9.3-p484
rbenv global 1.9.3-p484
git clone https://github.com/cowboyd/libv8.git
cd libv8
git checkout 3.11
export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2
bundle install
@ream88
ream88 / Rakefile
Created July 18, 2012 11:24
Minitest rake task
require 'rake'
require 'rake/testtask'
Rake::TestTask.new do |t|
t.test_files = Dir.glob('spec/**/*_spec.rb')
end
task(default: :test)
@matisojka
matisojka / measure_gem_loading_time.rb
Created July 4, 2012 07:05
Measure Gem loading time in your Rails APP
# Disclaimer: this solution has been taken from the post: http://stackoverflow.com/a/5071198/784270
# navigate to the bundler gem and in lib/bundler/runtime.rb,
# find the line that does Kernel.require and wrap it like this
puts Benchmark.measure("require #{file}") {
Kernel.require file
}.format("%n: %t %r")
# Add
@marktheunissen
marktheunissen / pedantically_commented_playbook.yml
Last active April 26, 2024 23:26 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
This playbook has been removed as it is now very outdated.
@matisojka
matisojka / valid_json.rb
Created March 29, 2012 11:36 — forked from carlcrott/gist:2218175
JSON validation method (without monkey patching and with proper error handling)
def valid_json?(value)
JSON.parse value
true
rescue JSON::ParserError, TypeError
false
end
@kagemusha
kagemusha / gist:1569836
Created January 6, 2012 09:20
Dump Heroku Postgres DB and load locally
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump