Skip to content

Instantly share code, notes, and snippets.

@AlexWayfer
AlexWayfer / benchmark.rb
Last active August 20, 2020 17:34
Benchmark example
# frozen_string_literal: true
require 'bundler/setup'
Bundler.setup :system
require 'pry-byebug'
require 'benchmark'
require 'benchmark/ips'
require 'benchmark/memory'
@BenStigsen
BenStigsen / TwitchBot.rb
Last active September 6, 2019 10:06
Twitch chat bot written in Ruby
# bot.rb
require 'socket'
require 'logger'
# Create logger
log = Logger.new("log.txt")
# Required Info
PASS = "oauth:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # "oauth:YourOauthToken" https://twitchapps.com/tmi/ <--- REQUIRED <--- REQUIRED
NICK = "botname" # Name of bot <--- REQUIRED <--- REQUIRED
@heliohead
heliohead / feature_helper.rb
Created April 4, 2017 00:06
Compile assets before run rspec features test
# spec/support/feature_helper.rb
RSpec.configure do |config|
config.before :all do
ENV['PRECOMPILE_ASSETS'] ||= begin
case self.class.metadata[:type]
when :feature, :view
STDOUT.write "Precompiling assets..."
system "bundle exec rake assets:precompile > /dev/null 2>&1"
@colby-swandale
colby-swandale / Rails DockerFile
Created October 25, 2015 08:56
Dockerfile with rbenv and ruby-install
FROM ubuntu:latest
MAINTAINER Colby Swandale <colby@taplaboratories.com.au>
# update apt cache and install dependencies
RUN apt-get update && apt-get install git curl build-essential libssl-dev libreadline-dev zlib1g-dev sqlite3 libsqlite3-dev -y
# add app user
RUN adduser --gecos '' --disabled-password app
# set user to app
USER app
# set rbenv, ruby-build bin paths
ENV HOME /home/app
@avdi
avdi / macro_modules.rb
Last active August 29, 2018 07:43
Modules for macros. In reference to: http://thepugautomatic.com/2013/07/dsom/
class SomeORM
def self.attributes(*names)
if const_defined?(:DynamicAttributes, false)
mod = const_get(:DynamicAttributes)
else
mod = const_set(:DynamicAttributes, Module.new)
include mod
end
mod.module_eval do
names.each do |name|
@samstokes
samstokes / regex-groups-global.rb
Created November 18, 2009 03:28
How to extract groups from a regex match in Ruby without globals or temporary variables. Code snippets supporting http://blog.samstokes.co.uk/post/251167556/regex-style-in-ruby
if "foo@example.com" =~ /@(.*)/
$1
else
raise "bad email"
end
# => "example.com"
@raggi
raggi / alias_task.rake
Created November 12, 2009 15:11
A helper to alias a task in rake
def alias_task(name, old_name)
t = Rake::Task[old_name]
desc t.full_comment if t.full_comment
task name, *t.arg_names do |_, args|
# values_at is broken on Rake::TaskArguments
args = t.arg_names.map { |a| args[a] }
t.invoke(args)
end
end