Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrés Álvarez aalvrz

View GitHub Profile
View django_orm_optimization_cheat_sheet.py
"""
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 Jan 19, 2016
how to access subdomains locally with Rails 5
View subdomain-localhost-rails-5.md

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 Apr 21, 2020
Rails examples: Single Table Inheritance (STI), strong parameters, single controller.
View users_controller.rb
# 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 Jan 21, 2014
Zenoss Uninstall / Remove / Delete
View zenoss-remove.md

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 Mar 23, 2012
Rspec Rails cheatsheet (include capybara matchers)
View rspec_rails_cheetsheet.rb
#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 Jan 7, 2020
Zenoss JSON API Examples (curl)
View zenoss-shell-functions
# 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
Add new items via JQuery TokenInput / Ruby on Rails
View gist:952240
#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
You can’t perform that action at this time.