Skip to content

Instantly share code, notes, and snippets.

View rugyoga's full-sized avatar

Guy Argo rugyoga

View GitHub Profile
@rugyoga
rugyoga / echo.rb
Created March 8, 2016 19:11
ruby echo
#!/usr/bin/env ruby
while a = gets
puts "#{a}"
end
import java.io.*;
class Echo
{
public static void main(String[] args)
throws IOException
{
BufferedReader reader = reader = new BufferedReader(new InputStreamReader(System.in));
String line;
@rugyoga
rugyoga / solve.rb
Created July 27, 2019 19:02
Backtracking solution to n queens
def solve(file = 0, &block)
if file == @size
yield self
else
@size.times do |rank|
next if unsafe?(file, rank)
move!(file, rank)
solve(file + 1, &block)
unmove!(file, rank)
def northwest(file, rank)
file + rank
end
def northeast(file, rank)
file + @size - rank
end
def unsafe?(file, rank)
@queens.any? do |f, r|
@rugyoga
rugyoga / n_queen_counts.rb
Created July 27, 2019 19:07
N Queens solutions using counts
class NQueensCounts < NQueens
def initialize(size)
super(size)
@attacks =
Array.new(size) do |file|
Array.new(size) { |rank| attacks_all(file, rank) }
end
@counts = Array.new(size) { Array.new(size) { 0 } }
end
@rugyoga
rugyoga / bitmask_operators.rb
Created July 27, 2019 19:12
Bitmask operators
def get?(bitmask, offset)
(bitmask >> offset) & 1 == 1
end
def set!(bitmask, offset)
(1 << offset) | bitmask
end
def clear!(bitmask, offset)
~(1 << offset) & bitmask
@rugyoga
rugyoga / n_queens_bitwise.rb
Created July 27, 2019 19:13
Bitmask based solution to N queens
def unsafe?(file, rank)
get?(@ranks, rank) ||
get?(@northwests, northwest(file, rank)) ||
get?(@northeasts, northeast(file, rank))
end
def move!(file, rank)
super(file, rank)
@ranks = set!(@ranks, rank)
@northwests = set!(@northwests, northwest(file, rank))
@rugyoga
rugyoga / n_queens_bitmask.cr
Created July 27, 2019 19:15
Crystal implementation of the bitmask solution to n queens
class NQueensBitarrays < NQueens
def initialize(size : Int32)
super(size)
@ranks = Array(Bool).new(n){ false }
@northwests = Array(Bool).new(2*size){ false }
@northeasts = Array(Bool).new(2*size){ false }
end
def unsafe?(file, rank)
@ranks[rank] ||

Using Elixir releases and multi-stage Docker files to simplify Phoenix deployment

This repo is my experiment in deploying a basic Phoenix app using the release feature from elixir 1.9 (https://elixir-lang.org/blog/2019/06/24/elixir-v1-9-0-released/) and docker, via a multi-stage Dockerfile (https://docs.docker.com/develop/develop-images/multistage-build/) leveraging bitwalker's docker images for Elixir and Phoenix.

Step 1: Install Elixir 1.9.1 (and Erlang)

The simplest way to manage Elixir versions is to use asdf.

@rugyoga
rugyoga / post_plsm.rb
Created November 6, 2019 20:54
I ran into some issues using `plsm` library with Phoenix 1.4.10 and El;ixir 1.9. This script remedied most of them.
# frozen_string_literal: true
require 'active_support/inflector'
module PatchedString
refine String do
def camelcase
split('_').map(&:capitalize).join
end
end