Skip to content

Instantly share code, notes, and snippets.

View aalvrz's full-sized avatar

Andrés Álvarez aalvrz

View GitHub Profile
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------
@indiesquidge
indiesquidge / subdomain-localhost-rails-5.md
Created January 19, 2016 07:42
how to access subdomains locally with Rails 5

Subdomaining Localhost with Rails 5

I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api

Rails.application.routes.draw do
  constraints subdomain: "api" do
    scope module: "api" do
@danielpuglisi
danielpuglisi / users_controller.rb
Last active August 9, 2021 12:33
Rails examples: Single Table Inheritance (STI), strong parameters, single controller.
# Variant 1
def user_params(type)
params.require(type.to_sym).permit(attributes)
end
# Variant 2
def user_params(type)
case type
when "user"
params.require(:user).permit(user_attributes)
@JosefJezek
JosefJezek / zenoss-remove.md
Created January 21, 2014 11:10
Zenoss Uninstall / Remove / Delete

Zenoss Uninstall / Remove / Delete

service zenoss stop

yum remove zenoss mysql-server mysql-client mysql-shared rabbitmq-server redis memcached
rpm -ef --nodeps MySQL-shared-compat

rm -rf /var/lib/mysql/
rm -rf /var/lib/rabbitmq/
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@cluther
cluther / zenoss-shell-functions
Last active January 7, 2020 21:58
Zenoss JSON API Examples (curl)
# This shell script is intended to be sourced into your shell. It adds
# Default Zenoss server settings.
[ -z "$ZENOSS_URL" ] && export ZENOSS_URL="http://localhost:8080"
[ -z "$ZENOSS_USERNAME" ] && export ZENOSS_USERNAME="admin"
[ -z "$ZENOSS_PASSWORD" ] && export ZENOSS_PASSWORD="zenoss"
# Generic call to make Zenoss JSON API calls easier on the shell.
zenoss_api () {
ROUTER_ENDPOINT=$1
@henkm
henkm / gist:952240
Created May 2, 2011 19:55
Add new items via JQuery TokenInput / Ruby on Rails
#model (idea 100% stolen from ryanb)
def author_tokens=(ids)
ids.gsub!(/CREATE_(.+?)_END/) do
Author.create!(:name => $1).id
end
self.author_ids = ids.split(",")
end
# jquery.tokeninput.js