Skip to content

Instantly share code, notes, and snippets.

View eliotsykes's full-sized avatar

Eliot Sykes eliotsykes

View GitHub Profile
@maxivak
maxivak / webpacker_rails.md
Last active April 13, 2023 18:46
Webpack, Yarn, Npm in Rails
@eliotsykes
eliotsykes / angularjs-rails-apps.md
Last active August 1, 2017 18:17
AngularJS Rails apps

Open Source AngularJS Rails Apps

Expect some false positives here, but hopefully most of these are open source Rails apps that use (or once used) AngularJS.

If you'd like to help update the list, please comment below with any of these apps you discover do not use AngularJS and include my username (@eliotsykes) in your message.

Confirmed using AngularJS

@eliotsykes
eliotsykes / multiline_expressions_in_ruby.md
Last active September 28, 2023 08:03
Multiline expressions in Ruby

How to break long lines up in Ruby

This page lists the options for breaking single-line expressions into multiple lines in Ruby.

Developers and teams need to come to their own decisions about which guideline(s) they prefer (preferences below are just my personal choices and I encourage you to disregard them).

# With trailing parens
x = [1, 2, 3].join(
 '-'
@rilian
rilian / config-environments-test.rb
Last active October 5, 2019 07:49 — forked from keithtom/no_animations.rb
Rack Middleware to disable Disable CSS3/jQuery Animations for Capybara
Rails.application.configure do
# ...
require_relative '../../spec/support/no_animations'
config.middleware.use Rack::NoAnimations
end
@alekseyg
alekseyg / stripe.js
Created March 15, 2017 22:03
What Stripe.applePay.checkAvailability actually does
Stripe.applePay.checkAvailability = function (callback) {
if (location.protocol === 'https:') {
var canMakePayments = window.ApplePaySession && ApplePaySession.canMakePayments()
if (/^pk_test_/.test(Stripe.key || Stripe.publishableKey)) {
callback(canMakePayments)
} else if (canMakePayments) {
var merchantId = "merchant." + window.location.hostname + ".stripe"
ApplePaySession.canMakePaymentsWithActiveCard(merchantId).then(callback)
} else {
@eliotsykes
eliotsykes / logger.js
Last active March 13, 2017 10:53
Logging JavaScript client-side to floating div
// Requires jQuery
var logger = {
setup: function() {
$('<div style="position:fixed; top: 0; left: 0; width: 100%; background-color: white;"><pre id="log-output" style="max-height: 70px; font-size: 10px; line-height: 12px;"></pre></div>')
.appendTo('body');
this.logOutput = $('#log-output');
},
info: function(msg) { this.logOutput.prepend(msg + "\n"); },
hide: function() { this.logOutput.parent().hide(); },
show: function() { this.logOutput.parent().show(); }
@eliotsykes
eliotsykes / api_controller.rb
Last active May 10, 2022 03:59
Token Authentication in Rails API Controller and Request Spec
# File: app/controllers/api/api_controller.rb
class Api::ApiController < ActionController::Base
# Consider subclassing ActionController::API instead of Base, see
# http://api.rubyonrails.org/classes/ActionController/API.html
protect_from_forgery with: :null_session
before_action :authenticate
def self.disable_turbolinks_cookies
skip_before_action :set_request_method_cookie
@eliotsykes
eliotsykes / cloud9-postgresql-rails-howto.md
Last active December 20, 2021 13:28
How to setup PostgreSQL & Rails on Cloud9

How to setup PostgreSQL & Rails on Cloud9

At time of writing, Cloud9 has PostgreSQL pre-installed, so you won't need to install it yourself. However, its not running by default, so you will need to start it with this command in the terminal:

sudo service postgresql start

Change the PostgreSQL password to 'password' (or choose a different password):

@eliotsykes
eliotsykes / deploy
Last active January 4, 2016 20:50
bin/deploy for rails+heroku app
#!/bin/sh
# Create this file in the bin/ directory of your
# Rails app.
# Run this script to deploy the app to Heroku.
set -e
# Push changes to Heroku
@eliotsykes
eliotsykes / naive_hash.rb
Last active January 6, 2016 16:46
Evolving NaiveHash into RubyHash
# Copy NaiveHash (end of this file) and rename to RubyHash.
#
# Try using RubyHash in irb/pry and store some data in it
# and notice it has problems with remembering all of your data due
# to RubyHash not handling hash collisions:
#
# require_relative 'ruby_hash'
# h = RubyHash.new
# ('a'..'z').each do |char|
# h[char] = char.upcase