Skip to content

Instantly share code, notes, and snippets.

View ByteDecoder's full-sized avatar
🏠
Working from home

Rodrigo Reyes ByteDecoder

🏠
Working from home
View GitHub Profile
@ByteDecoder
ByteDecoder / revert-a-commit.md
Created August 10, 2018 01:48 — forked from gunjanpatel/revert-a-commit.md
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}'

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@ByteDecoder
ByteDecoder / pbkdf2.rb
Created October 4, 2018 18:53 — forked from emboss/pbkdf2.rb
Using PBKDF2 with HMAC-SHA256 for storing passwords
p ="password"
#according to PKCS#5, should be at least 8 bytes. Public information, can be stored along with the pwd.
s = OpenSSL::Random.random_bytes(16)
c = 20000 # varies depending on how fast the system is, tweak until it takes "long enough"
digest = OpenSSL::Digest::SHA256.new
#should be >= the output size of the underlying hash function, but ">" doesn't improve security (says PKCS#5)
dk_len = digest.digest_length
#store the result for new passwords
value = OpenSSL::PKCS5.pbkdf2_hmac(p, s, c, dk_len, digest)

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@ByteDecoder
ByteDecoder / character_sequence.rb
Created March 22, 2019 19:42
Find character patterns in given words
def lookup(words, letter)
words.drop(1).each { |word| return false unless word.include?(letter) }
true
end
def char_sequence(words)
sorted_words = []
pattern = []
words.each { |word| sorted_words << word.chars.sort(&:casecmp).join }
sorted_words[0].chars.each { |letter| pattern << letter if lookup(words, letter) }
@ByteDecoder
ByteDecoder / bullet_and_minitest.md
Created March 24, 2019 01:35 — forked from kerrizor/bullet_and_minitest.md
Trigger MiniTest failures in Rails when Bullet detects N+1 query violations

In test/test_helper.rb...

### Bullet (N+1 queries)

if ENV['BULLET']
  Bullet.enable = true

  require 'minitest/unit'
git config --global alias.lol "log --oneline --graph --decorate"
@ByteDecoder
ByteDecoder / gist:2e5978a5626b8fbc525e52be12fdc139
Created May 22, 2019 06:07
Avoid joins on large tables for MAX performace
-- User Table
CREATE TABLE user (
id serial PRIMARY KEY,
account_id int not NULL,
name varchar(10)
);
-- Purchase Table
CREATE TABLE purchase (
id SERIAL PRIMARY KEY,
@ByteDecoder
ByteDecoder / no-where
Created September 6, 2019 22:51
Untrack files already added to git repository based on .gitignore
$ git rm -r --cached .
$ git add .
$ git commit -m ".gitignore fix"
@ByteDecoder
ByteDecoder / high_order_function.js
Created October 1, 2019 19:24
High Order function => records the time after the function was called, and returns the time the function took to run by subtracting the starting time from the ending time
const timeFuncRuntime = funcParameter => {
let t1 = Date.now();
funcParameter();
let t2 = Date.now();
return t2 - t1;
}
const addOneToOne = () => 1 + 1;
timeFuncRuntime(addOneToOne);
@ByteDecoder
ByteDecoder / tslint.json
Created February 14, 2020 07:33
TSLint example configuration file
{
"extends": "tslint:recommended",
"rulesDirectory": "./custom-ts-rules",
"rules": {
"copyright-required": true,
"max-line-length": {
"options": [120]
},
"new-parens": true,
"no-arg": true,