Skip to content

Instantly share code, notes, and snippets.

View jocubeit's full-sized avatar
🎯
Focusing

Dom Jocubeit jocubeit

🎯
Focusing
View GitHub Profile
@csm123
csm123 / index.html.haml
Last active April 12, 2017 07:56
React/Fluxxor in Rails Example
:javascript
$(document).ready(function() {
window.loadIngredientSuggestionsEditor(#{@ingredients});
});
%h1 Edit ingredient suggestions
#js-ingredient-suggestions-editor
@sebmarkbage
sebmarkbage / ElementFactoriesAndJSX.md
Last active May 17, 2022 11:06
New React Element Factories and JSX

New React Element Factories and JSX

In React 0.12, we're making a core change to how React.createClass(...) and JSX works.

If you're using JSX in the typical way for all (and only) React components, then this transition will be seamless. Otherwise there are some minor breaking changes described below.

The Problem

anonymous
anonymous / A-Pen-by-Tom-Speak.markdown
Created March 13, 2014 02:27
A Pen by Tom Speak.
@sma
sma / README.md
Last active July 4, 2023 06:28
This is an ad-hoc Java-to-Dart translator written in three days. This is version 2 which some bug fixes.

Java to Dart

This is an ad-hoc Java-to-Dart translator originally written on two (admittedly long) evenings.

See http://sma.github.io/stuff/java2dartweb/java2dartweb.html for a demo.

Note: It doesn't support the complete Java grammar specification and cannot translate everything. It only translates syntax and does not attempt to translate Java library classes and methods to Dart equivalents (with the exception of String.charAt and StringBuffer.append). You will have to make changes to the resulting Dart code. It does not support anonymous inner classes.

However, I was able to successfully convert a 7000+ line command line application with only minimal fixes in 30 minutes.

@jopotts
jopotts / default_values.rb
Last active August 13, 2022 16:26
Simple default values on creation of ActiveRecord models
module DefaultValues
def has_default_values(default_values = {})
class_attribute :default_values
self.default_values = default_values
after_initialize :assign_default_values
include InstanceMethods
# Rails 4
class AddHstoreIndexes < ActiveRecord::Migration
def change
add_index "nodes", "properties", using: :gin
end
end
# Rails 3.x
MyExceptions = [RangeError, RegexpError, IOError].freeze
begin
raise IOError, "should be rescued"
rescue *MyExceptions => e
puts e
end
@cmaitchison
cmaitchison / after_commit_with_transactional_fixtures.rb
Last active August 4, 2016 03:30 — forked from charleseff/after_commit_with_transactional_fixtures.rb
testing after_commit hooks with transactional fixtures in Rails 4
require 'active_record/connection_adapters/abstract/transaction'
module ActiveRecord
module ConnectionAdapters
class SavepointTransaction < OpenTransaction
def perform_commit_with_transactional_fixtures
commit_records if number == 1
perform_commit_without_transactional_fixtures
end
alias_method_chain :perform_commit, :transactional_fixtures
@lexmag
lexmag / article.rb_product.rb
Created July 28, 2012 15:12
Two-way polymorphic models / Polymorphic HABTM association
class Article < ActiveRecord::Base # Product class is similar
belongs_to :user
has_many :media, as: :ownable
with_options through: :media, source: :representable do |assn|
assn.has_many :videos, source_type: 'Video'
assn.has_many :images, source_type: 'Image'
end
end
@kulesa
kulesa / gist:2507892
Created April 27, 2012 09:44 — forked from dhh/gist:2492118
nested routes for namespaces
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes", "#{@scope[:shallow_prefix]}", "#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :projects # => config/routes/projects.rb
namespace :admin do