Skip to content

Instantly share code, notes, and snippets.

@scalaview
scalaview / gist:b0e6e3f76418f1a87e9c1b63e9bfffcb
Created August 14, 2021 15:21 — forked from markbates/gist:4240848
Getting Started with Rack

If you're writing web applications with Ruby there comes a time when you might need something a lot simpler, or even faster, than Ruby on Rails or the Sinatra micro-framework. Enter Rack.

Rack describes itself as follows:

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Before Rack came along Ruby web frameworks all implemented their own interfaces, which made it incredibly difficult to write web servers for them, or to share code between two different frameworks. Now almost all Ruby web frameworks implement Rack, including Rails and Sinatra, meaning that these applications can now behave in a similar fashion to one another.

At it's core Rack provides a great set of tools to allow you to build the most simple web application or interface you can. Rack applications can be written in a single line of code. But we're getting ahead of ourselves a bit.

@scalaview
scalaview / saga.rb
Created February 27, 2021 15:39 — forked from sclinede/saga.rb
Example of Full Saga implementation in Ruby (with Usage example, also)
class Saga
class << self
def with_redis; raise NotImplementedError; end
attr_accessor :cleanup_delay, :queue, :last_txid
def queue
Thread.current[:saga_queue] ||= []
end
def last_txid
@scalaview
scalaview / pipelines.rb
Created February 27, 2021 15:37 — forked from sclinede/pipelines.rb
Sagas implementation in pure Ruby (pre-DirtyPipelines gem)
class DirtyPipeline::Action
module WrappedCall
def call
Events.publish! Event.generate(self)
super
end
end
class << self
attr_accessor :attempted_event_klass, :pipeline, :timeout
@scalaview
scalaview / README.md
Created February 2, 2021 08:17 — forked from chuyik/README.md
macOS 给 Git(Github) 设置代理(HTTP/SSH)
@scalaview
scalaview / GitConfigHttpProxy.md
Created October 21, 2020 13:20 — forked from evantoli/GitConfigHttpProxy.md
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@scalaview
scalaview / lxml build script
Created June 2, 2019 13:45
macOS 10.13.4 lxml does not build with Xcode 9
from lxml import etree
get error:
ImportError: dlopen(/etc/locale/lib/python3.6/site-packages/lxml/etree.cpython-36m-darwin.so, 2): Symbol not found: __PyErr_FormatFromCause
solution:
pip uninstall lxml
python3 -mvenv /tmp/lxml
source /tmp/lxml/bin/activate
pip install lxml --no-binary :all:
@scalaview
scalaview / gist:cc271669dd46fc0eecee9fcef101e8a1
Created October 24, 2018 13:52 — forked from ryanlecompte/gist:1283413
Providing an ActiveRecord-like before_filter capability to arbitrary Ruby classes
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end
@scalaview
scalaview / clear-sidekiq-jobs.sh
Created October 9, 2018 07:23 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
@scalaview
scalaview / shared.rb
Created September 16, 2018 15:13 — forked from pbosetti/shared.rb
IPC shared memory access via FFI
#!/usr/bin/env ruby
# untitled.rb
# Created by Paolo Bosetti on 2011-04-22.
# Copyright (c) 2011 University of Trento. All rights reserved.
require "rubygems"
require 'ffi'
module Shared
@scalaview
scalaview / Casino.sol
Created March 15, 2018 15:18 — forked from anonymous/Casino.sol
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.21+commit.dfe3193c.js&optimize=false&gist=
pragma solidity ^0.4.10;
contract Ownable {
address owner;
function Ownable() public {
owner = msg.sender;
}
modifier Owned {
require(msg.sender == owner);