Skip to content

Instantly share code, notes, and snippets.

@sarthology
sarthology / regexCheatsheet.js
Created January 10, 2019 07:54
A regex cheatsheet 👩🏻‍💻 (by Catherine)
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@nepsilon
nepsilon / how-to-output-a-range-of-lines-from-a-file.md
Created July 12, 2017 04:56
How to output a range of lines from a file? — First published in fullweb.io issue #107

How to output a range of lines from a file?

Easy enough with sed:

sed -n	123,230p filename

This will output filename content, from line 123 to line 230, inclusives. Notice the p letter after the last line number, this is what instruct sed to print to stdout.

@nepsilon
nepsilon / how-to-split-a-file-into-smaller-chunks.md
Last active July 16, 2021 10:34
How to split a file into smaller chunks? — First published in fullweb.io issue #90

How to split a file into smaller chunks?

You may want to upload a 100GB file over an unstable network, or feed your scripts smaller inputs to load in RAM. In both cases, just splitting your file into smaller chunks is an easy solution.

Great news is Unix/Linux systems have the split utility already installed. And using it is simple as pie:

Cut a binary file into chunks of X bytes:

split -b X bigfile.avi
@nepsilon
nepsilon / a-better-setup-for-git.md
Last active October 19, 2020 19:15
A better setup for Git — First published in fullweb.io issue #46

A better setup for Git

Git default configuration is good but it can be personalized to improve your workflow efficiency. Here are some good lines to put in your ~/.gitconfig:

# The basics, who you commit as:
[user]
  name = John Doe
  email = john@doe.org
@nepsilon
nepsilon / how-to-update-a-github-forked-repository.md
Created March 14, 2017 17:19
How to update a GitHub forked repository? — First published in fullweb.io issue #91

How to update a GitHub forked repository?

So you hit "Fork" and now you have this repo copy on your Github account. Here is what to do to keep it up-to-date with the original repo.

1. Add the original repo as remote, here called upstream:

git remote add upstream https://github.com/author/repo.git

2. Fetch all the branches of that upstream remote:

@nepsilon
nepsilon / gitignore.md
Last active December 13, 2019 04:10
Understand what .gitignore rule is ignoring your files — First published in fullweb.io issue #54

Understand what .gitignore rule is ignoring your files

Ready to commit, you fire your git status and you don’t see your files 🤔.

Use this command to ask Git what rule is causing this ignore:

$ git check-ignore -v filename

For instance to see what rule ignores tests.pyc:

@nepsilon
nepsilon / how-to-rename-a-branch-in-git.md
Last active December 5, 2018 17:24
How to rename a branch in Git? — First published in fullweb.io issue #96

How to rename a branch in Git?

Rename your local foo branch with bar:

git branch -m foo bar

Remember this will add the new branch with you push, but it won’t delete the old foo remote branch.

Add -f --mirror to rename the branch on the remote:

@nepsilon
nepsilon / 3-vim-tips-with-external-commands.md
Last active December 5, 2018 17:23
3 Vim tips with external commands — First published in fullweb.io issue #95

3 Vim tips with external commands

Vim has this ! special character that will run any shell command without having to close it. Here are 3 ways I often use it:

1. Format a JSON blob:

:%!python -m json.tool

2. Count number of characters in a file:

@nepsilon
nepsilon / how-to-secure-your-site-with-https.md
Last active August 9, 2018 11:19
How to secure your site with HTTPS? — First published in fullweb.io issue #101

How to secure your site with HTTPS?

With HTTP everything is visible when traveling on the Internet. By generating an SSL certificate and configuring your webserver you can force browsers to use HTTPS. Here is how to proceed:

# 1. Install letsencrypt
sudo pip install letsencrypt
@nepsilon
nepsilon / speed-is-a-feature-10-tips-faster-browser-networking.md
Created September 6, 2016 05:31
Speed is a feature: 10 tips for faster browser networking — First published in fullweb.io issue #64

Speed is a feature: 10 tips for faster browser networking

1. Minimize TCP connections

Ensure the web server uses Keep-Alive headers.

2. Reduce DNS look-ups

DNS look-ups are the first thing blocking your HTTP requests.