Skip to content

Instantly share code, notes, and snippets.

@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@db42
db42 / ruby-upload-s3.rb
Created February 9, 2018 12:19
Ruby script to upload a file to amazon s3
require 'aws-sdk-s3' # v2: require 'aws-sdk'
ACCESS_KEY_ID = ""
SECRET_ACCESS_KEY = ""
REGION_ID = "us-east-1"
BUCKET_NAME = "bucket-name"
def uploadS3
credentials = Aws::Credentials.new(
ACCESS_KEY_ID,
@thorstenspringhart
thorstenspringhart / clean_code.rake
Created January 26, 2018 21:47
extended rake tasks to run rubocop only on uncommitted files / diff with master or entire project
namespace :clean_code do
# rubcop only available in dev
if Rails.env.development?
require 'rubocop/rake_task'
def diff_files
cmd = %q( git diff --name-only --diff-filter=ACMRTUXB \
$(git merge-base HEAD origin/master) \
| egrep '\.rake$|\.rb$' )
diff = `#{cmd}`
diff.split("\n")
@schweigert
schweigert / Embedding GoLang into a Ruby application.md
Last active May 3, 2024 19:23
Embedding GoLang into a Ruby application - Blogpost to Magrathealabs

Go Title

I am passionate about Ruby, but its execution time compared to other languages is extremely high, especially when we want to use more complex algorithms. In general, data structures in interpreted languages become incredibly slow compared to compiled languages. Some algorithms such as ´n-body´ and ´fannkuch-redux´ can be up to 30 times slower in Ruby than Go. This is one of the reasons I was interested in embedding Go code in a Ruby environment.

For those who do not know how shared libraries operate, they work in a similar way as DLLs in Windows. However, they have a native code with a direct interface to the C compiler.

Note Windows uses the DLL system, and in this case, this does not necessarily have to be in native code.

One example is DLLs written in C#, which runs on a virtual machine. Because I do not use windows, I ended up not testing if it is poss

@posener
posener / go-shebang-story.md
Last active June 28, 2024 21:18
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@harssh
harssh / checkbox_styling.html
Last active December 29, 2015 16:59
Changing dtyle of checkbox and radio buttons
Styling checkboxes and radio buttons using CSS
The styling of checkboxes and radio buttons became possible with the introduction of the :checked pseudo-class in CSS3. This page describes two techniques: an image-based method, shown in the demonstration below, and a pure CSS method.
Image-based styling
Image-based styling allows the greatest flexibility in appearance. In the example above we combine the images for the three states (unchecked, selected checkbox, and selected radio button) into a single image for faster loading:
HTML of the following form is used for each checkbox or radio button:
@harssh
harssh / usefull_links.txt
Last active December 29, 2015 07:49
usefull links
@harssh
harssh / ransack.rb
Created November 22, 2013 11:34 — forked from ledermann/ransack.rb
# Patch for ransack (https://github.com/ernie/ransack) to use scopes
# Helps migrating from Searchlogic or MetaSearch
# Place this file into config/initializer/ransack.rb of your Rails 3.2 project
#
# Usage:
# class Debt < ActiveRecord::Base
# scope :overdue, lambda { where(["status = 'open' AND due_date < ?", Date.today]) }
# end
#
# Ransack out of the box ignores scopes. Example:
@paulmillr
paulmillr / active.md
Last active June 24, 2024 13:58
Most active GitHub users (by contributions). http://twitter.com/paulmillr

Most active GitHub users (git.io/top)

The count of contributions (summary of Pull Requests, opened issues and commits) to public repos at GitHub.com from Wed, 21 Sep 2022 till Thu, 21 Sep 2023.

Only first 1000 GitHub users according to the count of followers are taken. This is because of limitations of GitHub search. Sorting algo in pseudocode:

githubUsers
 .filter(user =&gt; user.followers &gt; 1000)