Skip to content

Instantly share code, notes, and snippets.

@joshuaob
joshuaob / Cosine.rb
Created May 28, 2023 11:55 — forked from DDimitris/Cosine.rb
Cosine Similarity Ruby
class Cosine
def initialize vecA, vecB
@vecA = vecA
@vecB = vecB
end
def calculate_similarity
return nil unless @vecA.is_a? Array
return nil unless @vecB.is_a? Array
return nil if @vecA.size != @vecB.size
@joshuaob
joshuaob / responsive-video.css
Created January 14, 2018 18:32 — forked from jaicab/responsive-video.css
Pure CSS solution for embed videos with an aspect ratio of 16:9
.video-container {
position: relative;
padding-bottom: 56.25%; /*16:9*/
padding-top: 30px;
height: 0;
overflow: hidden;
}
.video-container iframe,
.video-container object,
@joshuaob
joshuaob / puma.service
Created September 2, 2017 09:25 — forked from arteezy/puma.service
Manage Puma with systemd on Ubuntu 16.04 and rbenv
[Unit]
Description=Puma Rails Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/app/current
ExecStart=/home/deploy/.rbenv/bin/rbenv exec bundle exec puma -C /home/deploy/app/shared/config/puma.rb
ExecStop=/home/deploy/.rbenv/bin/rbenv exec bundle exec pumactl -S /home/deploy/app/shared/tmp/pids/puma.state stop
@joshuaob
joshuaob / gist:a951718c8c281f6858b44ab0e4fa1b1b
Created June 29, 2017 18:18 — forked from markbates/gist:4240848
Getting Started with Rack

If you're writing web applications with Ruby there comes a time when you might need something a lot simpler, or even faster, than Ruby on Rails or the Sinatra micro-framework. Enter Rack.

Rack describes itself as follows:

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Before Rack came along Ruby web frameworks all implemented their own interfaces, which made it incredibly difficult to write web servers for them, or to share code between two different frameworks. Now almost all Ruby web frameworks implement Rack, including Rails and Sinatra, meaning that these applications can now behave in a similar fashion to one another.

At it's core Rack provides a great set of tools to allow you to build the most simple web application or interface you can. Rack applications can be written in a single line of code. But we're getting ahead of ourselves a bit.

# format and mount volume according to Digital Ocean instructions
# I followed the instructions found by clicking the "config instructions" link on the volume
#
$ sudo mkfs.ext4 -F /dev/disk/by-id/scsi-0DO_Volume_volume-fra1-01
$ sudo mkdir -p /mnt/volume-fra1-01;
$ sudo mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-fra1-01 /mnt/volume-fra1-01;
$ echo /dev/disk/by-id/scsi-0DO_Volume_volume-fra1-01 /mnt/volume-fra1-01 ext4 defaults,nofail,discard 0 0 | sudo tee -a /etc/fstab
$ sudo reboot
$ ls /mnt/
#
@joshuaob
joshuaob / create_user.sh
Created May 29, 2017 22:40 — forked from chloerei/create_user.sh
Create a deploy user with githu keys when setup vps
#!/bin/bash
USER=deploy
KEYS_PATH=https://github.com/chloerei.keys
useradd -s /bin/bash -m deploy
passwd $USER
adduser $USER sudo
mkdir /home/$USER/.ssh
wget $KEYS_PATH -O /home/$USER/.ssh/authorized_keys
@joshuaob
joshuaob / Git push deployment in 7 easy steps.md
Created May 26, 2017 19:39 — forked from thomasfr/Git push deployment in 7 easy steps.md
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@joshuaob
joshuaob / digital_ocean_setup.md
Created May 26, 2017 15:37 — forked from ChuckJHardy/digital_ocean_setup.md
DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3 Setup Instructions
@joshuaob
joshuaob / nginx.conf
Created May 26, 2017 15:36 — forked from kennethkalmer/nginx.conf
Sample nginx config for serving a rails API and static frontend like Ember on the same domain...
daemon off;
worker_processes 4;
events {
use epoll;
accept_mutex on;
multi_accept on;
worker_connections 1024;
}
@joshuaob
joshuaob / awesome-nginx.conf
Created May 26, 2017 15:31 — forked from vjt/awesome-nginx.conf
*AWESOME* nginx configuration for Ruby/Rack web applications
#
# mmm m m mmm mmm mmm mmmmm mmm
# " # "m m m" #" # # " #" "# # # # #" #
# m"""# #m#m# #"""" """m # # # # # #""""
# "mm"# # # "#mm" "mmm" "#m#" # # # "#mm"
#
# nginx configuration For Ruby/Rack web applications
#
# Cooked up with style, care and a bit of *secret*
# nerdy spice. :-)