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 / util.ex
Created May 13, 2020 16:35 — forked from nathan-cruz77/util.ex
Elixir's equivalent of Rails blank? and present? methods
defmodule Util do
defmacro __using__(_) do
quote do
require Util
# Should it be imported?
# import Util
end
end
defmacro blank?(x) when is_binary(x) do
@marka2g
marka2g / sha256-hmac.md
Created May 8, 2020 20:30 — forked from jasny/sha256-hmac.md
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

@marka2g
marka2g / simple_redis_profile.rb
Created April 8, 2020 01:54 — forked from joeyAghion/simple_redis_profile.rb
By sampling keys from your redis databases, this script tries to identify what types of keys are occupying the most memory.
#!/usr/bin/env ruby
# Evaluates a sample of keys/values from each redis database, computing statistics for each key pattern:
# keys: number of keys matching the given pattern
# size: approximation of the associated memory occupied (based on size/length of value)
# percent: the proportion of this 'size' relative to the sample's total
#
# Copyright Weplay, Inc. 2010. Available for use under the MIT license.
@marka2g
marka2g / redis_cheatsheet.bash
Created March 18, 2020 02:09 — forked from LeCoupa/redis_cheatsheet.bash
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
redis-server /path/redis.conf # start redis with the related configuration file
redis-cli # opens a redis prompt
# Strings.
@marka2g
marka2g / message.md
Created March 14, 2020 05:01 — forked from skplunkerin/message.md
rails custom error message validation without column

Best solution:

http://stackoverflow.com/a/808776/1180523

# model
validates   :email,    :uniqueness => { message: "is wrong" }
validates   :name,    :uniqueness => { message: "Your name is wrong" }

HUMANIZED_ATTRIBUTES = {
  :email => "E-mail address",
  :name => "" # don't include column name in error
@marka2g
marka2g / gist:a9841647dbb25e5444f2e6293e822733
Created March 2, 2020 22:58 — forked from djburdick/gist:5027494
Redis rails commands. #rails #redis
Rails.redis.get(key)
Rails.redis.set(key, value)
Rails.redis.expire(key, 1.hour)
Rails.redis.del(key)
Rails.redis.sadd(set_name, value)
Rails.redis.srem(set_name, key)
Rails.redis.sismember(set_name, value) # boolean test to see if val exists
@marka2g
marka2g / create_post.exs
Created September 24, 2019 16:36 — forked from stevedomin/create_post.exs
Using UUIDs as primary key with Ecto
defmodule MyBlog.Repo.Migrations.CreatePost do
use Ecto.Migration
def change do
create table(:posts, primary_key: false) do
add :id, :uuid, primary_key: true
add :body, :string
add :word_count, :integer
timestamps
@marka2g
marka2g / Setting_upa_new_repo.md
Created September 2, 2019 04:27 — forked from alexpchin/Setting_upa_new_repo.md
Create a new repository on the command line

Setting up a new Git Repo

##Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"

git remote add origin git@github.com:alexpchin/.git

@marka2g
marka2g / derp.sh
Created June 24, 2019 22:09 — forked from richardvenneman/derp.sh
Pull Heroku Postgres DB excluding specific table data
# Using the `--exlude-table-data` argument for the `heroku pg:pull` command doesn't seem to be working.
# Instead we're going to copy the Heroku PG database by using the Postgres `pg_dump` and `pg_restore` commands.
# Get the "Connection info string" for myapp
heroku pg:credentials:url DATABASE_URL -a myapp
# Download the database, excluding the `visits` and `ahoy_events` table data.
pg_dump "<PASTE_CONNECTION_INFO_STRING_HERE>" --exclude-table-data visits --exclude-table-data ahoy_events -O -x -Fc -f without_vists_and_ahoy_events.out -v
# In myapp, setup an empty database
@marka2g
marka2g / gist:436c93cc8d58a990b65bb716c2aa29e9
Created June 24, 2019 22:08 — forked from wrburgess/gist:5528649
Backup Heroku Postgres database and restore to local database

Grab new backup of database

Command: heroku pgbackups:capture --remote production

Response: >>> HEROKU_POSTGRESQL_COLOR_URL (DATABASE_URL) ----backup---> a712

Get url of backup download

Command: heroku pgbackups:url [db_key] --remote production