Skip to content

Instantly share code, notes, and snippets.

View Lamby777's full-sized avatar
😼
haiiiiiii ^w^

&Cherry Lamby777

😼
haiiiiiii ^w^
View GitHub Profile

The Borrow Checker

This pass has the job of enforcing memory safety. This is a subtle topic. This docs aim to explain both the practice and the theory behind the borrow checker. They start with a high-level overview of how it works, and then proceed to dive into the theoretical background. Finally, they go into detail on some of the more subtle aspects.

Table of contents

NOTE: This was first authored on 26 Feb 2014. Things may have changed since then.

C++'s Templates

C++'s templates could be seen as forming a duck typed, purely functional code generation program that is run at compile time. Types are not checked at the initial invocation stage, rather the template continues to expand until it is either successful, or runs into an operation that is not supported by that specific type – in that case the compiler spits out a 'stack trace' of the state of the template expansion.

To see this in action, lets look at a very simple example:

template 
@pepelsbey
pepelsbey / hocus.scss
Last active March 1, 2024 11:03
Simple “Hocus” Sass @mixin for :hover and :focus pseudos. Makes them easier to write and you’ll never forget to specify both.
@mixin hocus {
&:hover,
&:focus {
@content;
}
}
// Before
E {
&:hover,
@tilpner
tilpner / l.rs
Last active September 30, 2023 10:41
Macro for inline definition of anonymous functions, and examples of passing functions.
fn once(f: Box<Fn()>) { f() }
fn twice(f: fn()) { f(); f() }
fn thrice<F: Fn()>(f: F) { f(); f(); f() }
// Inline definition of anonymous functions. Examples:
// l!(42;)
// l!(i32 := 42)
// l!(i: i32 := i + 42)
@n-st
n-st / view-on-archive-org.js
Created February 28, 2016 16:20
Bookmarklet to view current page on the Internet Archive Wayback Machine (https://archive.org/)
javascript:(function(){if(location.href.indexOf('http')!=0){input=prompt('URL:','http://');if(input!=null){location.href='http://web.archive.org/web/*/'+input}}else{location.href='http://web.archive.org/web/*/'+location.href;}})();
@ttencate
ttencate / Makefile
Created February 23, 2017 08:31
The best Makefile ever
ifeq ($(MAKECMDGOALS),me a sandwich)
.PHONY: me a sandwich
me a:
@true
sandwich:
@if [[ $$(id -u) == "0" ]]; then \
echo "Okay."; \
else \
echo "What? Make it yourself."; \
false; \
@CMCDragonkai
CMCDragonkai / exporting_modules_functions_from_python_init.md
Last active June 5, 2024 07:28
Exporting Modules and Functions from Python `__init__.py` #python

Exporting Modules and Functions from Python __init__.py

Any directory with __init__.py is considered a package in Python.

Any python files inside a package is considered a module.

Modules contain functions and other bindings that is always exported.

If you are outside the package, and you want to import a module from a package:

@pavankjadda
pavankjadda / Generate Custom SSH Key.md
Last active October 27, 2023 16:54
Generate SSH Key with custom name

Create new Private and Public key on Host machine (Ex.macOS)

$ssh-keygen -t rsa
# Enter location and file name like (/Users/pjadda/.ssh/minishift_rsa), do not use default files
#Passphrase is optional

Create .ssh folder in Guest OS even if it exists

$ssh docker@192.168.64.3 mkdir -p .ssh
@nileshsimaria
nileshsimaria / User belongs to docker group
Last active May 8, 2023 03:57
A user belongs to docker group can gain root access on your host
Be careful if you are adding user to docker group.
1. As a root, create a file (owner root and group root)
$ touch /etc/foo
$ ls -l /etc/foo
-rw-r--r-- 1 root root 0 Dec 5 17:40 /etc/foo
2. Login as a non-root user belongs to docker group. In my example its user u1.
$ id
@jasonboukheir
jasonboukheir / git
Last active March 29, 2024 18:12
git when in unix, git.exe when in wsl
#!/bin/sh
if pwd | grep /mnt/c > /dev/null; then
exec git.exe "$@"
else
exec /usr/bin/git "$@"
fi