Skip to content

Instantly share code, notes, and snippets.

View shtakai's full-sized avatar
🐤
I am leaning Ada.

Alyson shtakai

🐤
I am leaning Ada.
View GitHub Profile
@shtakai
shtakai / Rakefile
Created September 15, 2020 23:23 — forked from schickling/Rakefile
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@shtakai
shtakai / redux.js
Created February 17, 2020 22:16 — forked from tomasr8/redux.js
Redux in 30 lines
function createStore(reducer) {
const store = {
state: {},
reducer,
dispatch(action) {
this.state = this.reducer(action, this.state)
}
}
store.dispatch({})
@shtakai
shtakai / .md
Created January 3, 2019 07:56 — forked from mbajur/.md
How to create small, unique tokens in Ruby

How to create small, unique tokens in Ruby

That is is basically a "fork" of blog article i'm constantly returning to. It seems that the blog is down:

My choice: Dave Bass’s rand().to_s() trick

Dave Bass proposed this which I picked up for my implementation (here for an 8-chars token):

@shtakai
shtakai / fizzbuzz.rb
Created December 11, 2018 10:11 — forked from Kerrick/fizzbuzz.rb
Different solutions for Fizz Buzz in Ruby
def fizz_buzz_1(max)
arr = []
(1..max).each do |n|
if ((n % 3 == 0) && (n % 5 == 0))
arr << "FizzBuzz"
elsif (n % 3 == 0)
arr << "Fizz"
elsif (n % 5 == 0)
arr << "Buzz"
else
@shtakai
shtakai / money_best_practices.md
Created September 27, 2018 08:57 — forked from abhinavmsra/money_best_practices.md
Tips for Money Related Arithmetic in Ruby

Tips for Money Related Arithmetic in Ruby

  1. Never use float for performing arithmetic calculations relating to money.

    Floating numbers can sometimes show funky behaviour. It is not Ruby’s fault but the very implementation of floating numbers raises precision issues.

Examples of odd behaviour:

@shtakai
shtakai / gist:6cb590247d2a4c11f51758d5e5d9b9d4
Created September 17, 2018 10:00 — forked from ryenus/gist:1518596
Using ruby in place of grep/awk/sed like perl

With options -e, -n, -p, perl can do what grep/awk/sed can, what about ruby?

Let's take the result of ls -l as input and process it with ruby

grep with ruby

\ls -l | ruby -ne 'print if /^d/'

awk with ruby

\ls -l | ruby -ne 'puts split(/\s+/).last if /^d/'

@shtakai
shtakai / spec_helper.rb
Created August 15, 2018 01:46 — forked from adamstegman/spec_helper.rb
Silence RSpec specs
RSpec.configure do |config|
config.before(:all, &:silence_output)
config.after(:all, &:enable_output)
end
# Redirects stderr and stdout to /dev/null.
def silence_output
@orig_stderr = $stderr
@orig_stdout = $stdout
@shtakai
shtakai / mix.txt
Last active April 7, 2018 11:38
`recompile` is not working on mix.
Just
r Module
@shtakai
shtakai / NsTA-1.rb
Created November 7, 2017 11:59
null created by shtakai - https://repl.it/NsTA/1
arr1 = [[1, 2, [3, 4], 5], 6]
arr2 = [[1, 2], 3]
arr3 = [1, [2]]
arr4 = [[1], 2]
arr5 = ["this", ["is", "that", ["Sushi"]], "car"]
arr6 = [["this"], ["is", "that", ["Sushi"]], "car"]
def flat_arr(arr, new_arr=[])
@shtakai
shtakai / 0_reuse_code.js
Created May 15, 2017 08:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console