Skip to content

Instantly share code, notes, and snippets.

View claudiug's full-sized avatar
💜
I eat stickers all the time, dude.

Klaus Heissler claudiug

💜
I eat stickers all the time, dude.
  • cto@relatico
  • Berlin
View GitHub Profile
#!/usr/bin/env bash
function generate_tags {
(ctags -R -f .tags 2> /dev/null &)
}
function generate_gemtags {
(bundle show --paths | xargs ctags -R -f .gemtags 2> /dev/null &)
}
require 'rubygems'
require 'httparty'
require 'benchmark'
require 'thread'
class Google
include HTTParty
base_uri 'http://google.com'
def self.benchmark
@claudiug
claudiug / gist:41af2ad400071b9d00ded420973b07ef
Created January 24, 2017 19:50 — forked from acwright/gist:1944639
Sinatra / ActionMailer / Sendgrid / Heroku
require 'sinatra'
require 'action_mailer'
class Mailer < ActionMailer::Base
def contact
mail(
:to => "test@example.com",
:from => "test@example.com",
:subject => "Test") do |format|
format.text
@claudiug
claudiug / output.txt
Created September 19, 2019 19:00 — forked from headius/output.txt
JRuby's new --environment flag
[] ~/projects/jruby $ jruby.bash --environment --dev
JRuby Environment
=================
JRuby executable:
/Users/headius/projects/jruby/bin/jruby.bash
JRuby command line options:
--environment --dev
Environment:
#contents of sample.rb
cat sample.rb
require './before'
puts "Hello World!"
#contents of before.rb
cat before.rb
puts "Before..."
#running:
@claudiug
claudiug / app.rb
Created February 6, 2020 15:50 — forked from jgaskins/app.rb
API app with Roda
require 'authentication'
class MyApp < Roda
include Authentication
plugin :json
route do |r|
r.on('docs') { r.run Docs }
@claudiug
claudiug / missing_indices.sql
Created April 7, 2020 20:35 — forked from consti/missing_indices.sql
Find missing indices in postgres
SELECT relname, seq_scan-idx_scan AS too_much_seq, case when seq_scan-idx_scan>0 THEN 'Missing Index?' ELSE 'OK' END, pg_relation_size(relname::regclass) AS rel_size, seq_scan, idx_scan
FROM pg_stat_all_tables
WHERE schemaname='public' AND pg_relation_size(relname::regclass)>80000 ORDER BY too_much_seq DESC;
module Slug
def self.customize(field: :name)
Module.new do
define_method :to_param do
public_send(field).downcase.gsub /\W+/, '-'
end
end
end
end

Faster Rails tests

Feedback loop speed in one of the biggest contributing factors to overall development time. The faster you get results, the faster you can move on to other things. A fast enough test suite is therefore critical to teams' success, and is worth investing some time at the beginning to save in the long run.

Below is a list of techniques for speeding up a Rails test suite. It is not comprehensive, but should definitely provide some quick wins. This list of techniques assumes you're using minitest, but most everything should translate over to rspec by simply replacing test/test_helper.rb with spec/spec_helper.rb.

@claudiug
claudiug / idb-backup-and-restore.md
Created March 31, 2021 16:35 — forked from loilo/idb-backup-and-restore.md
Back up and restore an IndexedDB database

Back up and restore an IndexedDB database

This gist is an ES module which provides functions to import and export data from an IndexedDB database as JSON. It's based on Justin Emery's indexeddb-export-import package, but applies some adjustments that reflect better on the current browser landscape (i.e. better developer ergonomics but no support for Internet Explorer).

Usage

For each of the provided functionalities, you need a connected IDBDatabase instance.

Export Data

import { idb } from 'some-database'