Skip to content

Instantly share code, notes, and snippets.

View martinstreicher's full-sized avatar
🎯
Focusing

Martin Streicher martinstreicher

🎯
Focusing
View GitHub Profile
@martinstreicher
martinstreicher / gist:64edd3821b4caf5806a24cf8c72355cc
Last active December 18, 2024 17:28
Service class bare bones
# frozen_string_literal: true
#
# Example usage:
# result = Gizmo.call(**params)
# result.success? ? succeed_path : failure_path
# This service class:
# Is based on the Interactor gem
# * Validates its parameters using ActiveRecord pieces
@martinstreicher
martinstreicher / request.rb
Created April 16, 2024 15:17
A sample base class for HTTP requests
# frozen_string_literal: true
require "net/http"
module Client
RequestError = Class.new(StandardError)
class Request
DEFAULT_HOSTNAME = "localhost"
DEFAULT_PORT = 80

Keybase proof

I hereby claim:

  • I am martinstreicher on github.
  • I am martinstreicher (https://keybase.io/martinstreicher) on keybase.
  • I have a public key ASA48hi-YA9SlOV7DlZt_vEOvMW9jzLyOLqNCC0w2qta_go

To claim this, I am signing this object:

@martinstreicher
martinstreicher / gist:c22363334aae8673d5d27b60787a2856
Created March 19, 2018 16:54
Connect Codeship to a local install of MySQL 5.7
#
# Setup
export MYSQL_DIR="$HOME/mysql-5.7"
export MYSQL_PORT="3307"
export MYSQL_SOCKET="$MYSQL_DIR/socket/mysqld.sock"
export PATH="$MYSQL_DIR/bin:$PATH"
export RAILS_ENV=test
\curl -sSL https://raw.githubusercontent.com/codeship/scripts/master/packages/mysql-5.7.sh | bash -s
# If `.ruby-version` file is present, RVM will set Ruby to the declared version.
if [ -f .ruby-version ]; then rvm use $(cat .ruby-version) --install; fi
@martinstreicher
martinstreicher / sidekiq_exception_worker.rb
Created September 28, 2017 20:52
Sidekiq Middleware to squelch some errors
module Middleware
SquelchedException = Class.new Exception
class SidekiqExceptionHandler
def call(worker, job, queue)
yield
rescue Exception => exception
notify exception, job, ignore: ignore_exception?(exception)
raise SquelchedException
end
define([
'mapbox-gl-supported'
], function(
isMapboxGlSupported
) {
// the function that will load the map code and initialize
// the map, or if the map code has been loaded, just
// initialize the map.
var loadAndInitMap;
class Device < ActiveRecord::Base
belongs_to :participant
validates :participant, presence: true
validates :provider, presence: true
validates :serial_number, presence: true, uniqueness: { scope: :provider }
validates :serial_number, format: { with: /\A\d{15}\z/, message: 'IMEI must be 15 digits'},
if: lambda { |d| d.provider == 'bodytrace' }
before_validation :normalize
@martinstreicher
martinstreicher / gist:a29530a7989b916e2cc5
Created December 22, 2015 17:23
Output of VCR matching
[webmock] Handling request: [get https://maps.google.com/maps/api/geocode/json?address=613%20Wolf%20Crescent,Lake%20Mandychester,New%20Hampshire&sensor=false] (disabled: false)
[webmock] Identified request type (recordable) for [get https://maps.google.com/maps/api/geocode/json?address=613%20Wolf%20Crescent,Lake%20Mandychester,New%20Hampshire&sensor=false]
[webmock] Handling request: [get https://maps.google.com/maps/api/geocode/json?address=9341%20Wiegand%20Gardens,Wavabury,New%20York&sensor=false] (disabled: false)
[webmock] Identified request type (recordable) for [get https://maps.google.com/maps/api/geocode/json?address=9341%20Wiegand%20Gardens,Wavabury,New%20York&sensor=false]
[Cassette: 'cms/sms_08'] Initialized with options: {:record=>:once, :match_requests_on=>[:uri, :method], :allow_unused_http_interactions=>true, :serialize_with=>:yaml, :persist_with=>:file_system, :allow_playback_repeats=>false}
[webmock] Handling request: [get https://maps.google.com/maps/api/geocode/json?address=469%20Bill%20Tra
@martinstreicher
martinstreicher / gist:1935754
Created February 28, 2012 22:37
Log of Lion build
Colossus-2:realvolve strike$ cat !$
cat /Users/strike/.rvm/log/ruby-1.9.3-p125/make.log
[2012-02-28 17:27:22] make
CC = clang
LD = ld
LDSHARED = clang -dynamiclib
CFLAGS = -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration -fno-common -pipe
XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I. -I.ext/include/x86_64-darwin11.3.0 -I./include -I.
DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -install_name /Users/strike/.rvm/rubies/ruby-1.9.3-p125/lib/libruby.1.9.1.dylib -current_version 1.9.1 -compatibility_version 1.9.1 -Wl,-unexported_symbol,_Init_* -Wl,-unexported_symbol,*_threadptr_* -Wl,-u,_objc_msgSend
@martinstreicher
martinstreicher / gist:1431262
Created December 4, 2011 21:02
Controller test
require 'spec_helper'
describe AccountsController do
before :each do
@user = create :user_with_requested_subdomain
@request.host = "#{@user.subdomain}.local"
end
describe 'authenticate_user!' do
it 'precludes access unless logged in' do