Skip to content

Instantly share code, notes, and snippets.

View MyklClason's full-sized avatar

Mykl Clason MyklClason

  • Wisconsin, United States
View GitHub Profile
@MyklClason
MyklClason / audit.yml
Last active April 18, 2016 04:39
rails-audit
Rubocop:
#Parameters: '-D -E --auto-gen-config --auto-correct'
Parameters: '-D -E --auto-gen-config'
Breakman:
Parameters: '-A -q --summary'
Cane:
Parameters: ''
@MyklClason
MyklClason / geolocation-demo.html
Created April 25, 2016 18:46
geolocation use demo
<div id="demo"></div>
<button onclick="getLocation()">Click to show location</button>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
@MyklClason
MyklClason / useful-heroku-addons.md
Last active May 24, 2016 13:05
(Potentially) Useful Heroku Addons (Focused on Ruby Apps)
  • AppSignal: Improve performance, debug errors and track deploys for your Ruby on Rails apps
  • Honeybadger: Modern error management and performance monitoring for web applications
  • Informant: Usability monitoring for Ruby on Rails.
  • Raygun: Real time error reporting you can set up in under 5 minutes!
  • Keen IO: Analytics for Developers
  • DbInsights: Business intelligence insights and analytics from your database
  • IronWorker: Highly available and scalable task queue / worker service.
    • Free version seems only suitable for very small scale tasks. Better to use Que if scheduled size expected to exceed 5.
  • QuotaGuard: Proxy Your API
@MyklClason
MyklClason / ajax.js.erb
Last active November 7, 2017 01:48
Simple way to handle Bootstrap flash messages when using AJAX and the twitter-bootstrap-rails gem.
// The below must be included somewhere in in .js.erb file.
...
$('#bootstrap-flash').html("<%= j (bootstrap_flash) %>");
...
@MyklClason
MyklClason / cronjob.rb
Last active May 29, 2016 17:03
A trivial Rails cron job made using the Que gem
# app/jobs/cron_job.rb
class CronJob < Que::Job
# To minimize log clutter from unavailable jobs,
# @run_at should be a bit less than Que.wake_interval
@run_at = proc { 59.seconds.from_now }
def run
# Do stuff here
@MyklClason
MyklClason / filter_form.html.erb
Created May 29, 2016 17:29
Rails checkbox and radio button sample for AJAX data filtering
<%= form_tag(form_path, remote: true, id: "this-form",
class: "form form-inline col-md-12",
onchange: "$('#this-form').submit();") do |f| %>
...
<%= check_box_tag ... %>
<%= radio_button_tag ... %>
...
<% end %>
@MyklClason
MyklClason / Gemfile.rb
Last active June 5, 2019 20:35
Search/Sort/Paginate with Ransack and Kaminari
...
gem 'kaminari'
gem 'ransack'
..
@MyklClason
MyklClason / gist:f6ac68ca4ce1faa5d655abfb0abe788b
Last active December 11, 2021 00:05
CSV Export (Rails)
# Good solution for exporting to CSV in rails.
# Source: https://www.codementor.io/victorhazbun/export-records-to-csv-files-ruby-on-rails-vda8323q0
class UsersController < ApplicationController
def index
@users = User.all
respond_to do |format|
format.html
format.csv { send_data @users.to_csv, filename: "users-#{Date.today}.csv" }
@MyklClason
MyklClason / gist:08bf67d13220e5ee44dc2a3118bf08c1
Last active July 12, 2017 04:04
Import from heroku MySQL database
Connection String
mysql://USERNAME:PASSWORD@HOST/DATABASE
Command line where FILENAME is file with data to be imported (filename.sql).
mysql -u USERNAME -pPASSWORD -h HOST DATABASE < FILENAME > import.log
@MyklClason
MyklClason / gist:4868769b6deec9deac7b4236896241fc
Created July 8, 2017 00:35
S3 IAM Template. Update the date and replace BUCKET_NAME with correct S3 bucket
{
"Version": "YYYY-MM-DD",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::BUCKET_NAME",
"arn:aws:s3:::BUCKET_NAME/*"
]