Skip to content

Instantly share code, notes, and snippets.

View thegreyfellow's full-sized avatar
🏠
Working Remotely

Youssef Idmoussi thegreyfellow

🏠
Working Remotely
  • Rabat, Morocco.
  • 20:22 (UTC -12:00)
View GitHub Profile
#recursively require all files in directory (and subdirectories)
Dir["#{File.dirname(__FILE__)}/squat/**/*.rb"].each {|file| require file }
#recursively require all files in directory but skip paths that match a pattern
Dir["#{File.dirname(__FILE__)}/squat/**/*.rb"].each do |file|
require file unless file =~ /\/model\//
end
@TeWu
TeWu / gist:1234573
Last active February 2, 2022 20:23
TCP client and multithreaded server in 14 lines of Ruby code

TCP client and multithreaded server in 14 lines of Ruby code

Server:

require "socket"
server = TCPServer.open(2626)
loop do
	Thread.fork(server.accept) do |client| 
 client.puts("Hello, I'm Ruby TCP server", "I'm disconnecting, bye :*")
@joshmcarthur
joshmcarthur / .vimrc.local
Created December 12, 2011 22:14
Add JBuiler syntax highlighting to VIM
" add jbuilder syntax highlighting
au BufNewFile,BufRead *.json.jbuilder set ft=ruby

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@andreareginato
andreareginato / spec_helper.rb
Created October 2, 2012 16:48
Rails Spec Helper (using Spork, Mongoid, Factory Girls, Draper, Webmock and Capybara)
require 'rubygems'
require 'spork'
# This code runs once when you run your test suite
Spork.prefork do
ENV['RAILS_ENV'] ||= 'test'
# Mongoid models reload
require 'rails/mongoid'
Spork.trap_class_method(Rails::Mongoid, :load_models)
@andreareginato
andreareginato / Guardfile
Created October 2, 2012 16:49
Rails Guardfile (handle Spork and RSpec automatic tests)
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch(%r{^config/locales/.+\.yml$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
end
@sedm0784
sedm0784 / CapsLockCtrlEscape.ahk
Last active July 16, 2024 11:14
AutoHotkey script to map Caps Lock to Escape when it's pressed on its own and Ctrl when used in combination with another key, à la Steve Losh. Adapted from one that does something similar with the Ctrl Key on the Vim Tips Wiki (http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_Windows?oldid=32281). (Plus contribs from @randy909 & @mmikeww.)
g_LastCtrlKeyDownTime := 0
g_AbortSendEsc := false
g_ControlRepeatDetected := false
*CapsLock::
if (g_ControlRepeatDetected)
{
return
}
@alecguintu
alecguintu / bm-string-contains-any-in-array.rb
Created April 29, 2014 03:33
Check if string contains any substring in an array in Ruby
require 'benchmark'
iterations = 1_000_000
words = 'foo, bar, test, boo'.split(',').map(&:strip)
string = 'this is going foo be awesome~!'
Benchmark.bmbm do |bm|
bm.report do
iterations.times do
words.any? { |s| string.include?(s) }
end
@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active June 20, 2024 02:39
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@christiangenco
christiangenco / download_egghead_videos.md
Last active January 29, 2024 03:16 — forked from ldong/download_egghead_videos.md
download egghead videos