Skip to content

Instantly share code, notes, and snippets.

View tonatiuh's full-sized avatar

Tonatiuh Núñez tonatiuh

View GitHub Profile
@tonatiuh
tonatiuh / to_set_signed_up_at_field.rb
Last active December 15, 2015 06:39
To set the 'update_at' (the last time the user signed in) field value to the 'signed_up_at' for the users who have that field as nil.
User.where(signed_up_at: nil).each do |user|
if user.oauth_token.present? then
user.signed_up_at = user.updated_at
user.save
end
end
@tonatiuh
tonatiuh / reset_db.sql
Created July 30, 2013 22:06
Reset db on psql
SELECT
'DROP TABLE '||c.relname ||' CASCADE;'
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_roles r ON r.oid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1;
class EnglishStudentsController < ApplicationController
def update
@english_student = User.find(params[:id])
respond_to do |format|
if @english_student.update_attributes(english_student_params)
format.json { render json: { message: "Student updated successfuly" } }
else
format.json { render json: { message: "Student could not be updated" } }
end
@tonatiuh
tonatiuh / material_covered_in_classes.md
Last active January 3, 2016 15:29
The material discussed along the Trainees classes (from Wednesday, January 15th to Friday 17th).

Requirements

What we're going to show the client (Proposal):

  • App's use cases
  • Wireframes of the UI
  • Technical diagrams

What we're expecting to find:

Easy Nested Forms with Rails

Introduction

  • What are nested forms?
    • Forms that allow you to save information not only for a base element, but for related elements of the main element

Basic Form

  • Someone is asking for a SalesOrder Form in which the client name can be set (as plain text)
  • What is required to accomplish that?

Therubyracer + libv8 in Mavericks with ruby-1.9.3-p448 issue

Therubyracer

If therubyracer gives you a problem like this one when installing it:

ERROR:  Error installing therubyracer:
  ERROR: Failed to build gem native extension.

/Users/tonatiuh/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb

done

  • improve file copying
  • commit the files, created repo
  • install nginx

to do

  • install the gems

pending

  • install the gems for auth and main
@tonatiuh
tonatiuh / git_bash_functions.md
Last active August 29, 2015 14:01
Bash functions that make automate some day to day tasks

Function that automates the creation of a new gitflow branch:

#!/bin/bash

function git_start_feature() {
  story_title=$1
  story_title=${story_title,,} # downcase string
  story_title=${story_title// /-} # replace spaces by dashes
 story_title=${story_title//\//-} # replace slashes by dashes

Since git allows you to run scripts as if they were git commands, this will show how to create a command for creating a pull request from the terminal.

  1. Create a file with the following name "git-pull-request", we can put it inside ~/.git/extensions for instance. Add the following content to the file
#!/usr/local/bin/bash

repo=`git remote -v | grep -m 1 "(push)" | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
branch=`git name-rev --name-only HEAD`
echo "... creating pull request for branch \"$branch\" in \"$repo\""
open https://github.com/$repo/pull/new/$branch