Skip to content

Instantly share code, notes, and snippets.

View olivierlacan's full-sized avatar

Olivier Lacan olivierlacan

View GitHub Profile
@olivierlacan
olivierlacan / gary_bernhardt_screencasting_parley.md
Created June 1, 2013 03:04
Gary Bernhardt on Screencasting

I'm planning on either writing this up in detail or maybe doing a screencast about screencasting, but I'll give a short version here.

On sound quality:

This matters a lot. In decreasing order of importance:

  1. Remove echo. You have to hear this to understand. Set up a mic in front of your mouth and record a sentence. Then, put a thick comforter over you and the mic and say it again at the same distance. Listen to
### Version 16 20181010
### https://lafibre.info/remplacer-livebox/tuto-remplacer-la-livebox-par-un-routeur-dd-wrt-internet-tv/
### Informations utilisateur
user=fti/abcdefg
pass=hijklmn
maclivebox=01:23:45:67:89:AB
verlivebox=3
serlivebox=ABCDE0123456789
@olivierlacan
olivierlacan / rendering_partials.md
Last active May 31, 2019 18:09
How to use shorthand syntax for rendering partials in Rails

Inside of Rails views, you can call partial views (any view file named with an underscore as the first character) like this:

render partial: "partial_name"

You can also pass local variables, which is fantastic to ensure that your views & partials don't try to access data you didn't specifically hand to them from the controller.

@tylerhunt showed me this week that it was possible to avoid using instance variables (which are copied from the Rails controller to the corresponding Rails views) altogether by passing local variables to the view.

@olivierlacan
olivierlacan / p_value_from_z_score.md
Last active October 21, 2018 20:26
Determine P value from positive AND negative Z scores

Obtain P value from positive and negative Z scores

My fiancée is working on her master's thesis and her professor recommended a website that gives her P values when she plugs in Z scores.

The website works fine (although it crashes for a while on incorrect input) but it provides no transparency as to the formula used to compute the P value.

More problematic, she had to input hundreds of numbers into it which took forever. I tried to find an Excel formula that could replicate the results of the website

@olivierlacan
olivierlacan / 1_contributor_covenant_1_3_0.md
Last active October 21, 2018 20:26
Comparing three proposals for a Ruby code of conduct from https://bugs.ruby-lang.org/issues/12004#note-276

Contributor Code of Conduct

As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.

We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance,

@olivierlacan
olivierlacan / output.bash
Created September 29, 2014 15:40
Does it really make sense to optimize for a 1.01x speed improvement by using single-quoted strings instead of double-quoted Strings in Ruby (to avoid interpolation scanning in the double-quoted strings)? I think the answer is no.
$ ruby string_benchmark.rb
Calculating -------------------------------------
single quote 128800 i/100ms
double quote 128351 i/100ms
-------------------------------------------------
single quote 6144842.6 (±5.4%) i/s - 30654400 in 5.008373s
double quote 6089768.4 (±6.4%) i/s - 30290836 in 5.000430s
Comparison:
single quote: 6144842.6 i/s
@olivierlacan
olivierlacan / rspec_time_comparison_warning.rb
Created September 24, 2018 16:53
Warn on RSpec comparisons between any time-like objects which may be sensitive to microsecond fluctuations in certain environments.
# This monkey patch modifies the RSpec `eq` matcher to suggest the `be_within`
# matcher instead when two time instances are being compared because equality
# comparison are inherently brittle on some operating systems like macOS so
# they may trigger false negatives.
module TimeComparisonWarning
def failure_message
msg = super
if [expected, actual].any? { |obj| obj.respond_to?(:strftime) }
@olivierlacan
olivierlacan / gist:5608432
Created May 19, 2013 18:00
Rails 4 doesn't like Bundler's binstubs. This is what happens when you upgrade to Rails 4 RC1 with Bundler binstubs installed.
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, your app's bin/ directory contains executables that are versioned
like any other source code, rather than stubs that are generated on demand.
Here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
@olivierlacan
olivierlacan / add_index_on_client_application_id_for_oauth_tokens.rb
Created October 17, 2014 07:17
Example of a (slightly hacky) concurrent migration for Rails 3.2 to add an index to a huge table without locking the table in a transaction.
class AddIndexOnClientApplicationIdForOauthTokens < ActiveRecord::Migration
def ddl_transaction(&block)
# hack because AR 3.x doesn't support the `disable_ddl_transaction!`
# method that AR 4.x introduced yet.
block.call # do not start a transaction
end
def change
# using raw SQL because ActiveRecord 3.x doesn't support concurrent
# migrations yet, in AR 4 this would be:
@olivierlacan
olivierlacan / bottles.rb
Created July 22, 2016 07:40
My first ever 99 Bottles of OOP exercism torture run in 30 minutes and 34 seconds because I'm a dirty cheater. Just look at this ugly little thing. Go get Sandi and Katrina's book if you don't know what this is about: 99bottlesbook.com
class Bottles
def verse(number)
<<-STRING
#{pluralize_bottle(number, true)} of beer on the wall, #{pluralize_bottle(number)} of beer.
#{ending(number)}
STRING
end
def verses(first, second)
range = (second..first).to_a.reverse