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 / heroku-remote.md
Created March 28, 2022 23:47 — forked from randallreedjr/heroku-remote.md
Add a Heroku remote to an existing git repo

Working with git remotes on Heroku

Generally, you will add a git remote for your Heroku app during the Heroku app creation process, i.e. heroku create. However, if you are working on an existing app and want to add git remotes to enable manual deploys, the following commands may be useful.

Adding a new remote

Add a remote for your Staging app and deploy

Note that on Heroku, you must always use master as the destination branch on the remote. If you want to deploy a different branch, you can use the syntax local_branch:destination_branch seen below (in this example, we push the local staging branch to the master branch on heroku.

$ git remote add staging https://git.heroku.com/staging-app.git
@marka2g
marka2g / config.yml
Created March 19, 2022 03:18 — forked from LukeMathWalker/config.yml
CircleCI - Rust setup
version: 2
jobs:
build-and-test:
docker:
- image: circleci/rust
environment:
# Fail the build if there are warnings
RUSTFLAGS: '-D warnings'
steps:
- checkout
@marka2g
marka2g / postgres.md
Created December 6, 2021 07:02 — forked from phortuin/postgres.md
Set up postgres + database on MacOS (M1)

Based on this blogpost.

Install with Homebrew:

$ brew install postgresql

Run server:

@marka2g
marka2g / 00_Readme.md
Created November 9, 2021 20:08 — forked from palkan/00_Readme.md
graphql-ruby fragment caching

PoC: GraphQL Ruby fragment caching

This example demonstrates how we can cache the response fragments in graphql-ruby.

Existing solutions only allow caching resolved values but not all the GraphQL machinery (validation, coercion, whatever).

Caching response parts (in case of Ruby, sub-Hashes) is much more efficient.

Benchmarks

@marka2g
marka2g / Update-branch.md
Created November 3, 2021 16:28 — forked from santisbon/Update-branch.md
Deploying from Git branches adds flexibility. Bring your feature branch up to date with master and deploy it to make sure everything works. If everything looks good the branch can be merged. Otherwise, you can deploy your master branch to return production to its stable state.

Updating a feature branch

First we'll update your local master branch. Go to your local project and check out the branch you want to merge into (your local master branch)

$ git checkout master

Fetch the remote, bringing the branches and their commits from the remote repository. You can use the -p, --prune option to delete any remote-tracking references that no longer exist in the remote. Commits to master will be stored in a local branch, remotes/origin/master

@marka2g
marka2g / encrypt_decrypt.rb
Created October 23, 2021 01:12 — forked from wteuber/encrypt_decrypt.rb
Simply encrypt and decrypt Strings in Ruby.
require 'openssl'
class String
def encrypt(key)
cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
cipher.key = Digest::SHA1.hexdigest key
s = cipher.update(self) + cipher.final
s.unpack('H*')[0].upcase
end

Screen Quick Reference

Basic

Description Command
Start a new session with session name screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r
@marka2g
marka2g / opposite_of_array_intersection.rb
Created September 9, 2020 22:06 — forked from awesome/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 / upsert_profile.ex
Created July 26, 2020 23:09 — forked from slashdotdash/upsert_profile.ex
Upserts in Ecto using `Ecto.Multi`
defp upsert_profile(multi, source, source_uuid, profile_url) do
profile = %Profile{
source: source,
source_uuid: source_uuid,
profile: profile_url,
}
Ecto.Multi.insert(multi, source_uuid, profile, on_conflict: [set: [profile: profile_url]], conflict_target: [:source, :source_uuid])
end
@marka2g
marka2g / echo_upsert.ex
Last active July 6, 2020 23:31
Ecto Upsert Example
# ensure a [unique constraint](https://hexdocs.pm/ecto/constraints-and-upserts.html) on the user table,
# this uses the `on_conflict` option to ensure the record exists before selecting,
# which should avoid a race condition. [docs](https://hexdocs.pm/ecto/Ecto.Repo.html#c:insert/2-upserts)
def find_or_create(user_params) do
{:ok, user} = %User{}
|> User.changeset(user_params)
|> Repo.insert(on_conflict: :nothing)
if is_nil(user.id) do
Repo.one from u in User, where: u.id == ^user.id