Skip to content

Instantly share code, notes, and snippets.

View mechanicles's full-sized avatar

Santosh Wadghule mechanicles

View GitHub Profile
colorize_logs.png
@mechanicles
mechanicles / Gemfile
Created June 27, 2020 08:13 — forked from dhh/Gemfile
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@mechanicles
mechanicles / findLocalItems.js
Created June 6, 2020 17:51 — forked from n0m4dz/findLocalItems.js
how to filter keys from localStorage with a regex
// returns an array of localStorage items in key/value pairs based on a query parameter
// returns all localStorage items if query isn't specified
// query can be a string or a RegExp object
function findLocalItems (query) {
var i, results = [];
for (i in localStorage) {
if (localStorage.hasOwnProperty(i)) {
if (i.match(query) || (!query && typeof i === 'string')) {
value = JSON.parse(localStorage.getItem(i));
@mechanicles
mechanicles / profile_with_freeze.rb
Created March 1, 2016 15:18
Profile with freeze
require 'memory_profiler'
require 'active_support/core_ext/string'
def translate_using_freeze(key)
if key.to_s.first == '.'.freeze
"products/index".tr('/'.freeze, '.'.freeze)
end
end
report = MemoryProfiler.report(ignore_files: 'active_support/core_ext/string') do
@mechanicles
mechanicles / profile_without_freeze.rb
Created March 1, 2016 15:17
Profile without freeze
require 'memory_profiler'
require 'active_support/core_ext/string'
def translate_without_freeze(key)
if key.to_s.first == '.'
"products/index".tr('/', '.')
end
end
report = MemoryProfiler.report(ignore_files: 'active_support/core_ext/string') do
@mechanicles
mechanicles / methods.rb
Last active March 1, 2016 09:44
first() & last() methods behave differently with limit.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@mechanicles
mechanicles / gist:d58818713e55fd4b1bc0
Last active August 29, 2015 14:22
JavaScript ES6: Simple Generator Example.
// Example 1
function* numbers(){
var n = 1;
var a;
while(true) {
a = yield n++;
console.log('a:', a);
}
};
@mechanicles
mechanicles / gist:2d015c1df47ab237e54e
Created October 9, 2014 17:15
Partial Application Example in Ruby.
# Partial Application Example in Ruby
# We have this string 'all mimsy were the borogoves' and we need to convert this
# string into another string and it contains 3 characters or less than 3
# characters of words.
split = -> (string) {
string.split(' ')
}
capitalize = -> (words_array) {
@mechanicles
mechanicles / gist:5cbdd802d8e49db89236
Last active August 29, 2015 14:05
Ruby's hash sort speed comparison.
# using ruby-2.1.1
require "benchmark"
n = 100_000
hash = { "for" => "sale",
"to_price" => "1000000",
"bath" => "0;6",
"bed" => "0;6",