Skip to content

Instantly share code, notes, and snippets.

View chrisdl's full-sized avatar

Chris DiLorenzo chrisdl

View GitHub Profile
@chrisdl
chrisdl / gist:68d9ae5d6d48ac058cd9e9767c9d11fe
Last active January 23, 2023 19:39
DispelJobListingChatGPT
(see the picture in the first comment)
@chrisdl
chrisdl / LegacyCode.md
Last active January 10, 2019 13:34
Legacy Code Notes

Legacy Code

Definition

  • Classical: Code that relates to something which is no longer supported.
  • Modern: (1) source code inherited from someone else and (2) source code inherited from an older version of the software.

(3) BOTH Trifecta

How does it happen? (types)

  • Inherited from someone else: Employee who built can't work on it anymore.
const crypto = require("crypto");
class Db {
constructor(users={}) {
this.users = users;
}
// Expects passwordPayload to be a string of the form 'salt$passwordHash'
// Where the '$' is used as a separator.
storeUser(username, passwordPayload) {
@chrisdl
chrisdl / symmetricEncryptionAssignment.js
Last active April 9, 2020 22:49
SymmetricEncryptionAssignment
// https://nodejs.org/api/crypto.html#crypto_class_cipher
// 'aes256' -> AES256 - CBC
// The available ciphers depend on openssl. See ``$> openssl list-cipher-algorithms`` for a list.
const crypto = require("crypto");
const encrypt = (key, plaintext) => {
const cipher = crypto.createCipher("aes256", key);
let ciphertext = cipher.update(plaintext, "utf8", "hex");
ciphertext += cipher.final("hex");
return ciphertext;
@chrisdl
chrisdl / savePasswordAssignment.js
Last active April 9, 2020 22:49
Saving passwords assignment
const crypto = require("crypto");
class Db {
constructor(users={}) {
this.users = users;
}
// Expects passwordPayload to be a string of the form 'salt$passwordHash'
// Where the '$' is used as a separator.
storeUser(username, passwordPayload) {
@chrisdl
chrisdl / hashFunctionAssignment.js
Last active April 9, 2020 22:49
hash functions playground.
const crypto = require("crypto");
const hashFunction = crypto.createHash("sha256");
const plaintext = "123456";
hashFunction.update(plaintext);
const hash = hashFunction.digest("hex");
console.log(hash);
// Things to try:
@chrisdl
chrisdl / crypto_glossary.md
Last active January 30, 2018 23:59
Basic cryptography terms
  • plaintext = The secret text (message, password, ...) you want to encrypt.
  • ciphertext = A plaintext that has been encrypted.
  • cipher = A mathematical function that takes at least a key and a plaintext and produces a ciphertext. For example: AES.
  • hash function = A mathematical function that produces a hash which cannot be reversed back to plaintext.
  • key = A secret key that allows someone to decrypt a ciphertext back into a plaintext.
  • secret = see key.

Keybase proof

I hereby claim:

  • I am chrisdl on github.
  • I am chrisdl (https://keybase.io/chrisdl) on keybase.
  • I have a public key ASDQYgsg3r5Pqx0G9Ut_xjCYzQUJr-fcFb1oGbzLDRmvSAo

To claim this, I am signing this object:

@chrisdl
chrisdl / hello.py
Created January 23, 2017 16:29
Where art thou verify?
(py27) ubuntu@ubuntu-xenial:/vagrant$ bpython
bpython version 0.16 on top of Python 2.7.12 /home/ubuntu/.virtualenvs/py27/bin/python
>>> from Crypto.Hash import HMAC
>>> import os
>>> import binascii
>>> key = binascii.hexlify(os.urandom(32))
>>> msg = 'Hello World'
>>> my_hmac = HMAC.new(key=key, msg=msg)
>>> import Crypto
>>> Crypto.version_info
@chrisdl
chrisdl / many-files.js
Created December 1, 2015 15:25
Emitting Events between React and RequireJS
// This kind of sucks because is relies on the window object which means the React will have issues being Isomorphic (rendered server side).
// So if anyone has a better suggestion as to attaching to a global object and waiting for it to exist i'm all ears.
// main.js
requirejs.config({
paths: {
EventEmitter: "vendor/EventEmitter"
},
shim: {