Skip to content

Instantly share code, notes, and snippets.

Justin Halsall Juice10

Block or report user

Report or block Juice10

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Juice10
Juice10 / play.cr
Last active Feb 15, 2019
Calculate what percentage of taxes you'd pay if AOC's 70% tax bracket gets added
View play.cr
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,
}
View main.rb
def main(params = {})
  name = params["name"] || "stranger"
  greeting = "Hello #{name}!"
{ greeting: greeting }
end
@Juice10
Juice10 / main.rb
Created Aug 24, 2018
Bare minimum Serverless action
View main.rb
def main(params)
{ hello: "world" }
end
View Gemfile
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'
View main.rb
# 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 / splitwise-script.js
Last active Nov 12, 2018
Script to set all items in Splitwise to a specific ratio (useful for couples paying rent etc. based on income)
View splitwise-script.js
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 / manifest.yaml
Created Apr 19, 2018
Example manifest.yaml file with a Docker container for OpenWhisk
View manifest.yaml
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
View docker-compose.yml
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
View Dockerfile
# 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" ]
View action.rb
# 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
You can’t perform that action at this time.