Skip to content

Instantly share code, notes, and snippets.

View Grape with a route param.rb
require 'grape'
class API < Grape::API
prefix :api
version 'v1', using: :path
resources :users do
desc 'return all users'
get '/' do
puts 'Users'
View openstruct_vs_class_accessors.rb
require 'ostruct'
require 'benchmark/ips'
class User
attr_accessor :name, :email
def initialize(attrs)
attrs.each { |key, val| send("#{key}=", val) }
end
end
@dnesteryuk
dnesteryuk / index.html
Created May 28, 2019
HTML/JS for testing Cache storage and Disk cache
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<button onClick="clearCache()">Clear cache</button>
<button onClick="loadImages()">Load images</button>
<button onClick="cacheImages()">Cache images</button>
@dnesteryuk
dnesteryuk / request.json
Created Apr 15, 2019
GA request for extracting sessions
View request.json
{
"reportRequests": [
{
"viewId": "YOUR_VIEW_ID_IS_HERE",
"dateRanges": [
{
"startDate": "2015-01-01",
"endDate": "2019-04-10"
}
],
View gist:946145
# --------------------------------------------------------------------
# How to convert n-pass algorithm to one-pass algorithm?
# --------------------------------------------------------------------
require 'fiber'
def each_number
puts "each number orig before"
(1..5).each do |n|
yield(n)
You can’t perform that action at this time.