Skip to content

Instantly share code, notes, and snippets.

@abdes-zakari
abdes-zakari / mac-git-name-branch.md
Created December 3, 2021 15:23
Add Git Branch Name to Terminal Prompt on Mac (Big Sur)

Add Git Branch Name to Terminal Prompt on Mac (Big Sur)

Open ~/.zprofile or ~/.zshrc in your favorite editor and add the following content to the bottom. ( if the file ~/.zprofile or ~/.zprofile does not already exist create it)

# Git branch in prompt.
function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
@fernandoaleman
fernandoaleman / mysql2-m1.md
Last active July 4, 2024 06:22
How to install mysql2 gem on m1 Mac

Problem

Installing mysql2 gem errors on Apple silicon M1, M2 or M3 Mac running macOS Sonoma.

Solution

Make sure mysql-client, openssl and zstd are installed on Mac via Homebrew.

Replace mysql-client with whichever mysql package you are using

@starbeast
starbeast / gist:9cfbc9f499bff84a57db815a2dfa81d2
Created November 24, 2019 13:55
NaCl secret box (RbNaCl BE + TweetNaCl.js FE)
Ruby - https://github.com/RubyCrypto/rbnacl
JavaScript - https://github.com/dchest/tweetnacl-js
## FE encrypt -> BE decrypt
# FE
const { publicKey, secretKey } = nacl.box.keyPair();
// every time you encrypt change the nonce
const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);
const encodedNonce = nacl.util.encodeBase64(nonce);
const encodedPublic = nacl.util.encodeBase64(publicKey);
@WJWH
WJWH / c10k.ru
Created October 15, 2018 09:12
The double hijack trick, serving 65k connections from a single ruby process
# This server demo does a socket hijack in Rack and then saves the socket to a global variable
# to prevent it from being GCed when the Puma thread ends. It will then write "BEEP" to each
# socket every ten seconds to prevent the connection timing out. During testing, it easily
# handled up to 65523 connections, after which it ran into the `ulimit` for open file descriptors.
# The bit with the waiting area is there because a normal `Set` is not thread safe and it would
# drop socket due to race conditions. The `Queue` is thread safe and will make sure all sockets
# are preserved.
# run with `rackup -q -p 8000 -o 0.0.0.0 c10k.ru`
# testing: install `ab` and then run `ab -c 20000 -n 20000 <ip adress of server>:8000/
@pcreux
pcreux / Gemfile
Last active December 11, 2023 20:24
Fast Rails + Heroku Configuration
group :production do
gem 'unicorn'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
end