Skip to content

Instantly share code, notes, and snippets.

View flarnie's full-sized avatar

Flarnie Marchan flarnie

View GitHub Profile
@flarnie
flarnie / Validate Email in RoR
Created August 17, 2013 14:14
The right way to validate uniqueness case insensitive of email in Ruby on Rails.
##Check uniqueness of email-----------------------------------------------
#in migration
add_index :users, :email, :unique => true
#but that doesn't cover case insensitive
#in the model take email to lowercase before save
class User..
attr_accessible :email
#this gives you custom message for the error
let React = require('react');
var ReactTestUtils = require('react-dom/test-utils');
class TextWithStringRef extends React.Component {
render() {
return (
<span ref="foo">
Hello world!
</span>
);
@flarnie
flarnie / deprecating_unused_create_mixin_helper.md
Created May 24, 2017 16:58
More information about the deprecation of the unused `React.createMixin` helper

React.createMixin was never implemented

The React.createMixin helper was never actually implemented - the code for it simply took a mixin as an argument and returned it with no changes:

  createMixin: function(mixin) {
    // Currently a noop. Will be used to validate and trace mixins.
 return mixin;
@flarnie
flarnie / unknown-prop-warning-v15.6-fixture.html
Created April 21, 2017 18:32
fixture used to test the deduping of unknown prop warning in React v15.6
<!DOCTYPE html>
<html style="width: 100%; height: 100%; overflow: hidden">
<head>
<meta charset="utf-8">
<title>Unknown Props Example</title>
</head>
<body>
<h1>Unknown Props Example</h1>
<div id="container">
<p>
@flarnie
flarnie / infinite-scroll-example-step-2.jsx
Last active May 21, 2016 15:38
React-Waypoint Infinite Scroll Step 2
var InfiniteScrollExample = React.createClass({
//...
_renderItems: function() {
return this.state.items.map(function(imageUrl, index) {
// ... generate list items here ...
});
},
_renderWaypoint: function() {
if (!this.state.isLoading) {
@flarnie
flarnie / webpack.config.js
Last active January 8, 2016 05:30
Webpack configuration file for Rails setup
/**
* @see http://webpack.github.io/docs/configuration.html
* for webpack configuration options
*/
module.exports = {
// 'context' sets the directory where webpack looks for module files you list in
// your 'require' statements
context: __dirname + '/app/assets/javascripts',
// 'entry' specifies the entry point, where webpack starts reading all
@flarnie
flarnie / Webpack-Bundle-Logic-Simplified.js
Last active January 8, 2016 05:30
A simplified and annotated example of how JavaScript is loaded in the bundle by webpack.
/**
* In this simplified example,
* '_application.js' is our entry point
* and it requires 'init.js',
* which in turn requires both the 'home_view'
* and the 'current_user_model'
*/
var modules = [
// dependencies can be referenced by index
@flarnie
flarnie / index.html
Last active December 27, 2015 00:59
CSS3 Media Queries Demo
<html>
<head>
<link rel="stylesheet" type="text/css" href="media_qs.css" >
</head>
<body>
<b>HELLO WORLD.</b>
</body>
</html>
@flarnie
flarnie / rspec_ready.rb
Created October 20, 2013 14:07
A template to set up RSpec and FactoryGirl for testing when generating a new Rails app. Use: rails new my_app_name_here -m rspec_ready.rb
gem_group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
end
gem_group :test do
gem 'faker'
gem 'capybara'
gem 'guard-rspec'
gem 'launchy'
@flarnie
flarnie / 'inherits' JS helper
Created August 22, 2013 15:47
A helper function to get a target class to inherit from another class without side-effecting the parent class prototype.
Function.prototype.inherits = function(parent){
function Surrogate(){};
Surrogate.prototype = parent.prototype;
this.prototype = new Surrogate();
}