Skip to content

Instantly share code, notes, and snippets.

View PabloVallejo's full-sized avatar

Pablo Vallejo PabloVallejo

View GitHub Profile
@PabloVallejo
PabloVallejo / App.java
Last active August 29, 2015 14:21
Hospice project
// Import all Java utils.
import java.util.*;
// Improt java lang.
import java.lang.*;
// Excercises.
public class App {
# Assigning multiple attributes to an object at once.
@thing.assign_attributes(
:created_by => current_user,
:period_template => period_template
)
@PabloVallejo
PabloVallejo / ruotes.rb
Last active August 29, 2015 14:11
Examples of routes usage
# Resource without certain actions.
resources :users, :except => :show
# Specify routes and add new ones.
resources :sessions, :only => [:new, :create, :destroy] do
get :recovery, :on => :member
end
@PabloVallejo
PabloVallejo / query.rb
Created December 8, 2014 23:18
Query API
# Ordering records in descending order
User.order(email: :desc)
@PabloVallejo
PabloVallejo / registration_controller.rb
Last active August 29, 2015 14:10
Configuring permitted parameters in devisee.
#
# Configure permitted parameters for a devise action.
# This can be done in several ways on which this two are
# the most used.
#
def configure_permitted_parameters
# Usign a `do` block.
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:name, :heard_how,
@PabloVallejo
PabloVallejo / general.rb
Last active August 29, 2015 14:10
Helpful uncategorized tips.
# Autoload `lib` directory.
# Inside config/application.rb
config.autoload_paths << Rails.root.join('lib')
@PabloVallejo
PabloVallejo / migrations.sh
Last active August 29, 2015 14:10
Rails migrations
# Adding a column to users model.
rails g migration add_email_to_users email:string
# Reverting a migration.
rake db:migrate:down VERSION=3846656238
# Drop a table.
rails g migration DropProducts
<snippet>
<content><![CDATA[base(this, '${1:method}'${2});${0}]]></content>
<tabTrigger>base</tabTrigger>
<scope>source.js</scope>
<description>Base method call</description>
</snippet>
# views.py
class UserProfileUpdate(LoginRequiredMixin, UpdateView):
# ...
# Pass current user to form through `initial`
def get_form_kwargs(self, **kwargs):
kwargs = super(UserProfileUpdate, self).get_form_kwargs(**kwargs)
kwargs['initial']['user']=self.request.user
return kwargs
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()