Skip to content

Instantly share code, notes, and snippets.

View adamcrown's full-sized avatar

Adam Crownoble adamcrown

View GitHub Profile
@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

@giannisp
giannisp / gist:ebaca117ac9e44231421f04e7796d5ca
Last active March 1, 2024 14:39
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@denji
denji / README.md
Last active April 5, 2024 10:03 — forked from Cubixmeister/README.md
Simple Sentry docker-compose.yml
  1. Download docker-compose.yml to dir named sentry
  2. Change SENTRY_SECRET_KEY to random 32 char string
  3. Run docker-compose up -d
  4. Run docker-compose exec sentry sentry upgrade to setup database and create admin user
  5. (Optional) Run docker-compose exec sentry pip install sentry-slack if you want slack plugin, it can be done later
  6. Run docker-compose restart sentry
  7. Sentry is now running on public port 9000
@tony-gutierrez
tony-gutierrez / AWS_Single_LetsEncrypt.yaml
Last active March 7, 2024 11:29
AWS Elastic Beanstalk .ebextensions config for single instance free SSL using letsencrypt certbot and nginx. http://bluefletch.com/blog/domain-agnostic-letsencrypt-ssl-config-for-elastic-beanstalk-single-instances/
# Dont forget to set the env variable "certdomain", and either fill in your email below or use an env variable for that too.
# Also note that this config is using the LetsEncrypt staging server, remove the flag when ready!
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
@aresnick
aresnick / index.html
Last active October 22, 2021 12:58
Google Drive Export Client Side Export Example
<html>
<head>
<script type="text/javascript">
// Your Client ID can be retrieved from your project in the Google
// Developer Console, https://console.developers.google.com
var CLIENT_ID = '436763072331-rod105o2ppkpjrcdpsmrvmn2st3qg9el.apps.googleusercontent.com';
var SCOPES = ['https://www.googleapis.com/auth/drive.readonly'];
@hiasinho
hiasinho / factory_girl_strategy_find_or_create.rb
Last active May 27, 2020 18:31
FactoryGirl strategy for adding find & find_or_create
## http://stackoverflow.com/questions/7145256
module FactoryGirl
module Strategy
class Find
def association(runner)
runner.run
end
def result(evaluation)
build_class(evaluation).where(get_overrides(evaluation)).first
@longlostnick
longlostnick / uploads_controller.rb
Created June 17, 2014 18:20
Rails JSON file upload with carrierwave (from base64 string)
class Api::UploadsController < ApiController
def create
@upload = Upload.new(upload_params)
ensure
clean_tempfile
end
private
@adamcrown
adamcrown / upay.css
Last active December 16, 2015 21:59
Bootstrap style uPay CSS
* { margin: 0; }
html, body { height: 100%; font-family: Arial, Helvetica, sans-serif; }
body { background: #f5f5f5; }
img { border-style: none; font-weight: normal; }
a:link, a:visited { color: #009; font-weight: bold; text-decoration: none; }
a:hover, a:active { color: #6cb33f; font-weight: bold; text-decoration: none; outline: none; }
a:focus, a:active { outline: none; }
:focus { outline-style: none; }
.clear { clear: both; margin: 0px; padding: 0px; height: 1px; }
p { color: #333; margin: 0px 0px 5px; font-size: 0.8em; display: block; width: 100%; }
@rsierra
rsierra / 1ST README.md
Last active December 11, 2015 21:38
Rails < 2.3 patch for CVE-2013-0333 vulnerability

Rails < 2.3 patch for CVE-2013-0333 vulnerability:

  • Add CVE-2013-0333_patch.rb in '/config/initializers' directory.
  • Add okjson.rb in '/lib' directory.

To test the parser, try to decode with a bad formatted json: (I don't know if it's the best test, but you check if you are using the json parser in the rails 2.3 official patch)

  • In console, before patch:
@adamcrown
adamcrown / active_record_sessions_batch_delete.rb
Last active December 11, 2015 00:18
Deleting a large batch of session records can really overload the DB (at least MySQL). This script paces it out a bit.
def batch_session_prune(keep_after = 1.month.ago, batch_by = 1.day, pause_time = 10)
time = ActiveRecord::SessionStore::Session.order(:updated_at).first[:updated_at]
while time < keep_after
time = time + batch_by
puts "Deleting sessions from #{time.to_s(:short)}"
ActiveRecord::SessionStore::Session.where('updated_at < ?', time).delete_all
sleep pause_time