Skip to content

Instantly share code, notes, and snippets.

View rbazinet's full-sized avatar

Rob Bazinet rbazinet

View GitHub Profile
@r00k
r00k / setup.sh
Last active December 29, 2018 16:41
Rails bin/setup script, from refactoringrails.io
#!/bin/sh
# Set up Rails app. Run this script immediately after cloning the codebase.
# Exit if any subcommand fails
set -e
# Copy over configs
if ! [ -f .env ]; then
cp .sample.env .env
@hopsoft
hopsoft / prefetch.js
Last active December 27, 2023 02:45
Turbolinks Prefetching
const hoverTime = 400
const fetchers = {}
const doc = document.implementation.createHTMLDocument('prefetch')
function fetchPage (url, success) {
const xhr = new XMLHttpRequest()
xhr.open('GET', url)
xhr.setRequestHeader('VND.PREFETCH', 'true')
xhr.setRequestHeader('Accept', 'text/html')
xhr.onreadystatechange = () => {
@agiletortoise
agiletortoise / ViewController.swift
Created October 5, 2017 15:20
How to update input accessory view to handle iPhone X with external keyboard
//
// ViewController.swift
// TEST_InputViewX
//
// Created by Greg Pierce on 10/5/17.
// Copyright © 2017 Agile Tortoise. All rights reserved.
//
// Demonstrates how to update an input accessory view
// to work on iPhone X with external keyboard attached
// using safe area insets.

Advanced JavaScript Learning Resources

This is a list of advanced JavaScript learning resources from people who responded to this [Tweet][13] and this [Tweet][20].

  • [You Don't Know JS][3]

  • [Frontend Masters courses by Kyle Simpson][12]

  • [@mpjme][6]'s [YouTube videos][5]

@hartfordfive
hartfordfive / verify_s3_file.rb
Created November 1, 2016 17:47
Check if file exists in S3 bucket with Ruby aws-sdk gem
require 'aws-sdk'
s3 = Aws::S3::Resource.new(
region: 'us-east-1',
credentials: Aws::InstanceProfileCredentials.new()
)
bucket = s3.bucket('my-daily-backups')
file = (DateTime.now).strftime("%Y.%m.%d-backup")
if bucket.object(file).exists?
class SomeController < ApplicationController
before_action :add_http_preload
private
def add_http_preload
# Always add a Link header to responses to this controller
http_preload script: "application.js", style: "application.css"
http_preload "myfont.woff", as: :font, push: false
# TODO: How should crossorigin work?
@derwiki
derwiki / README.md
Last active September 27, 2023 17:50
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

@fideloper
fideloper / update_curl.sh
Last active January 11, 2024 15:23
Update curl on Ubuntu 14.04
#! /usr/bin/env bash
# Install any build dependencies needed for curl
sudo apt-get build-dep curl
# Get latest (as of Feb 25, 2016) libcurl
mkdir ~/curl
cd ~/curl
wget http://curl.haxx.se/download/curl-7.50.2.tar.bz2
tar -xvjf curl-7.50.2.tar.bz2
@zackify
zackify / dropdown-with-toggle.jsx
Last active December 22, 2015 15:26
The simplest react dropdown component ever
import React from 'react'
export default class Dropdown extends React.Component{
constructor(props){
super()
this.state = { show: props.show }
this.onClick = this.onClick.bind(this)
}
onClick(){
@chriseidhof
chriseidhof / json.swift
Last active March 21, 2019 07:45
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {