Skip to content

Instantly share code, notes, and snippets.

View plukevdh's full-sized avatar
🔥

Luke van der Hoeven plukevdh

🔥
View GitHub Profile
@plukevdh
plukevdh / objectDiff.js
Last active April 11, 2022 13:56
Ramda - Compact diff output for complex objects.
import R from 'ramda'
const isObject = R.compose(R.equals('Object'), R.type);
const allAreObjects = R.compose(R.all(isObject), R.values);
const hasLeft = R.has('left');
const hasRight = R.has('right');
const hasBoth = R.both(hasLeft, hasRight);
const isEqual = R.both(hasBoth, R.compose(R.apply(R.equals), R.values));
const markAdded = R.compose(R.append(undefined), R.values);
@plukevdh
plukevdh / UJS Investigation
Created September 14, 2012 21:51
jQuery <=> rails.js <=> Rails
TL;DR: jQuery <=> rails.js <=> Rails is a strange beast.
Breakdown:
Rails expects a format to translate a request into a response. This could be
HTML, JSON, Script (js request), etc. Usually a straight GET/POST/etc. translates
to HTML. Ajax requests translate to a Script request. An odd thing starts happening
when you start playing with the request type params (or acceptance headers). Rails
has some behind-the-scenes defaults of how it translates requests to response formats
when not specified or if the specified does not exists. This gets confusing the more
response handlers you add.
@plukevdh
plukevdh / hold_music.rb
Created June 23, 2011 21:49
Replicating functionality of the hold music "twimlet" from Twilio (http://labs.twilio.com/twimlets/holdmusic)
require 'httparty'
require 'twilio'
module Twimlet
module HoldMusic
include HTTParty
AWS_URL = "s3.amazonaws.com"
def generate_playlist(bukkit='com.twilio.music.classical', options={})
@bucket = "http://#{bukkit}.#{AWS_URL}"
@plukevdh
plukevdh / transcode.rb
Created June 2, 2018 20:43
Quick and dirty transcoder job
require 'aws-sdk'
Aws.config.update({
region: "us-east-1",
credentials: Aws::SharedCredentials.new(profile_name: "...")
})
PRESET_ID = "..."
PIPELINE_ID = "..."

Keybase proof

I hereby claim:

  • I am plukevdh on github.
  • I am plukevdh (https://keybase.io/plukevdh) on keybase.
  • I have a public key ASAUM0TdYG6iD3RQxK29SEzkPqj18SAcJszaiNe1uZVCzQo

To claim this, I am signing this object:

def envs = [
[env: "stage", region: "us-east-1"]
]
stage("Plan") {
def planJobs = [:]
for(int i = 0; i < envs.size(); i++) {
def details = envs.get(i)
@plukevdh
plukevdh / pipeline-flow.groovy
Last active May 25, 2017 16:41
Dynamic Pipeline Flow Example
// Example envs, could be one of the following
def defaultEnvs = [
[env: "stage", region: "us-east-1"],
[env: "prod", region: "us-east-1"]
]
// Or
def defaultEnvs = [
@plukevdh
plukevdh / leven.ex
Created November 28, 2012 18:17
Levenshtein in elixir
defmodule Levenshtein do
def first_letter_check(one_letter, two_letter) do
case one_letter == two_letter do
true -> 0
false -> 1
end
end
def distance(string_1, string_1), do: 0
def distance(string, ''), do: :string.len(string)
@plukevdh
plukevdh / escaped_path_is_gone.rb
Created July 22, 2014 20:42
escaped_path missing?
RSpec.configure do |config|
config.include InputExampleGroup, type: :input, example_group: {
file_path: config.escaped_path(%w[spec inputs])
}
end
@plukevdh
plukevdh / detect.js
Created October 24, 2016 18:33
Ramda - Type Detection Functions
const isObject = R.compose(R.equals('Object'), R.type);
const isScalar = R.compose(R.not, R.either(isObject, R.isArrayLike), R.last, R.values);