Skip to content

Instantly share code, notes, and snippets.

View marka2g's full-sized avatar
🎯
Focusing

Mark Sadegi marka2g

🎯
Focusing
View GitHub Profile
@marka2g
marka2g / redis.md
Last active August 30, 2018 17:55 — forked from nrollr/Redis.sh
Install Redis via Homebrew

Commands

Install Redis using Homebrew

$ brew install redis

Enable Redis autostart

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

Start Redis server via launchctl

@marka2g
marka2g / curl.md
Last active August 23, 2018 21:13 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@marka2g
marka2g / create_superuser_postgres.sql
Created July 21, 2018 06:45 — forked from njwest/create_superuser_postgres.sql
SQL command for creating PostgreSQL Superuser
CREATE USER postgres WITH PASSWORD 'postgres' SUPERUSER;
@marka2g
marka2g / faker.md
Created March 21, 2018 21:06 — forked from MilanGrubnic70/faker.md
Faker

#Faker

Usage is simple; first grab the gem using your gem program:

$sudo gem install faker

Now you can use it in your favorite ruby program or script. For now let's fire up irb and see what we can fake.

require 'rubygems'  
@marka2g
marka2g / opposite_of_array_intersection.rb
Created March 16, 2018 01:47 — forked from chadmiko/opposite_of_array_intersection.rb
Ruby opposite of array intersection
# Ruby opposite of array intersection... or maybe the method is missing from my brain bc not enough coffee
# http://twitter.com/soawesomeman/status/8035087261
def awesome(ar_1, ar_2)
(ar_1 + ar_2) - (ar_1 & ar_2)
end
awesome([1,2,3,4], [3,4,5,6]) # => [1, 2, 5, 6]
@marka2g
marka2g / measure_require_memory.rb
Last active December 29, 2017 00:17
Monkey Patch Require
# better way - from https://gist.github.com/marka2g/1629357/edit
Kernel.class_eval do
alias :old_require :require
def require(*args)
puts args
old_require(*args)
end
end
@marka2g
marka2g / list-native-gems.rb
Last active December 26, 2017 20:12 — forked from stepheneb/list-native-gems.rb
list RubyGems that have native extensions
#!/usr/bin/env ruby
require 'rubygems'
gempaths = Gem::default_path
puts
puts "Scanning paths in Gem::default_path for RubyGems with native extensions ..."
puts
@marka2g
marka2g / order_days.rb
Created October 24, 2017 00:39
Order By Index
days_array = ["everyday", "school_nights", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
def order_days(hashes)
days_indexes = {}
days_array.each_with_index do |item, index|
days_indexes[item] = index
end
hashes.sort_by do |schedule|
days_indexes.fetch(schedule[:day].downcase)
end
@marka2g
marka2g / gist:61a1c059b84ebeb7167e35ae17141cd2
Created September 14, 2017 21:18 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
const memoize = (fn) => {
let cache = {}, key;
return (...args) => {
key = JSON.stringify(args);
return cache[key] || (cache[key] = fn.call(null, ...args));
}
};