Skip to content

Instantly share code, notes, and snippets.

View kenmazaika's full-sized avatar

ken mazaika kenmazaika

View GitHub Profile

Rebuilding Your Database.

Unfortunately databases migrations will only run a single time for a given environment (once for localhost / once for heroku). That means that once it ran the migration, it added the picture column to the users table and that it was done. Any time you run "rake db:migrate" again it doesn't know that the migration changed so it won't do anything.

You may want to revisit this video, for more in-depth details about database migrations.

So rule of thumb: never edit a migration after you run it.

When your database is out of sync with the rules that we wrote to build them up. Often times the easiest thing to do will be to tear down your database and put it back up. You will lose all you user/places/etc but by running all of them start to finish again you won't run the migration in the intermediate state.

rm -rf /.git
rm -rf /vagrant/.git
rm -rf /vagrant/src/.git
git rev-parse --show-toplevel
cat .git/config
module Luhn
def self.is_valid?(num)
digits = num.to_s.split("").collect(&:to_i)
new_digits = []
digits.reverse.each_with_index do |digit, index|
if index % 2 == 1
digit = digit * 2
digit = digit - 9 if digit >= 10
end
new_digits << digit

Engineering a Content-Hub with Rails API and React, Redux & WebPack

Traditional blogging engines, like Wordpress, treat the content of a blog post as the most important element of the page. Other elements, like widgets and plugins are often disjointed and second class citizens in comparison to the content itself. A wide array of plugins exist in Wordpress, but getting them to work perfectly can be a challenge.

Breaking the problem down I decided that a blog post could be a collection of BlogPostComponents (and the content of the post is just one such component) and set off to build a JSON API in Rails that could be consumed by a React front-end to be the ulitmate user experience on the blog.

This project is an interesting case study in building a production ready react app, including a number of gotchas along the way.

I'll start with a brief high-level overview of React and Redux for people unfamiliar with the concepts, and explain the application logic code. I then will dive into the more advanced

Box Model Example

A simple webpage to showcase the difference between setting an item's margin vs. padding and an in-depth process of considering the implications of the CSS Model Model.

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
acts_as_followable
acts_as_follower
end
class Game < ActiveRecord::Base
belongs_to :white_user, class_name: 'User', foreign_key: "white_user_id"
end
class User < ActiveRecord::Base
has_many :white_games, class_name: 'Game', foreign_key: "white_user_id" # => app/models/game.rb
has_many :black_games, class_name: 'Game', foreign_key: "black_user_id" # => app/models/game.rb
class TreeNode
def initialize(value = nil, left = nil, right = nil)
@value = value
@left = left
@right = right
end
def set_value(value)
@value = value
end
{
id: 1,
title: "29 Ways to Be unstoppabel",
slug: "29-Ways-to-Be-unstoppabel",
status: "draft",
created_at: "2016-06-30T16:19:58.376Z",
updated_at: "2016-06-30T16:19:58.376Z",
components: [{
id: 2,
post_id: 1,
{
id: 1,
title: "29 Ways to Be unstoppabel",
slug: "29-Ways-to-Be-unstoppabel",
status: "draft",
created_at: "2016-06-30T16:19:58.376Z",
updated_at: "2016-06-30T16:19:58.376Z",
components: [
{
id: 2,