Skip to content

Instantly share code, notes, and snippets.

@weshouman
Last active September 30, 2016 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weshouman/041cc6db70e0842d1164bc7ad362c032 to your computer and use it in GitHub Desktop.
Save weshouman/041cc6db70e0842d1164bc7ad362c032 to your computer and use it in GitHub Desktop.
documenting the html list to redis app

URI

open_uri

Nokogiri

Official tutorials
Nokogiri usage with css selection
Accessing node element attributes

Capturing xpath, css selectors in chrome

A chrome extension for that

Extend Core Extensions

extending string class
I used this line instead,

Dir[File.join(File.dirname(__FILE__), "core_ext", "*.rb")].each {|l| require l }

It worked till I decided to execute the file from another dir, seems that Dir[].each gives the files relative to the FILE but require expects the files relative to the cwd. Thus I replaced it with

Dir[File.join(File.dirname(__FILE__), "core_ext", "*.rb")].each {|l| require File.expand_path(l) }

expand_path captures the fullpath for us, that way require won't get confused

A to_boolean extension
For the method to work on the string (ie: like to_i) here's the new version

  def to_boolean
      self == 'true'
  end

Regex

Match string with benchmarking
Capture specific regex
Check file ends with extname

File download

Using open-uri:
IO.stream_copy method
Is there a magic trick for checksumming remote files?

String to date/time conversion

String to date/time
date/time to string

Cancel pry debugging methods

exit-program and !!!

Classes

Advanced: classes intro
Interesting stuff about scopes, and this one too
Scope resolution operator, more explanation(http://stackoverflow.com/questions/11043450/vs-dot-vs-double-colon-for-calling-a-method#comment48694104_11043499), and even more explanation
double colon

Static methods

class methods vs instance methods class variable considerations

Non Static considerations

Initialize vs body

Unzipping

Unzip file
Check valid zip file
rubyzip: (the official gem)
zip:(useful for any ruby version even if <1.9.2) - inactive development last release was 2010

Callbacks

different ways for callbacks in ruby

Rescue blocks

Syntax

Directories

Create directory if not found. Create nested directories

Logging

Logging notes
Interesting article about being verbose

Redis

Redis set/get elements
Redis subscribe to a channel , and even simpler
TTL, checking expiry
Redis with Rails

Ruby Memos

Single line conditioning, and even more conditioning
Loop with index

IRB

Redirecting console output

RubyGem Creation guides

Patterns
Make your own gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment