Skip to content

Instantly share code, notes, and snippets.

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@isaidspaghetti
isaidspaghetti / index.js
Last active February 9, 2021 20:26
Index createHubspotContact
//backend/routes/index.js:10
async function createHubspotContact(firstName, lastName, email) {
let hubspotContact;
try {
hubspotContact = await axios.get(`https://api.hubapi.com/crm/v3/objects/contacts/${email}/?idProperty=email&hapikey=${hubspotKey}`);
}
catch {
hubspotContact = await axios.post(`https://api.hubapi.com/crm/v3/objects/contacts?hapikey=${hubspotKey}`,
{
properties: {
@bazzel
bazzel / README.md
Last active July 27, 2024 16:48
Webpacker and I18n
$ rails new my-i8n --webpack

Gemfile

gem 'i18n-js'
@ginjo
ginjo / omniauth-slack-integration.md
Last active February 20, 2024 21:50
OmniAuth::Slack OAuth2 Cycle Description and Integration Notes

OmniAuth::Slack OAuth2 Cycle Description and Integration Notes

This document was written for the ginjo-omniauth-slack ruby gem. It attempts to clarify the OAuth2 authorization cycle and how that cycle is implemented in your appliation with the ginjo-omniauth-slack gem.

OAuth2

The OAuth2 cycle is a three-way dance between the user's browser, the OAuth2 provider (Slack API), and the application server (your Slack App). It should work this way for any OAuth2 provider, including Slack.

  1. The user/browser makes a request to https://slack.com/oauth/authorize, passing the application's client-id, requested-scopes, and optionally state, team-id, and redirect-uri. Slack then runs the user through the authorization dialogs.
@JasonTrue
JasonTrue / searchkick_and_elasticsearch_guidance.md
Last active March 11, 2025 03:37
Searchkick and Elastic Search guidance

Resources:

https://github.com/ankane/searchkick

Indexing

By default, simply adding the call 'searchkick' to a model will do an unclever indexing of all fields (but not has_many or belongs_to attributes).

In practice, you'll need to customize what gets indexed. This is done by defining a method on your model called search_data

def search_data

@zthxxx
zthxxx / Activate Office 2019 for macOS VoL.md
Last active October 10, 2025 10:59
crack activate Office on mac with license file
@berkedel
berkedel / flow-error-icu4c-not-loaded.md
Created April 4, 2018 14:13
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib

How to solve dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib

brew uninstall --ignore-dependencies node icu4c
brew install node
@mattfwood
mattfwood / titleize.js
Created February 22, 2018 22:03
Ruby-like "titleize" string method
module.exports = String.prototype.titleize = function () {
// avoid conflict with other native methods
if (!String.prototype.titleize) {
// clear underscores
let value = this.valueOf().replace('_', ' ');
let words = value.split(' ');
words = words.map(word => {
word = word.charAt(0).toUpperCase() + word.substring(1);
return word;
});
@ventsislaf
ventsislaf / rails_sql_in_console.md
Created July 12, 2015 12:58
Show SQL queries in Rails console

Execute this in the Rails console and then all SQL queries from ActiveRecord will be shown:

ActiveRecord::Base.logger = Logger.new(STDOUT)
@eliotsykes
eliotsykes / rails_new_help_output.md
Last active July 28, 2025 11:02
"rails new" options explained

Run rails new --help to view all of the options you can pass to rails new:

$ bin/rails new --help
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice
                                                         # Default: /Users/eliot/.rbenv/versions/2.2.0/bin/ruby