Skip to content

Instantly share code, notes, and snippets.

defined_indexes = Model.index_specifications.map { |s| s.fields.map(&:to_s) };
existing_indexes = Model.collection.indexes.map { |i| i['key'].keys };
missing_indexes = defined_indexes - existing_indexes
# => []
extra_indexes = existing_indexes - defined_indexes - [['_id']]
# => []
#################################################################################
@exAspArk
exAspArk / processes_vs_threads.rb
Created August 24, 2017 15:46
Compare Process vs Thread creation / deletion time
# gem install benchmark-ips
require 'benchmark/ips'
Benchmark.ips do |x|
x.warmup = 0
x.report("threads") do
thread = Thread.new { puts 'thread' }
thread.join
end
@exAspArk
exAspArk / web-servers.md
Created May 16, 2017 16:36 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
source 'https://rubygems.org'
gem 'puma'
gem 'sinatra'
gem 'faraday'
gem 'typhoeus'
group :development do
@exAspArk
exAspArk / memory_middleware.rb
Created December 27, 2016 16:12
MemoryMiddleware
class MemoryMiddleware
ENV_REQUEST_PATH = 'REQUEST_PATH'.freeze
ENV_PUMA_AFTER_REPLY = 'rack.after_reply'.freeze
LOGGER = Logger.new('/tmp/memory.log'.freeze)
def initialize(app)
@app = app
end
def call(env)
(export LC_ALL="ru" ; awk '{split($0,l,";") ; print l[2],l[3],l[4]}' ~/.zsh_history | sort | uniq -c | sort -nr | head -n 20)
require "net/http"
require "socket"
socket = "/tmp/portal2.sock"
sock = Net::BufferedIO.new(UNIXSocket.new(socket))
request = Net::HTTP::Get.new("/")
request.exec(sock, "1.1", "/")
begin
@exAspArk
exAspArk / state_machine.rb
Last active February 22, 2016 22:28
HACK StateMachine gem to make it work with ActiveRecord 4.2
# HACK to enable using protected methods from Rails 4.2 and initial states as default attributes for ActiveRecord
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
module ActiveRecord
public :around_save
@exAspArk
exAspArk / The Technical Interview Cheat Sheet.md
Created January 20, 2016 11:11 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@exAspArk
exAspArk / simple_form.rb
Last active December 26, 2015 12:28 — forked from clyfe/simple_form.rb
# http://stackoverflow.com/questions/14972253/simpleform-default-input-class
# https://github.com/plataformatec/simple_form/issues/316
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.boolean_style = :nested
config.wrappers :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error',
defaults: { input_html: { class: 'default_class' } } do |b|