Skip to content

Instantly share code, notes, and snippets.

# Import Sinatra
require 'sinatra'
# Import Sinatra's JSON package needed for neat JSON responses.
require 'sinatra/json'
# setup port, ip address and environment
set :port, 8080
set :bind, '0.0.0.0'
set :environment, :production
# image with ruby installed
FROM ruby:2.5
# install Sinatra, sinatra helpers and thin, our fast webserver
RUN gem install sinatra && gem install sinatra-contrib && gem install thin
# load our code into the container
ADD action.rb /
# expose port 8080
EXPOSE 8080
# run our ruby script
CMD [ "ruby", "/action.rb" ]
version: '3'
services:
# name of our dockerized action
action:
# current directory is where our projects root
build: .
# docker hub account repo
# IMPORTANT: rename this to your docker hub username/project-name
image: juice10/openwhisk-ruby # rename me!
# expose ports
@Juice10
Juice10 / manifest.yaml
Created April 19, 2018 22:15
Example manifest.yaml file with a Docker container for OpenWhisk
project:
# All of these params you will need to grab from your OpenWhisk credentials page
# In IBM Cloud Functions the url where you can get these is:
# https://console.bluemix.net/openwhisk/learn/api-key
apiHost: REPLACE-ME-WITH-YOUR-API-HOST-FOR-EXAMPLE
# example apiHost: openwhisk.ng.bluemix.net
credential: REPLACE-ME-WITH-YOUR-CREDENTIALS
# credential is the same as your API Key
namespace: REPLACE-ME-WITH-YOUR-NAMESPACE
# exmple namespace: cloud-foundry-org_cloud-foundry-space
@Juice10
Juice10 / splitwise-script.js
Last active November 12, 2018 14:31
Script to set all items in Splitwise to a specific ratio (useful for couples paying rent etc. based on income)
var yearlyIncomePersonA = 120000;
var yearlyIncomePersonB = 100000;
var query = '.expense:not(.summary)'
var delayMultiplier = 20;
var elLength = $(query).length;
var i = 0;
var maxNum = 0; // maximum number of items it should edit
var interval = setInterval(function () {
var elements = $(query).toArray();
var el = elements[i];
@Juice10
Juice10 / main.rb
Last active September 10, 2018 22:34
# initialize standalone bundler
require __dir__ + '/bundle/bundler/setup.rb'
# require the gems we want to use
require 'betterlorem'
def main(params = {})
length = (params["length"] || 20).to_i
{ lipsum: BetterLorem.w(length, true) }
end
@Juice10
Juice10 / Gemfile
Last active September 12, 2018 16:30
source 'https://rubygems.org'
# make sure you are running the same major ruby version locally as will be used in the OpenWhisk Ruby runtime (currently 2.5.0)
ruby '>= 2.5.0', '< 2.6'
# the gems you need for your action
gem 'betterlorem'
@Juice10
Juice10 / main.rb
Created August 24, 2018 15:46
Bare minimum Serverless action
def main(params)
{ hello: "world" }
end
@Juice10
Juice10 / main.rb
Last active September 12, 2018 16:24
def main(params = {})
  name = params["name"] || "stranger"
  greeting = "Hello #{name}!"
{ greeting: greeting }
end
@Juice10
Juice10 / play.cr
Last active February 15, 2019 19:10
Calculate what percentage of taxes you'd pay if AOC's 70% tax bracket gets added
BRACKETS = {
0 => 0.1,
9700 => 0.12,
39475 => 0.22,
84_200 => 0.24,
160_725 => 0.32,
204_100 => 0.35,
510_300 => 0.37,
10_000_000 => 0.70,
}