Skip to content

Instantly share code, notes, and snippets.

@kmikiy
kmikiy / crypto.gs
Last active June 16, 2022 12:17
Google Sheets Apps Script for fetching latest crypto price from Binance
function BINANCE_PRICE(coinsymbol, pair) {
var url = "https://api.binance.com/api/v3/ticker/price?symbol="+coinsymbol.toUpperCase()+pair.toUpperCase()
var response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
var json = response.getContentText();
var data = JSON.parse(json);
return data.price
}
/*
@jmoe
jmoe / ridb.rb
Created April 11, 2015 15:16
A quick ruby module for interacting with RIDB API
module RIDB
# A set of client classes for new RIDB API
# https://ridb.recreation.gov/api/v1
# http://ridb-dev.nsitellc.com/docs/api/v1/
# Usage:
# > $ridb = RIDB::Client.new(ENV['RIDB_API_KEY'], debug: true)
# Returns a list of organization items
# > $ridb.organizations.list.items
@spalladino
spalladino / can_destroy.rb
Created January 31, 2012 14:42
How to check if object can be destroyed if it has dependent restrict associations
class ActiveRecord::Base
def can_destroy?
self.class.reflect_on_all_associations.all? do |assoc|
assoc.options[:dependent] != :restrict || (assoc.macro == :has_one && self.send(assoc.name).nil?) || (assoc.macro == :has_many && self.send(assoc.name).empty?)
end
end
end