Skip to content

Instantly share code, notes, and snippets.

View ravicious's full-sized avatar

Rafał Cieślak ravicious

View GitHub Profile
# Elm Sprockets Integration for Rails 3
#
# I'm working on turning this into a Gem - see https://github.com/NoRedInk/sprockets-elm - but
# I know a lot more about Elm than I do Rails, and haven't gotten that version working yet.
# If you know how to help Gemify this, by all means please hit me up! https://twitter.com/rtfeldman
# I could definitely use the help.
#
# Anyway, in the meantime, this is what we're using at NoRedInk to integrate Elm into our asset
# pipeline, and it works like a charm. Just copy this into config/initializers/elm_sprockets.rb
#
@acdlite
acdlite / flux.js
Last active October 7, 2021 17:19
A Redux-like Flux implementation in <75 lines of code
/**
* Basic proof of concept.
* - Hot reloadable
* - Stateless stores
* - Stores and action creators interoperable with Redux.
*/
import React, { Component } from 'react';
export default function dispatch(store, atom, action) {
@gaearon
gaearon / combining.js
Created June 3, 2015 18:03
Combining Stateless Stores
// ------------
// counterStore.js
// ------------
import {
INCREMENT_COUNTER,
DECREMENT_COUNTER
} from '../constants/ActionTypes';
const initialState = { counter: 0 };
@bhauman
bhauman / project.clj
Last active August 29, 2015 14:19
figwheel test runner with red/green favicon
:cljsbuild {
:builds [{:id "dev"
:source-paths ["src" "dev_src"]
:compiler {:output-to "resources/public/js/compiled/slides.js"
:output-dir "resources/public/js/compiled/out"
:optimizations :none
:main slides.dev
:asset-path "js/compiled/out"
:source-map true
:source-map-timestamp true
@solnic
solnic / gist:9b9deedd7891e2c7ac83
Last active August 19, 2016 08:46
Virtus pg array type for Sequel
module Virtus
class PGArray < Attribute
primitive Sequel::Postgres::PGArray
def primitive
options[:primitive]
end
def coerce(value)
Sequel.pg_array(value)
@danielpclark
danielpclark / path_finder.rb
Created December 31, 2014 22:45
My first Tail Recursive Ruby script
# Tail Recursive
# A to Z path finder
def path_finder(arr, n = nil)
arr = arr.dup
n ||= Array(arr.shift)
val = arr.shift
if n.last.last == val.first
path_finder(arr, n << val)
elsif arr.any? {|b| n.last.last == b.first}
@mbbx6spp
mbbx6spp / README.md
Last active January 8, 2025 13:23
Gerrit vs Github for code review and codebase management

Gerrit vs Github: for code review and codebase management

Sure, Github wins on the UI. Hands down. But, despite my initial annoyance with Gerrit when I first started using it almost a year ago, I am now a convert. Fully. Let me tell you why.

Note: This is an opinionated (on purpose) piece. I assume your preferences are like mine on certain ideas, such as:

  • Fast-forward submits to the target branch are better than allowing merge commits to the target branch. The reason I personally prefer this is that, even if a non-conflicting merge to the target branch is possible, the fact that the review/pull request is not up to date with the latest on the target branch means feature branch test suite runs in the CI pipeline reporting on the review/PR may not be accurate. Another minor point is that forced merge commits are annoying as fuck (opinion) and clutter up Git log histories unnecessarily and I prefer clean histories.
  • Atomic/related changes all in one commit is something worth striving for. Having your dev
@rbxbx
rbxbx / deep_fetch.rb
Created August 27, 2014 15:25
Similar to Clojure's get-in for Ruby hashes
def deep_fetch(*keys, &default)
keys.inject(self) do |hsh, key|
hsh.fetch(key, &(proc { |*args| return default.call(*args) } if default))
end
end
@steveklabnik
steveklabnik / Entfremdung.md
Created August 3, 2014 18:15
alienation 101

Quick summary:

Alienation is one of the ways that capitalism sucks. It's a symptom that something's not right, not the underlying cause. Alienation is something that happens because of the way that capitalism is built.

In short, alienation is a separation between things that should be together. This separation causes tension.

Four ways that capitalism is alienating:

From your product of labor

@blairanderson
blairanderson / DependencyInjectionInRuby.md
Last active December 18, 2024 23:08
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache.

Dependency Injection in Ruby 07 Oct 04

Introduction

At the 2004 Ruby Conference, Jamis Buck had the unenviable task to explain Dependency Injection to a bunch of Ruby developers. First of all, Dependency Injection (DI) and Inversion of Control (IoC) is hard to explain, the benefits are subtle and the dynamic nature of Ruby make those benefits even more marginal. Furthermore examples using DI/IoC are either too simple (and don’t convey the usefulness) or too complex (and difficult to explain in the space of an article or presentation). I once attempted to explain DI/IoC to a room of Java programmers (see onestepback.org/articles/dependencyinjection/), so I can’t pass up trying to explain it to Ruby developers.

Thanks goes to Jamis Buck (the author of the Copland DI/IoC framework) who took the time to review this article and provide feedback.

What is Dependency Injection?