Skip to content

Instantly share code, notes, and snippets.

View texpert's full-sized avatar

Aurel Branzeanu texpert

View GitHub Profile
@texpert
texpert / flatten.rb
Last active October 13, 2019 02:55
Flatten Ruby implementation
# frozen_string_literal: true
def flatten(arg)
return "arg should be an array, but was #{arg.inspect} instead" if arg.nil? || !arg.is_a?(Array)
@result = []
analyze(arg)
@result
end
.modal-dialog {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) !important;
}
src/AppBundle/EventListener/LogoutListener.php:
//
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
@texpert
texpert / document_types.rb
Last active March 15, 2017 16:22 — forked from acuppy/document_types.rb
All major document mime types (Microsoft Office, Apple iWork, Adobe PDF) as a Ruby Module
module DocumentFileTypes
module Microsoft
WORD = %w(
application/msword
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/vnd.openxmlformats-officedocument.wordprocessingml.template
application/vnd.ms-word.document.macroEnabled.12
application/vnd.ms-word.template.macroEnabled.12
).freeze
On Windows set the following environment variables:
QT_SCALE_FACTOR=1
QT_SCALE_FACTOR_ROUNDING_POLICY=PassThrough
QT_USE_PHYSICAL_DPI=1
@texpert
texpert / nginx-config-rails4-with-puma-ssl-version.conf
Created August 8, 2017 23:45 — forked from rkjha/nginx-config-rails4-with-puma-ssl-version.conf
Nginx config for rails 4 application using puma [ssl and non-ssl version]
upstream myapp_puma {
server unix:/tmp/myapp_puma.sock fail_timeout=0;
}
# for redirecting to https version of the site
server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}
require 'active_support'
require 'active_support/all'
require 'action_view'
array = ['a', 'b', 'http://www.example.com/?a=1', 'is a > 0 & a < 10?']
s = array.join(&:html_safe)
safe = array.join(''.html_safe + '').html_safe
safe_doubt = array.join(''.html_safe + '')
safe_sb = ActiveSupport::SafeBuffer.new(array.join)
Code:
-----------------------------
# frozen_string_literal: true
# Install the necessary gems:
# gem install benchmark-ips
# gem install kalibera
require 'benchmark/ips'
Warming up --------------------------------------
Array5#include? 196.263k i/100ms
Array5#find 102.092k i/100ms
Array5#bsearch 173.777k i/100ms
Array5#detect 97.253k i/100ms
Calculating -------------------------------------
Array5#include? 5.089M (±11.0%) i/s - 25.122M in 5.018964s
Array5#find 1.455M (± 4.9%) i/s - 7.351M in 5.062443s
Array5#bsearch 3.555M (± 6.6%) i/s - 17.725M in 5.007809s
Array5#detect 1.496M (± 5.9%) i/s - 7.488M in 5.021683s
Legend:
=> in the meaning column means there's a non-boolean return value
empty columns in Prior Name mean the method didn't exist before
* before a new method name means it's an alias to the prior method
Prior Name New Name Meaning
attribute_was(attr_name) *attribute_in_database(attr_name) current database value of attribute
attribute_change(attr_name) *attribute_change_to_be_saved => the changed value for attribute
attribute_changed?(attr_name) *will_save_change_to_attribute?(attr_name) was attribute modified since last save