Skip to content

Instantly share code, notes, and snippets.

Ravil Bayramgalin brainopia

Block or report user

Report or block brainopia

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@brainopia
brainopia / readme.md
Created Nov 28, 2018 — forked from techgaun/readme.md
OpenSSH 7.4 on Ubuntu 16.04
View readme.md

Installing OpenSSH 7.4 on Ubuntu 16.04

sudo apt install -y build-essential libssl-dev zlib1g-dev
wget "http://mirrors.evowise.com/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz"
tar xfz openssh-7.4p1.tar.gz
cd openssh-7.4p1
./configure
make
sudo make install
View main.rb
require 'yaml'
require 'json'
require 'bundler/inline'
gemfile _install=true do
source 'https://rubygems.org'
gem 'pry'
gem 'puma'
gem 'sinatra', require: 'sinatra/base'
View swagger-docs.rb
module Docs
def self.extended(version)
version.include Swagger::Blocks
end
def root
Swagger::Blocks.build_root_json [self]
end
concerning :App do
View normalizer.rb
# Usually normalization is performed during `before_validation`
# or in a setter. But neither would help with normalization of
# where conditions.
#
# This will add `normalize` to ActiveRecord with support for
# where conditions. For example,
#
# class User
# normalize(:email) { email.downcase }
# end
View tilt-jbuilder.rb
# This class is used to render jbuilder templates in grape.
#
# There is an existing grape-jbuilder gem but it depends
# on tilt-jbuilder gem which
# - does not support partial! with :collection
# - does not support template compilation
#
# In constrast this template handler supports all features of jbuilder
# and uses template compilation (5x-10x times faster than without).
class Tilt::Jbuilder < Tilt::Template
View docs.gemspec
Gem::Specification.new do |s|
s.name = 'docs'
s.version = '0.0.1'
s.files = ['docs.rb']
s.require_path = '.'
s.add_dependency('swagger-ui_rails', ">= 2.1.0.alpha.7.1")
end
View replace_superclass_pointer_in_memory.rb
require 'fiddle'
A = Class.new
B = Class.new
C = Class.new A
p C.superclass # => A
(Fiddle::Pointer[Fiddle.dlwrap C] + 16)[0, 8] = Fiddle::Pointer[Fiddle.dlwrap B].ref
p C.superclass # => B
View method_calls.rb
def method_calls(detailed: false, thread: nil)
[].tap do |log|
ident = -1
trace = TracePoint.new(:call, :return, :c_call, :c_return) do |tp|
break if thread and thread != Thread.current
case tp.event
when :call, :c_call
if tp.event == :call or detailed
ident += 1
View reduce_allocations_rails_32.rb
# rails 3.X patch to remove extra allocations on field access
module ActiveRecord::AttributeMethods::Read::ClassMethods
def internal_attribute_access_code(attr_name, cast_code)
access_code = "(v=@attributes[attr_name]) && #{cast_code}"
unless attr_name == primary_key
access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ")
end
if cache_attribute?(attr_name)
View gist:8f0a7d83509c80b53c45
def track_sql(&block)
timing = Hash.new 0
track = ->(_,start,finish,_,data) do
Thread.exclusive do
timing[data[:name]] += (finish - start)
end
end
ActiveSupport::Notifications.subscribed(track, 'sql.active_record', &block)
timing
You can’t perform that action at this time.