Skip to content

Instantly share code, notes, and snippets.

@thatrubylove
thatrubylove / gol.rb
Last active August 29, 2015 14:01
Functional Game of Life (spike)
require 'curses'
module Seeder
extend self
def generate_matrix
rand(40..200).times.map { [rand(24), rand(48)] }
end
end
class Universe
@drbrain
drbrain / README.md
Last active August 29, 2015 14:19
Parentheses don't make code readable by themselves

I've heard people argue "parentheses make code more readable" or "parentheses make code less ambiguous". Parentheses neither help nor hinder ambiguity or readability, your style decisions beyond use of () do that.

Here's a bug we introduced in our application that was allowed through by a coding style that preferred parentheses. If you follow a coding style that omits all unneccesary parentheses (only those that suppress warnings, which I prefer) this bug would have been impossible.

The bug is simple but subtle. The environment-specific data wasn't fetched from config/two.yml because a ) was in the wrong place. Neither my coworker who wrote it, another coworker who reviewed it, nor my own review of the line caught it.

Without parentheses, though, there is no way to introduce this class of bugs because you can't chain off of intermediate results without introducing a local variable.

The main difference between the two examples is not the use of parentheses, it's the style in which the code is wri

@JoshCheek
JoshCheek / lambda_calculus_list.rb
Created April 19, 2015 20:39
Linked List (only as far as the stack) implemented with the constraints of the lambda calculus.
# Build the relevant methods
-> with_self {
-> list {
-> the_program {
the_program[with_self, list] }}[
# list
-> build_node {
with_self[-> me {
build_node[-> { me }, -> { raise 'too far!' }]}]}[
At Monmouth Telecom we provide high-availability cloud based telephone systems for medium to large companies. Because
we have written our own code in Ruby it is easy for us to customize or add additional features at the request of customers,
often at no charge, and that is key to our business.
Several years ago our engineering team developed a real time display panel for managers and operators alike that kept people
abreast of the status of phone extensions, conference bridges, and call queues, as well as allowing a variety of call control
features. We wrote this in ruby so that it would be easy to extend. The web display panel accesses customer data through
Active Record and is based on HTML5 with canvas and web sockets so it doesn’t require setup on the customer site.
Unsurprisingly it was one our more popular features and so we immediately started monitoring Rubinius as our migration path
for the day when one core of our 8 processor cores would become insufficient to meet demand. Well earlier this year
@NullVoxPopuli
NullVoxPopuli / deserialization.md
Last active October 9, 2019 20:30
ActiveModelSerializers vs jsonapi-rb Benchmarks
@quirkey
quirkey / console_helpers.rb
Last active February 13, 2020 19:57
All the code for the Paperless Profiler
require 'rblineprof'
module Rblineprof
module ConsoleHelpers
include Rblineprof::Helpers
def lineprof_block(options = {}, &block)
profile = lineprof(rblineprof_profiler_regex(options[:lineprofiler])) do
ret = yield
end
@flomotlik
flomotlik / Gemfile
Last active April 6, 2021 13:17
Puma on Heroku
gem 'foreman'
gem 'puma'
@royshouvik
royshouvik / console.ts
Last active October 4, 2022 00:12
Nestjs REPL
import 'dotenv/config';
import { NestFactory } from '@nestjs/core';
import * as repl from 'repl';
import * as Logger from 'purdy';
const LOGGER_OPTIONS = {
indent: 2,
depth: 1,
};
@anotheruiguy
anotheruiguy / web-fonts-asset-pipeline.md
Last active May 24, 2023 22:08
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@briankung
briankung / docker-pry-rails.md
Last active December 12, 2023 10:40
Using pry-rails with Docker

First, add pry-rails to your Gemfile:
https://github.com/rweng/pry-rails

gem 'pry-rails', group: :development

Then you'll want to rebuild your Docker container to install the gems