This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch_events(start, end, timezone) | |
Rails.cache.fetch(cache_key, expires_in: 1.hour.from_now) do | |
GoogleClient.fetch_events | |
end | |
end | |
def cache_key | |
[ | |
start, | |
end, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'google/apis/calendar_v3' | |
class GoogleCalendarController < ApplicationController | |
def redirect | |
client = Signet::OAuth2::Client.new(client_options) | |
redirect_to client.authorization_uri.to_s | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/http" | |
uri = URI.parse('https://tlstest.paypal.com') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
begin | |
request = Net::HTTP::Get.new(uri.request_uri) | |
response = http.request(request) | |
puts response.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
csv do | |
column 'credit id' do |credit| | |
credit.id.to_s | |
end | |
column "account id" do |credit| | |
credit.account_id.to_s | |
end | |
column('enterprise') { |c| c.account && (c.account.enterprise? ? 'yes' : '') || '' } | |
column "client id" do |credit| | |
credit.user && credit.user.id.to_s || 'no user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition(a,p,r) | |
q = 0 | |
pivot = a[r] | |
if p < r | |
(0).upto(r-1) do |j| | |
if a[j] < pivot | |
a[q],a[j] = a[j],a[q] | |
q += 1 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PriorityQueue | |
attr_accessor :a | |
attr_accessor :size | |
def initialize(a) | |
@a = a | |
self.size = a.length | |
build_heap | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# UniqueCustomerTrialPurchaseByMonth | |
SELECT DATE_TRUNC('MONTH', created) as month, | |
COUNT(DISTINCT customer_id) as customer_purchased_trial | |
FROM charges | |
WHERE amount = 3900 AND paid = true AND status = 'succeeded' and refunded = false | |
AND created BETWEEN TIMESTAMP '2023-03-01' AND CURRENT_DATE | |
GROUP BY 1 | |
ORDER BY 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w = [10, 20, 30] | |
b = [60, 100, 120] | |
$result = {} | |
def knaspask(w, b, n, max_w) | |
if n == 0 || max_w == 0 | |
result = 0 | |
else | |
if result = $result["#{n.to_s}-#{max_w.to_s}"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Iterative using visited attribute | |
def in_order_ite | |
s = Stack.new | |
s.push root | |
until s.empty? | |
c = s.last | |
if c.left && !c.left.visited |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def permutations(str, prefix) | |
if str.length == 0 | |
puts prefix | |
else | |
(0).upto(str.length-1) do |i| | |
permutations(str.slice(0,i)+str.slice(i+1, str.length), prefix + str[i]) | |
end | |
end | |
end |
NewerOlder