Skip to content

Instantly share code, notes, and snippets.

if (C)
{
if (c)
{
if (a)
{
return "<link type=\"text/css\" rel=\"preload\" href=\"https://cdn.no{0}\" as=\"style\" onload=\"this.onload=null;this.rel='stylesheet'\" /><noscript><link rel = \"stylesheet\" href=\"https://cdn
.no{0}\"></noscript>";
}
else
@mkurtikov
mkurtikov / Gemfile
Last active February 1, 2017 11:09
sinatra_app
# A sample Gemfile
source "https://rubygems.org"
gem 'rack-contrib'
gem 'sinatra'
gem 'shotgun'
gem "sinatra-param", require: "sinatra/param"
gem 'sinatra-contrib'
class A
def initialize()
@a = 1
end
end
a = A.new
a.instance_variable_get(:@a) # 1
a.instance_variable_set(:@a, 2)
@mkurtikov
mkurtikov / ruby_meta1.rb
Last active September 19, 2016 16:42
Ruby Metaprogramming
'hello'.hello_world # NoMethodError: undefined method `hello_world' for "hello":String
class String
def hello_world
p 'Hello ' + self
end
end
'hello'.hello_world # "Hello hello"
@mkurtikov
mkurtikov / ruby_modules1.rb
Last active February 8, 2017 15:22
Ruby Modules
module A
def self.a
p 'self a'
end
def a
p 'Aa'
end
def b
ERROR:
"error": {
"code": "validation_error",
"description": "Validation failed"
}
"meta": {
"validation_errors": {
"card_number": {
@mkurtikov
mkurtikov / ruby_sintata.rb
Created April 14, 2016 15:47
Sinatra Basics
require 'sinatra'
require 'sinatra/param'
require 'sinatra/json'
set :raise_sinatra_param_exceptions, true
set :show_exceptions, false
get '/hi' do
param :param1, Float, required: true
param :param2, Float, required: true
@mkurtikov
mkurtikov / ruby_exceptions_1.rb
Last active April 14, 2016 17:47
Ruby Exceptions
## http://ruby-doc.org/core-2.3.0/Exception.html
begin
p '1'
1 / 0
rescue
p '2'
end
# "1"
@mkurtikov
mkurtikov / ruby_require.rb
Created April 14, 2016 11:16
Ruby require
## http://ruby-doc.org/core-2.1.2/Kernel.html
# /Users/tmp/a.rb
p 'Hello'
class A
def hello
p 'Hello'
end
@mkurtikov
mkurtikov / ruby_oop_1.rb
Last active April 12, 2016 06:09
Advancep OOP
A = Class.new do
attr_reader :a
def initialize(a)
@a = a
end
end
a = A.new 1
a.class.class #class