Skip to content

Instantly share code, notes, and snippets.

View awesome's full-sized avatar

So Awesome Man awesome

View GitHub Profile
@awesome
awesome / strip HTML tags
Created November 3, 2009 16:29
ruby strip HTML tags
# copied from (thanks!): http://codesnippets.joyent.com/posts/show/615
str = <<HTML_TEXT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>Application error</h1>
<p>Change this error message for exceptions thrown outside of an action (like
in Dispatcher setups or broken Ruby code) in public/500.html</p>
@awesome
awesome / raven-shell
Created November 9, 2023 18:36 — forked from barroco/raven-shell
Send Sentry error from shell using curl
#!/bin/sh
SENTRY_KEY=
SENTRY_SECRET=
SENTRY_PROJECTID=1
SENTRY_HOST=sentry.example.com
SCRIPT_ARGUMENTS=$@
capture_error()
{
@awesome
awesome / ruby-multi-line-string-without-newlines-AND-ruby-multi-line-string-without-concatenation.rb
Created November 21, 2013 15:47
Ruby Multi-line String without Newlines —AND— Ruby Multi-line String without Concatenation
##
# by SoAwesomeMan
str =<<-EOS.gsub(/^[\s\t]*|[\s\t]*\n/, '') # no space "\s" for new line "\n"; kill tabs too
select awesome, awesome, awesome, awesome, awesome, awesome,
from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,
where cool cool cool cool cool cool cool cool cool cool cool'
EOS
# => "select awesome, awesome, awesome, awesome, awesome, awesome,from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,where cool cool cool cool cool cool cool cool cool cool cool'"
str =<<-EOS.gsub(/^[\s\t]*/, '').gsub(/[\s\t]*\n/, ' ').strip # yes space "\s" for new line "\n"; kill tabs too
@awesome
awesome / 20210313000000_create_foos.rb
Created October 17, 2023 17:54
`citext` pg column format is case insensitive: https://www.postgresql.org/docs/current/citext.html for ruby on rails migration
# citext pg column format is case insensitive: https://www.postgresql.org/docs/current/citext.html
class EnablePostgresExtensions < ActiveRecord::Migration[6.1]
def change
enable_extension 'citext'
end
end
class CreateFoo < ActiveRecord::Migration[6.1]
def change
create_table :foos, id: :uuid do |t|
@awesome
awesome / macos-sonoma-ruby-install-ruby-3-1-2.sh
Created September 29, 2023 20:25
ruby-install ruby 3.1.2 FAILED? → FIX 🏥🔧🛠️ ( macOS Sonoma 14.0 / Intel Core i7)
# https://github.com/rbenv/ruby-build/discussions/2245#discussioncomment-7022979
export LDFLAGS="-L/opt/brew/Cellar/openssl@1.1/1.1.1v/lib"
export CPPFLAGS="-I/opt/brew/Cellar/openssl@1.1/1.1.1v/include"
export PKG_CONFIG_PATH="/opt/brew/Cellar/openssl@1.1/1.1.1v/lib/pkgconfig"
ruby-install ruby 3.1.2
# $ sysctl -n machdep.cpu.brand_string
# > Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
@awesome
awesome / jQuery-non-AJAX-POST.coffee
Created October 25, 2012 17:42
jQuery non-AJAX POST
# function submit(action, method, values) {
# var form = $('<form/>', {
# action: action,
# method: method
# });
# $.each(values, function() {
# form.append($('<input/>', {
# type: 'hidden',
# name: this.name,
# value: this.value
@awesome
awesome / .gitconfig
Created February 23, 2023 00:06 — forked from joelpittet/.gitconfig
kaleidoscope git mergetool config
# Kaleidoscope.app as difftool and mergetool.
[difftool "Kaleidoscope"]
cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
[diff]
tool = Kaleidoscope
[difftool]
prompt = false
[mergetool "Kaleidoscope"]
cmd = ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot
trustExitCode = true
@awesome
awesome / README.md
Created January 13, 2023 22:36 — forked from basti/README.md
AWS S3 CORS configuration for Rails ActiveStorage

AWS S3 now uses JSON for CORS configuration and cors.json is minimal configuration for Rails 7 direct uploads.

@awesome
awesome / load_dotenv.sh
Created January 13, 2023 20:30 — forked from mihow/load_dotenv.sh
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@awesome
awesome / how-to-get-the-directory-of-the-current-file-using-ruby.rb
Last active December 15, 2022 20:23
how to get the directory of the current file using ruby #soawesomeman
# UPDATE: Ruby 2.0.0 https://docs.ruby-lang.org/en/2.0.0/Kernel.html#method-i-__dir__
# $ ruby -v
# ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
# $ pwd
# /Users/dev/Documents/Github/Gists/awesome/
# $ echo "puts __dir__" > how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb
# $ cat how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb
# puts __dir__
# $ ruby how-to-get-the-directory-of-the-current-file-using-ruby-2-0-0.rb