Skip to content

Instantly share code, notes, and snippets.

@khamusa
khamusa / postgres_custom_enums_on_rails_schema_migrations.rb
Last active January 12, 2022 14:19
Support custom postgres enum types on rails migrations and schema.rb
# frozen_string_literal: true
# Adds migration and schema.rb support to postgres custom enum types, tested on rails 4.2
# The implementation is quite fragile against ActiveRecord version upgrades since it touches many core AR classes.
# The following code should be placed in an initializer
# On migrations:
#
# create_enum(:mood, %w(happy great been_better))
# create_table :person do
# t.enum :person_mood, enum_name: :mood
# end
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
@jwilson8767
jwilson8767 / es6-element-ready.js
Last active October 10, 2024 00:35
Wait for an element to exist. ES6, Promise, MutationObserver
// MIT Licensed
// Author: jwilson8767
/**
* Waits for an element satisfying selector to exist, then resolves promise with the element.
* Useful for resolving race conditions.
*
* @param selector
* @returns {Promise}
*/
@lvonk
lvonk / Cursor.rb
Last active July 7, 2024 12:20
Simple postgres cursor
# Use as
Cursor.new(Model.includes(foos: [:bar], :foo_bars).where(id < 1000000)).find_each do |model|
# do something
end
# Inspired by https://github.com/afair/postgresql_cursor
class Cursor
class NoopObserver
def close_failed(e)
end
@MarkMurphy
MarkMurphy / README.md
Last active March 25, 2022 21:47
ActiveRecord: Store Milliseconds (or Microseconds) in Timestamps with Rails / MySQL

ActiveRecord: Store Milliseconds (or Microseconds) in DateTimes or Timestamps with Rails / MySQL

Milliseconds in your DateTimes or Timestamps.

We got 'em, you want 'em.

NOTE: only MySQL 5.6.4 and above supports DATETIME's with more precision than a second. For reference see MySQL 5.6.4 Changelog

Why

Shit needs to be PRECISE

@tomysmile
tomysmile / brew-java-and-jenv.md
Last active September 30, 2024 19:44
How To Install Java 8 on Mac

Install HomeBrew first

brew update
brew tap caskroom/cask
brew install brew-cask

If you get the error "already installed", follow the instructions to unlink it, then install again:

@subfuzion
subfuzion / curl.md
Last active November 19, 2024 20:02
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@attenzione
attenzione / boolean_value.rb
Last active June 11, 2020 08:22
Ruby: casting to boolean value
class BooleanValue
# https://github.com/rails/rails/blob/master/activemodel/lib/active_model/type/boolean.rb
FALSE_VALUES = [
false, 0,
"0", :"0",
"f", :f,
"F", :F,
"false", :false,
"FALSE", :FALSE,
"off", :off,
@gmodarelli
gmodarelli / pre-commit
Last active December 7, 2021 11:20
RuboCop with git pre-commit
#!/bin/sh
#
# Check for ruby style errors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
if git rev-parse --verify HEAD >/dev/null 2>&1
@iamatypeofwalrus
iamatypeofwalrus / generate_ctags.md
Last active February 11, 2019 10:17
Generate ctags for Atom (or for any other reason) on Mac os X

Why?

Atom can automagically picks up any tags file in your current directory which enables you to:

  • shift+cmd+r search for any function in your project
  • alt+cmd+down GoTo a function declaration

How

Get brew if you don't already have it. Then:

brew install ctags