Skip to content

Instantly share code, notes, and snippets.

@rewinfrey
rewinfrey / sql.txt
Created March 13, 2015 23:11
sql with negative look ahead
SELECT organizations.name,
organizations.id,
organizations.ancestry,
tmp.average_activated_time_of_children from organizations
JOIN (
SELECT org.ancestry,
AVG(org.updated_at - org.created_at) as average_activated_time_of_children,
CAST(substring(org.ancestry from '\d+(?!\/)$') as integer) as organization_id
FROM organizations org
INNER JOIN accounts acc ON acc.organization_id=org.id
@solomonhawk
solomonhawk / example.js
Last active August 29, 2015 14:16
EZ Store Listening
// some pieces of this file have been omitted
let React = require('react')
let notesStore = require('../../stores/notesStore')
let monitorMixin = require('../../mixins/monitorMixin')
let Notes = React.createClass({
mixins: [monitorMixin(notesStore)]
// this gets called whenever `notesStore` emits a change event
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

@rewinfrey
rewinfrey / struct_class.rb
Last active August 29, 2015 14:09
model like struct class
class Location < Struct.new(:city,
:state,
:zipcode)
def initialize(from_hash)
super(*from_hash.values_at(*members))
end
def display_city
city.capitalize
@seyhunak
seyhunak / apache_bench.sh
Last active July 5, 2023 17:02
Rails - Apache Bench - Load Testing (if Devise Sign-in Required)
1.
LOGIN_PAGE=http://localhost/users/sign_in
curl --cookie-jar cookie_file $LOGIN_PAGE | grep csrf-token
2.
<meta content="csrf-token" name="csrf-token" />
@rewinfrey
rewinfrey / rails_application_tuning.md
Last active August 29, 2015 14:04
Rails Large Application Tuning

Notes from Tuning Legacy Rails App: How to Make an Elephant Sprint

###Measuring performance

  • Monitor the values of specific code paths and graph them to see performance over time (response times as one example metric)
  • Automated tests that measure performance can fail based on a set threshold
    • If a given code path exceeds 20% of the existing response time, then the automated test fails, alerting ops and devs that a recent code change has negatively impacted performance beyond an pre-defined SLA or threshold
  • Need a production like environment
  • Make that performance test environment exclusive to performance testing (don't let regular usage or QA usage affect the test results)
  • Using NewRelic to compare boxes against each other
@runlevel5
runlevel5 / lotus_console.md
Last active August 29, 2015 14:02
A simple rake task that replicates the `rails console` for Lotus Framework

Lotus Console

A simple rake task that replicates the rails console for Lotus Framework

How to?

I assume that your config/application.rb is the place where you initialize all Lotus boot config

below is my config/application.rb for your interest

@tristanfisher
tristanfisher / Ansible-Vault how-to.md
Last active April 3, 2024 13:55
A short tutorial on how to use Vault in your Ansible workflow. Ansible-vault allows you to more safely store sensitive information in a source code repository or on disk.

Working with ansible-vault


I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.

What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.

Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.

@rewinfrey
rewinfrey / heredoc_remove_leading_whitespace.rb
Last active August 29, 2015 14:02
Simple example for removing leading whitespace with Ruby's heredoc operator
# This is not as sophisticated as ActiveSupport's `strip_heredoc`, but is the simplest solution for
# removing leading whitespace.
# For more nuanced whitespace removal, take a look at http://apidock.com/rails/String/strip_heredoc
puts "With leading whitespace:"
puts <<-TEST
This is a test.
To remove leading spaces.
From Ruby's heredoc operator.
TEST