Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / what-forces-layout.md
Last active May 14, 2024 08:57
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@sevkin
sevkin / getfreeport.go
Last active May 14, 2024 08:56
get free port in golang
// GetFreePort asks the kernel for a free open port that is ready to use.
func GetFreePort() (port int, err error) {
var a *net.TCPAddr
if a, err = net.ResolveTCPAddr("tcp", "localhost:0"); err == nil {
var l *net.TCPListener
if l, err = net.ListenTCP("tcp", a); err == nil {
defer l.Close()
return l.Addr().(*net.TCPAddr).Port, nil
}
}
@amalmurali47
amalmurali47 / edit_commit_history.md
Last active May 14, 2024 08:56
Change ownership of selected older commits in Git
  1. Clone the repo.
  2. Use git rebase -i --root
  3. vim will open. Select the commits you want to modify by changing pick to edit. If you would like to change all the commits, perform the following replace: :%s/^pick/edit/g. This command changes all instances of "pick" at the start of lines to "edit".
  4. You will now be shown all the selected commits one by one. Each commit message will be displayed. You have two options:
    • If you would like to keep the commit author details the same, do a git rebase --continue.
    • If you would like to change it to a different name/email, do git commit --amend --reset-author. If --reset-author is specified, it will use the details from your git config. (If you need to specify an alternate name/email, you can do so with --author="John Doe <john@example.com>". If you would like to change the time to a previous date, you can do so with --date "2 days ago".)
  5. Do the same for all the commits and finish the rebase.
  6. Perform git push -f origin master to
@mariocesar
mariocesar / telegram.py
Created June 13, 2017 19:52
Send a telegram message with python requests
import requests
api_url = 'https://api.telegram.org/bot{token}/{method}'.format
TELEGRAM_ACCESS_TOKEN = os.environ.get('TELEGRAM_ACCESS_TOKEN', None)
def telegram_command(name, data):
url = api_url(token=TELEGRAM_ACCESS_TOKEN, method=name)
return requests.post(url=url, json=data)
@ctlllll
ctlllll / longest_chinese_tokens_gpt4o.py
Created May 13, 2024 19:53
Longest Chinese tokens in gpt4o
import tiktoken
import langdetect
T = tiktoken.get_encoding("o200k_base")
length_dict = {}
for i in range(T.n_vocab):
try:
length_dict[i] = len(T.decode([i]))
except:
@ifyoumakeit
ifyoumakeit / github-conventional-comments.js
Last active May 14, 2024 08:49
GitHub Conventional Comments (instructions to install in comment below code)
(async function generateReplies(document) {
// https://conventionalcomments.org/#labels
const LABEL = {
praise: "praise",
nitpick: "nitpick",
suggestion: "suggestion",
issue: "issue",
todo: "todo",
question: "question",
thought: "thought",
@mlanett
mlanett / rails http status codes
Last active May 14, 2024 08:48
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@cdaven
cdaven / Spacemacs on Windows 10.md
Last active May 14, 2024 08:48
Setting up Spacemacs on Windows 10

Install Emacs First

Download emacs-w64 and extract somewhere, e.g. a tools or apps folder like C:\Users\<user>\tools\emacs.

Select Emacs' Home

Emacs and many other applications store its configuration in the user's "home" folder. Translated directly from the Unix world, that is %UserProfile% (C:\Users\<user>), but Windows prefers %AppData% instead (C:\Users\<user>\AppData\Roaming).

For simplicity's sake, override this by specifying the HOME environment variable explicitly. Emacs and some other applications (e.g. MinGW) lets this override the default.

@JunichiIto
JunichiIto / alias_matchers.md
Last active May 14, 2024 08:48
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@martinlaxenaire
martinlaxenaire / TextTexture.js
Last active May 14, 2024 08:48
A class to create multiline text textures easily with curtains.js
/***
Helper class to create text textures easily with curtains.js
Supports:
- vertical and horizontal text alignements
- lowercase and uppercase
- filled or stroked text
Does not support:
- right to left text (TODO)
- custom letter spacing