Skip to content

Instantly share code, notes, and snippets.

View sunny's full-sized avatar

Sunny Ripert sunny

View GitHub Profile

To install this gem, paste this line in your Gemfile:

gem "some-gem-name"

To install this gem, paste these lines in your Gemfile:

# Adds some things to your Rails app
gem "some-gem-name"
# XML Parsing library, required for our RSS feed reader
gem "nokogiri"
#!/usr/bin/env ruby
class Watcher
def watch
loop do
if unresponsive? && sleep(3) && unresponsive?
restart
sleep 20
end
sleep 5
end
@sunny
sunny / enumerator_lazy_compact_extension.rb
Last active September 7, 2019 16:16
Adds #compact to Lazy Enumerators in Ruby
class Enumerator::Lazy
def compact
reject(&:nil?)
end
end
# This concern helps controllers redirect to the previous page by storing in session
# the current GET request.
#
# On controllers that need to redirect or that you don't want to keep track of, use:
# skip_before_action :store_previous_url
#
# And then you can redirect to `session[:previous_url]` or use the
# `redirect_to_previous_or_root` helper.
#
# Also, this catches exceptions thrown by `redirect_to :back` when there is
@sunny
sunny / markov.rb
Created May 11, 2015 08:41
Markov chain generator
# Markov Chain generator from a text file.
#
# Example:
# source = Markov::FileSource.new('jackson.txt')
# chain = Markov::Chain.new(source)
#
# 10.times do
# puts chain.generate_uniq
# end
#
# Get phrases
phrases = File.readlines('phrases.txt')
.map { |p| p.gsub(/["()*]/, '') }
.map { |p| p.gsub(/ +/, ' ').strip }
.reject { |p| p.split(' ').size < 2 }
.uniq
# Get first words
starters = phrases.map { |p| p.split(' ').first }
@sunny
sunny / gif_processes.rb
Last active May 5, 2019 11:24
Addon to CarrierWave to process GIF files.
# frozen_string_literal: true
require "rmagick"
# Addons to CarrierWave to process GIF files.
#
# Example:
#
# class AvatarUploader < CarrierWave::Uploader::Base
# include CarrierWave::GifProcesses
@sunny
sunny / ip.sh
Created March 25, 2015 17:15
ip command line
# Install: place this in your `~/bin/` and call it `ip` for example.
#
# Usage:
# $ ip
# 192.168.1.42
# 242.242.42.89
ipconfig getifaddr en0
curl ipecho.net/plain;echo