Skip to content

Instantly share code, notes, and snippets.

@jvillarejo
jvillarejo / retry_until_timeout_spec.rb
Created January 7, 2022 22:38
A timeout for failing specs when using turbo frames and hotwire
# This is how we use it
retry_until_timeout do
expect(page).to have_button('Add comment')
expect(page).to have_text('Cancell')
end
def retry_until_timeout(seconds = 10, message: 'Failed with timeout')
Timeout.timeout(seconds) do
loop do
yield
@Treeki
Treeki / TurnipPrices.cpp
Last active November 1, 2024 14:15
AC:NH turnip price calculator
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// munged from https://github.com/simontime/Resead
namespace sead
{
class Random
{
@0xjmp
0xjmp / Procfile
Last active July 18, 2020 15:21
How to set up a Rails and Webpack app for fun and profit
api: sh -c "cd api && bundle exec rails s -p5000"
nginx: /usr/bin/nginx -c nginx.conf
client: sh -c "cd client && npm start"
#!/usr/bin/env ruby
# frozen_string_literal: true
# README
# - gem install git
# - Update the ticket prefix
# - Update the branch name
# - Put this in /usr/local/bin and chmod +x it
require 'git'
@bbonamin
bbonamin / Brewfile
Last active August 18, 2024 09:26
Capybara Selenium Webdriver: Headless Chrome (with file downloads!) & Headless Firefox
tap "caskroom/cask"
cask "google-chrome"
cask "firefox"
brew "chromedriver"
brew "geckodriver"
@naoyamakino
naoyamakino / railsConfShopifyScaling.md
Created May 2, 2013 20:31
How Shopify Scales Rails via @johnduff #railsConf

How Shopify Scales Rails John Duff

The Stack:

  • ruby1.9.3-p327
  • rails3.2
  • unicorn 4.5
  • percona Mysql5.5
  • memcache14.14
  • redis2.6

33 app servers, 1172 unicorn workers, 5 job servers, 370 job workers

@jaymcgavren
jaymcgavren / javascript_objects.md
Last active September 12, 2018 09:23
In this screencast, Jay McGavren gives you a clear, no-nonsense look at Javascript objects. You'll learn how properties and functions are woven together to make a complete object. You'll learn what's special about constructor functions (not that much), and how prototypes form the basis for creating new objects. If you're ready to take the next s…

Objects

To create a new object, use the new keyword followed by a call to a constructor function. Javascript provides the Object() constructor out-of-the-box:

var toilet = new Object();

Properties

Once you have an object, you can set and get properties on it, like this:

@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base
@jhjguxin
jhjguxin / creating-nested-resources-in-ruby-on-rails-3-and-updating-scaffolding-links-and-redirection.markdown
Created July 9, 2012 03:32
Creating nested resources in ruby on rails 3 and updating scaffolding links and redirection
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection