Skip to content

Instantly share code, notes, and snippets.

@tonywok
tonywok / gist:8764367
Created February 2, 2014 07:42
Remove annoying nokogiri notice for OSX Mavericks
gem uninstall nokogiri
brew uninstall libxml2
bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
bundle install
echo "sleep at night"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script>
<script src="http://builds.emberjs.com/tags/v1.4.0/ember.js"></script>
</head>
@tonywok
tonywok / active_model_serializer.rb
Created April 2, 2014 17:37
Hacking polymorphic has_many into AMS. (e.g has_many :tasks, embed: :ids, include: true, polymorphic: true)
module ActiveModel
class Serializer
module Associations
class HasMany
def key_with_polymorphism
return @name if !option(:key) && option(:polymorphic)
key_without_polymorphism
end
alias_method_chain :key, :polymorphism
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
</head>
<body>
<script type="text/x-handlebars">
@tonywok
tonywok / gist:a954531b5395d52ead6f
Created June 23, 2014 22:12
Some helpers for dealing with missing data and handling defaults w/o making a bunch of nested if/else
Neo.UI.Mixin.Maybe =
maybeAnchored: (bool, url, dom...) ->
if bool
React.DOM.a(href: url, dom)
else
dom
maybeDisplayed: (bool, dom...) ->
if bool then dom else null
@tonywok
tonywok / gist:d4395f242e8b29f3f126
Last active August 29, 2015 14:13
More Flexible User Models

More Flexible Users

Applications are built for users. We give them distinguishing properties, connect them to other entities, respond to their actions, and make various decisions based on any combination of those things.

In rails, it's almost guaranteed that sitting inside of app/models/ is a class called User. I'm sure you're intimately familiar with this class. In fact, I suspect that if you were to hack together a heat-map representing your code editor, user.rb would probably be molten.

The Setup

Taking this into consideration, how would you describe the responsibility of your User model? I've noticed a few trends while working in rails:

class ShortUrlsController < ActionController::Base
# before_filter :login_required
def index
@urls = Url.paginate :page => params[:page], :per_page => 4, :order => 'updated_at DESC'
end
def create_link
@url = Url.new(:long_url => params['url'])
!!!
%html
%h1
Multiple Files Upload Using Rails and JQuery
%h3
Files
- form_tag(:action => '/services/uploadr', :method => :post, :multipart => true)
= text_field_tag 'name'
= submit_tag 'Submit'
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="StudentProfilesDataSource">
<EditItemTemplate>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
<br />
LastName:
<asp:TextBox ID="LastNameTextBox" runat="server" Text='<%# Bind("LastName") %>'>
</asp:TextBox>
<br />
FirstName:
require 'lib/string_util.rb'
require 'singleton'
class Tokenizer
include Singleton
attr_accessor :source, :chunks
def initialize(filename = '')