Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
rentalcustard / gist:5524668
Last active January 13, 2022 14:21
Removing all literals from Ruby

Literals are ugly. Let's remove them.

True/false:

2.0.0p0 :001 > !Date
=> false
2.0.0p0 :002 > require Date.to_s.downcase
=> true

Integers and floats:

@rentalcustard
rentalcustard / gist:5405403
Created April 17, 2013 15:49
Ruby 2.0.0 changelog
~> irb
1.9.3-p194 :001 > Date
NameError: uninitialized constant Date
from (irb):1
from /Users/thomasstuart/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
1.9.3-p194 :002 > exit
~> rvm use 2.0.0
Using /Users/thomasstuart/.rvm/gems/ruby-2.0.0-p0
~> irb
2.0.0p0 :001 > Date
!some-branch ~/some_repo> gst
# On branch some-branch
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: app/models/user.rb
#
no changes added to commit (use "git add" and/or "git commit -a")
!some-branch ~/some_repo> ga app/models/user.rb
> rvm install 1.9.3
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p392.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing requirements for osx/10.8/x86_64, might require sudo password
Warning: Your Xcode (4.5.2) is outdated
Please install Xcode 4.6.
==> Upgrading git <- WAT
==> Downloading http://git-core.googlecode.com/files/git-1.8.1.4.tar.gz######################################################################## 100.0%
==> make prefix=/usr/local/Cellar/git/1.8.1.4 CC=cc CFLAGS= LDFLAGS= install
@rentalcustard
rentalcustard / gist:5030640
Created February 25, 2013 15:34
What actually is `using`?

A search for 'using' on http://www.ruby-doc.org/core-2.0/index.html returns, well, nothing. So, what is it?

2.0.0p0 :001 > method(:using)
=> #<Method: main.using> 
2.0.0p0 :002 > _.source_location
=> nil

So it's some kind of method on main with no source location. Hmm. Well, the changelog mentions ri ruby:syntax. Let's try that.

~/code/200-test> ri ruby:syntax | cat

(http://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/)

Documentation

We have also made documentation improvements which many rubyists have requested. We have added a huge amount of rdoc for modules and methods. 2.0.0 will be around 75% documented while 1.9.3 was about 60%. Also, we have added a description of Ruby's syntax. You can see:

ri ruby:syntax

@rentalcustard
rentalcustard / gist:4681932
Created January 31, 2013 10:19
Check your Gemfile.lock for unverified Rubygems
#unverified.list obtained from https://gist.github.com/raw/865b05630be54544ca72/a1a0c114d5eab0e65efccc941ca013fd06e6f43c/unverified.list
File.readlines("unverified.list").map do |line|
line.split.last.gsub("./", "").gsub(/-(\d+).*/, "")
end.sort.uniq.each do |gem|
in_gemfile_lock = system "grep -q #{gem} Gemfile.lock"
puts "Unsafe #{gem}" if in_gemfile_lock
end
@rentalcustard
rentalcustard / screwit.clj
Last active December 10, 2015 22:28
I suck at Clojure
(apply str (map #(str "String value for " %) some-seq))
for file in $(find . -name '*.rb')
do
if [ $(egrep "\b[A-Z]" $file | wc -l) -gt $(egrep "(class|module)" $file | wc -l) ]
then
echo $file " fails"
fi
done | wc -l
@rentalcustard
rentalcustard / config.js
Created January 3, 2013 09:53
Opening console config for extension
(function() {
var C = JS.Console;
var adapterConditions = {};
var registerAdapterCondition = function(check, initializer) {
adapterConditions[check] = initializer;
};
var configureC = function() {
C.adapter = new C.Base();