# Creating a lambda
l = lambda { |name| "Hi #{name}!" }
# Executing the lambda
l.call("foo") # => Hi foo!
import code; code.interact(local=dict(globals(), **locals())) |
# In controller | |
result = TaxCalculator.new(order).call | |
if result[:success] | |
render json: { value: result[:value] } | |
else | |
render json: { errors: result[:errors] }, status: 422 | |
end | |
# The service | |
class TaxCalculator |
class API::V1::BaseController < ApplicationController | |
skip_before_filter :verify_authenticity_token | |
before_filter :cors_preflight_check | |
after_filter :cors_set_access_control_headers | |
def cors_set_access_control_headers | |
headers['Access-Control-Allow-Origin'] = '*' | |
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS' |
Command Line
pry -r ./config/app_init_file.rb
- load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb
- load your rails into a pry session
Debugger
// === Arrays | |
var [a, b] = [1, 2]; | |
console.log(a, b); | |
//=> 1 2 | |
// Use from functions, only select from pattern | |
var foo = () => [1, 2, 3]; |
# Install ARCH Linux with encrypted file-system and UEFI | |
# The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description. | |
# Download the archiso image from https://www.archlinux.org/ | |
# Copy to a usb-drive | |
dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux | |
# Boot from the usb. If the usb fails to boot, make sure that secure boot is disabled in the BIOS configuration. | |
# Set swedish keymap |
RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.
On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.
So, many developers have started going straight t
#Getting Started
##Webpage:
<html>
<head>
<title>Testing with Ruby and Selenium WebDriver</title>
</head>
<body bgcolor="antiquewhite">
<h2>Sign up</h2> | |
<div id="stripe_error" class="alert alert-error" style="display:none" > | |
</div> | |
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'card_form form-vertical' }) do |f| %> | |
<h3><%= params[:plan].titleize if params[:plan] %> Subscription Plan</h3> | |
<%= hidden_field_tag 'plan', params[:plan] %> | |
<%= f.error_notification %> | |
<%= f.input :f_name, :autofocus => true %> | |
<%= f.input :l_name %> | |
<%= f.input :email, :required => true %> |