Skip to content

Instantly share code, notes, and snippets.

View monorkin's full-sized avatar
👻
Boo!

Stanko Krtalić monorkin

👻
Boo!
View GitHub Profile
f = -> x { x + 2 }
g = -> x { x * 2 }
# h is the composition of f and g
h = f >> g
# h is the same as -> x { (x + 2) * 2 }
[1, 2, 3].map(&h) # => [6, 8, 10]
# This is exactly the same as
[1, 2, 3].map(&f).map(&g) # => [6, 8, 10]
fetch_transactions =
ApiClient.new(api_token).method(:get)
>> JSON.method(:parse)
>> (-> response { response['data']['transactions'] })
fetch_transaction.call('/api/current_user/transactions')
f = -> x { x + 2 }
g = -> x { x * 2 }
# h is the composition of g and f
h = f << g
# h is the same as -> x { (x * 2) + 2 }
[1, 2, 3].map(&h) # => [4, 6, 8]
# This is exactly the same as
[1, 2, 3].map(&g).map(&f) # => [4, 6, 8]
require 'net/http'
require 'uri'
require 'json'
fetch =
self.method(:URI) \
>> Net::HTTP.method(:get) \
>> JSON.method(:parse) \
>> -> response { response.dig('bpi', 'EUR', 'rate') || '0' } \
>> -> value { value.gsub(',', '') } \
# Copyright 2018 Stanko K.R. <[email protected]>
#
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject
# to the following conditions:
# This code is license under the MIT license
# Full text: https://opensource.org/licenses/MIT
# Author Stanko K.R. <[email protected]>
# Usage:
# ```ruby
# user.avatar = S3UrlToShrineObjectConverter.call(
# arguments[:input][:avatar][:url],
# name: arguments[:input][:avatar][:filename]
# )
mutation SetAvatar($url: String, $filename: String) {
updateUser(
id: "some_user_uuid"
input: {
avatar: {
filename: $filename
url: $url
}
}
) {
mutation SetAvatar($data: String, $filename: String) {
updateUser(
id: "some_user_uuid"
input: {
avatar: {
filename: $filename
data: $data
}
}
) {
user.avatar_data_uri = arguments[:input][:avatar][:data]
user.save
mutation UploadGalleryImages {
uploadGalleryImages(
galleryID: "some_gallery_id"
images: [null, null]
) {
id
filename
url
}
}