Skip to content

Instantly share code, notes, and snippets.

@lyrixx
lyrixx / HardCoreDebugLogger.php
Last active Nov 11, 2021
Hardcore Debug Logger
View HardCoreDebugLogger.php
<?php
const STREAM_OPEN_FOR_INCLUDE = 128;
final class HardCoreDebugLogger
{
public static function register(string $output = 'php://stdout')
{
register_tick_function(function () use ($output) {
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
@sarthology
sarthology / regexCheatsheet.js
Created Jan 10, 2019
A regex cheatsheet 👩🏻‍💻 (by Catherine)
View regexCheatsheet.js
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 Jul 12, 2017
How to output a range of lines from a file? — First published in fullweb.io issue #107
View how-to-output-a-range-of-lines-from-a-file.md

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-track-large-files-in-git.md
Created Jun 6, 2017
How to track large files (database, PSD, bin) in Git? — First published in fullweb.io issue #103
View how-to-track-large-files-in-git.md

How to track large files (database, PSD, bin) in Git?

Sometimes you have PSD or a small-ish SQLite file you’d like to track with Git. The problem is Git is bad at tracking changes in big binary files by default. With Git Large File Storage (LFS) you can replace these large files with text pointers while storing the file contents on a remote server. Both GitHub and BitBucket support it. Here is how to get started:

1. Install Git LFS extension (Mac here):

brew install git-lfs
@nepsilon
nepsilon / how-to-secure-your-site-with-https.md
Last active Aug 9, 2018
How to secure your site with HTTPS? — First published in fullweb.io issue #101
View how-to-secure-your-site-with-https.md

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 / how-to-rename-a-branch-in-git.md
Last active Dec 5, 2018
How to rename a branch in Git? — First published in fullweb.io issue #96
View how-to-rename-a-branch-in-git.md

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 Dec 5, 2018
3 Vim tips with external commands — First published in fullweb.io issue #95
View 3-vim-tips-with-external-commands.md

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:

View webpack.mix.js
// ...
let webpack = require("webpack");
mix.webpackConfig({
plugins: [
// Choose the language you want to keep (Ex: "fr")
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /fr/)
]
});
@nepsilon
nepsilon / how-to-update-a-github-forked-repository.md
Created Mar 14, 2017
How to update a GitHub forked repository? — First published in fullweb.io issue #91
View how-to-update-a-github-forked-repository.md

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 / how-to-split-a-file-into-smaller-chunks.md
Last active Jul 16, 2021
How to split a file into smaller chunks? — First published in fullweb.io issue #90
View how-to-split-a-file-into-smaller-chunks.md

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