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.
Vim Tips:
**g-**
There are a lot of better answers already given (".", "*", and "%" are far more useful), but I vote for "g-" because it is relatively new and feels like magic. Somehow, it always seems to go to the exact text state I want.
Basically, if you make a lot of edits, then undo them, then make one more edit, then decide you want the first set of edits back, most editors can't do it. Emacs can, but it's a pain. g- in Vim will usually take you straight there. {not in Vi}
function fooCallBack(param1, param2) {
window.alert(param1 + param2);
}
function newFoo(num1, num2, callback) {
var result = num1 + num2;
if(callback && typeof callback === 'function') {
callback(result, ' is the result');
}
}
function newFoo(num1, num2, callback) {
var result = num1 + num2;
window.alert(result);
if(callback && typeof callback === 'function') {
callback();
}
}
newFoo(12412, 11, function(){
alert('my callback executed');