Skip to content

Instantly share code, notes, and snippets.

Patrick Tran theptrk

Block or report user

Report or block theptrk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@theptrk
theptrk / bcrypt-nodejs.md
Last active Oct 17, 2018
bcrypt-nodejs bug - Invalid salt revision
View bcrypt-nodejs.md

Bug - Invalid salt revision

Whenever I ran compareSync(password, passwordHash) I would see the error

Invalid salt revision

What did it mean? Where did it come from?

This is the code in the library bcrypt-nodejs

minor = salt.charAt(2);
View delete_files.sh
# find
find -name '* SOME_SPECIFIER.SOME_EXTENSION'
# find and delete
find -name '* SOME_SPECIFIER.SOME_EXTENSION' -delete
# example 1: delete all files to end in `"space"1.JPG`
find -name '* 1.JPG' -delete
View express-hello-world.js
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))
@theptrk
theptrk / npm-start.md
Created Jul 14, 2018
hello world: npm start script
View npm-start.md

package.json

{
  "name": "theptrk",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js"
View didfile.md

Its likely more natural for you to type at the bottom of the file so with normal Go we move the cursor to the bottom before reading from the date command.

# bash_profile.sh
alias did="vim +'normal Go' +'r!date' ~/did.txt"
View check-if-browser-online.js
(function {
window.addEventListener('online', doSomething);
window.addEventListener('offline', doSomething);
})()
// @returns: String { "online", "offline" }
function doSomething() {
returns navigator.onLine;
}
View example.diff
--- /dev/null
+++ b/my_file.txt
@@ -0,0 +1,3 @@
+Dear Abby
+I met a new person today
+It was a good day
@theptrk
theptrk / k-shifted-array.js
Created Jul 18, 2017
Algo. K shifted array. Find K
View k-shifted-array.js
// TODO TEST
// given [3,4,5,6,7,8,9,1,2]
// return 7
const test1 = [3,4,5,6,7,8,9,1,2]
const test2 = [8,9,1,2,3,4,5,6,7]
const findk = list => {
if (list[0] < list[list.length-1]) {
return 0;
}
@theptrk
theptrk / phone-number-mnemonics-iteratively.js
Created Jun 21, 2017
given a telephone number, return a list of possible mnemonics using a standard US telephone
View phone-number-mnemonics-iteratively.js
const phoneNumberMnemonics = (phoneNumber) => {
const letters = ["0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
const numbers = phoneNumber.split('');
const results = [];
const wipStack = [
{ wip: '', remaining: numbers }
];
while (wipStack.length > 0) {
let [wip, remainingNumbers] = wipStack.pop();
if (remainingNumbers.length > 0) {
@theptrk
theptrk / spiral-traversal.js
Created Jun 20, 2017
Spiral Traversal of 2D array in JavaScript
View spiral-traversal.js
const test1 = [
[1]
];
const test2 = [
[1, 2],
[3, 4]
];
const test3 = [
[1, 2, 3],
[4, 5, 6],
You can’t perform that action at this time.