Skip to content

Instantly share code, notes, and snippets.

View equivalent's full-sized avatar
:octocat:
I'm IDDQD + IDKFA for Ruby on Rails

Tomas Valent equivalent

:octocat:
I'm IDDQD + IDKFA for Ruby on Rails
View GitHub Profile
module SessionSystemTestHelper
def sign_in_as(user)
visit root_url # any fast-to-load page will do
cookie_jar = ActionDispatch::TestRequest.create.cookie_jar
cookie_jar.signed[:session_token] = user.sessions.create.token
page.driver.browser.manage.add_cookie(name: "session_token", value: cookie_jar[:session_token], sameSite: :Lax, httpOnly: true)
end
end
@brenogazzola
brenogazzola / direct_upload.js
Created January 20, 2022 23:41
Active Storage Direct Upload Progress
import Rails from '@rails/ujs'
const DirectUpload = {
start () {
document.addEventListener('direct-upload:initialize', DirectUpload.initialize)
document.addEventListener('direct-upload:start', DirectUpload.begin)
document.addEventListener('direct-upload:progress', DirectUpload.progress)
document.addEventListener('direct-upload-error', DirectUpload.error)
document.addEventListener('direct-upload:end', DirectUpload.end)
},
@dteoh
dteoh / rspec_rails_set_session.md
Created May 29, 2020 07:49
Setting session variables in an RSpec Rails request spec

Setting session variables in an RSpec Rails request spec

You are writing a spec with type: :request, i.e. an integration spec instead of a controller spec. Integration specs are wrappers around Rails' ActionDispatch::IntegrationTest class. I usually write controller tests using this instead of type: :controller, mainly because it exercises more of the request and response handling stack. So instead of writing something like get :index to start the request, you would write get books_path or similar.

One of the issues with using type: :request is that you lose the ability to

@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active April 19, 2024 04:06
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@amirrajan
amirrajan / subspace.rb
Created February 27, 2019 21:50
Initial work for a subspace clone written on top of a game engine I'm working out that hasn't been released yet.
class Game
attr_accessor :_
def default_ship x, y, heading
_.new(:ship) do |s|
s.x = x
s.y = y
s.dy = 0
s.dx = 0
s.heading = heading
@JasonTrue
JasonTrue / searchkick_and_elasticsearch_guidance.md
Last active March 7, 2024 14:42
Searchkick and Elastic Search guidance

Resources:

https://github.com/ankane/searchkick

Indexing

By default, simply adding the call 'searchkick' to a model will do an unclever indexing of all fields (but not has_many or belongs_to attributes).

In practice, you'll need to customize what gets indexed. This is done by defining a method on your model called search_data

def search_data

@shoesCodeFor
shoesCodeFor / selenium-webdriver-cheatsheet.md
Last active February 13, 2024 21:43 — forked from huangzhichong/selenium-webdriver-cheatsheet.md
Ruby Selenium Webdriver CheatSheet

API workthough

  1. Open a browser

    # start an instance of firefox with selenium-webdriver
    driver = Selenium::WebDriver.for :firefox
    # :chrome -> chrome
    # :ie     -> iexplore
    
@phoebebright
phoebebright / index.html
Created July 18, 2018 10:14
Materialize AutoComplete with id
<div class="row">
<div class="col s12">
<div class="row">
<div class="input-field col s13">
<i class="material-icons prefix">textsms</i>
<input type="text" id="autocomplete" class="autocomplete" >
<label for="autocomplete">Autocomplete</label>
</div>
</div>
</div>
@r00takaspin
r00takaspin / puma.service
Created May 11, 2018 15:29
Run puma web server with RVM from systemd
[Unit]
Description=Puma HTTP Server
After=network.target
# Uncomment for socket activation (see below)
# Requires=puma.socket
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple