Skip to content

Instantly share code, notes, and snippets.

View zzidante's full-sized avatar

Zzi/Mel zzidante

  • Vancouver
View GitHub Profile
@zzidante
zzidante / exclude.sql
Created November 3, 2022 17:24 — forked from fphilipe/exclude.sql
PostgreSQL EXCLUDE constraint
CREATE EXTENSION btree_gist;
CREATE TABLE room_reservations (
room_id integer,
reserved_at timestamptz,
reserved_until timestamptz,
canceled boolean DEFAULT false,
EXCLUDE USING gist (
room_id WITH =, tstzrange(reserved_at, reserved_until) WITH &&
) WHERE (not canceled)
@zzidante
zzidante / README.md
Created May 17, 2022 22:17 — forked from joyrexus/README.md
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")
@zzidante
zzidante / CHRUBY_add_ruby_version.md
Created February 14, 2022 04:16 — forked from yannvery/CHRUBY_add_ruby_version.md
CHRUBY - How to install a new ruby version

Install a new ruby version with chruby

OSX

First of all you must update ruby-build to update definitions list.

brew update

And update ruby-build

@zzidante
zzidante / install_ruby_rpi.sh
Created May 16, 2019 06:07 — forked from blacktm/install_ruby_rpi.sh
A Bash script to install Ruby 2.6 on the Raspberry Pi (Raspbian)
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Installs Ruby 2.6 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s https://gist.githubusercontent.com/blacktm/8302741/raw/install_ruby_rpi.sh)
# --------------------------------------------------------------------------------------------
# Welcome message
@zzidante
zzidante / simple_and_fake_jasmine_describe_it_expect_equalsto_pattern.js
Last active April 30, 2019 14:46
A simple (and assumed) example of how Jasmine works under the hood using Describe->It->Expect->EqualsTo pattern. Meant to help to understand the workings of tests rather than being accurate to Jasmine itself.
// Run the file `node simple_and_fake_jasmine_describe_it_expect_equalsto_pattern.js` from containing folder.
// Should receive 1 passing and 1 failing test (as noted by text color -> Green/Red).
// To understand: read from the call site and work backwards.
// -- Fancy console printing like tests do (no emojis yet) -- //
const printToConsole = function(text, status = 'normal', padding = false) {
const CC = {
Reset: '\x1b[0m',
Underscore: '\x1b[4m',
FgRed: '\x1b[31m',
@zzidante
zzidante / expect_assertion_inner_workings_example.js
Last active April 28, 2019 07:44
A very basic implementation of `expect` as seen in mocha/jasmine test libraries to help new coders understand some of the magic behind testing and method/property chaining.
// A super simple no-edge case version of the `expect` function
// as seen in mocha/jasmine test environments.
// Long form
// step one: define a function called `expect` which takes one value.
// This value is intended to be the return value of a function.
const expect = function(actualValue) {
// assign a property onto `expect` called 'equalsTo' which is
// itself a function taking one argument (using `this` keyword
@zzidante
zzidante / Rakefile
Created April 20, 2019 04:59
Sequel Rake tasks for a Sinatra app
# change foo to your library name
# change Foo::Database to your Sequel database
namespace :bundler do
task :setup do
require 'rubygems'
require 'bundler/setup'
end
end
@zzidante
zzidante / Floatify_String.rb
Created February 26, 2019 23:13
Floatify_String ->Float or Nil
def floatify_string?(val)
# if its already a number type, return it
return val if (val.class == Integer || val.class == Float)
# pre-match zero so that we can initially weed out all no-numeric strings as unparseable
return 0.0 if val == "0" || val == "0.0"
return nil if val.to_f == 0.0 # "Hello".to_f => 0.0
# only match float-like looking values: "1.0" => 1.0, "1" => 1.0, "0.001" => 0.001, "01345345" => 1345345.0
return val.to_f if val =~ /^[-+]?[0-9]*\.?[0-9]+$/
@zzidante
zzidante / Hash Keys to Symbols.rb
Created January 30, 2019 21:54 — forked from Integralist/Hash Keys to Symbols.rb
Convert Ruby Hash keys into symbols
hash = { 'foo' => 'bar' }
# Version 1
hash = Hash[hash.map { |k, v| [k.to_sym, v] }]
# Version 2
hash = hash.reduce({}) do |memo, (k, v)|
memo.tap { |m| m[k.to_sym] = v }
end

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger