Skip to content

Instantly share code, notes, and snippets.

@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
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 / 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 / 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
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
# 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" ]
# 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
@Juice10
Juice10 / directory.txt
Last active April 19, 2018 21:50
File structure
Dockerfile
docker-compose.yml
manifest.yaml
action.rb
@Juice10
Juice10 / billing_ruby_examples.rb
Created January 29, 2016 15:54
Billing Examples in Ruby
# please substitute your username and api key below,
# SoftLayer library will look to see if these global variables are set when making a connection
# more information here: https://github.com/softlayer/softlayer-ruby/blob/master/lib/softlayer/Config.rb#L11-L58
SL_API_USERNAME = "<your username here>"
SL_API_KEY = "<your apikey here>"
require 'softlayer_api' # Requires softlayer_api >= 3.2
require 'pp' # used to display results
# Create a client
@Juice10
Juice10 / list-packages.py
Created October 23, 2015 13:52
List SoftLayer package ids for ordering via SoftLayer_Product_Order (in python). For ordering see: https://softlayer.github.io/python/create_server_from_template/
import SoftLayer
from pprint import pprint as pp
# HELP: please scroll to the very bottom to see how this works
class example():
def __init__(self):
self.client = SoftLayer.Client()