Skip to content

Instantly share code, notes, and snippets.

View eddyw's full-sized avatar
🏠
Working from home

Eddy Wilson eddyw

🏠
Working from home
View GitHub Profile
@hurryabit
hurryabit / stack_safe.js
Last active June 14, 2022 09:34
Stack-safety for free?
// This gist contains the JavaScript version of the code from the blog post
// https://hurryabit.github.io/blog/stack-safety-for-free/
function triangular(n) {
if (n == 0) {
return 0;
} else {
return n + triangular(n - 1);
}
}
@danydev
danydev / zsh_history.sh
Created May 21, 2020 09:01
Store commands in history only if successful
# README: This allows you to store in your history file only commands
# with a successful status (or forced exited by you with signal 2).
# Put this content in your .zhsrc
# CREDITS: inspired by https://scarff.id.au/blog/2019/zsh-history-conditional-on-command-success/
# This function will be hooked to zshaddhistory.
# zshaddhistory is called before a history line is saved. See zshmisc(1).
function my_zshaddhistory() {
# Prevent the command from being written to history before it's
# executed; save it to LASTHIST instead. Write it to history
@max-rocket-internet
max-rocket-internet / prom-k8s-request-limits.md
Last active July 19, 2024 23:33
How to display Kubernetes request and limit in Grafana / Prometheus properly

CPU: percentage of limit

A lot of people land when trying to find out how to calculate CPU usage metric correctly in prometheus, myself included! So I'll post what I eventually ended up using as I think it's still a little difficult trying to tie together all the snippets of info here and elsewhere.

This is specific to k8s and containers that have CPU limits set.

To show CPU usage as a percentage of the limit given to the container, this is the Prometheus query we used to create nice graphs in Grafana:

sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container_name!="POD"}[5m])) by (pod_name, container_name) /
@iaincollins
iaincollins / Google Spreadsheet.js
Last active May 30, 2021 16:03
Example Node.js code to append to a Google Spreadsheet every hour
/**
* Append data to a Google Spreadsheet
*
* You will need a file called '.env' with the following values:
*
* - GOOGLE_ID (Google oAuth Client ID)
* - GOOGLE_SECRET (Google oAuth Client Secret)
* - GOOGLE_REFRESH_TOKEN (Google oAuth Refresh Token)
* - GOOGLE_SPREADSHEET_ID (Google Spreadsheet ID)
*
@jarshwah
jarshwah / launch.json
Created April 23, 2017 11:28
Webpack Source Maps with vscode debugging
// debug config for running project under vscode debugger
{
"version": "0.2.0",
"configurations": [
{
"trace": true,
"name": "Chrome Debug",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8000/",
@Daniel-Hug
Daniel-Hug / collision-detection.js
Last active March 3, 2024 04:02
JS functions: check if 2 rectangles intersect, are touching, or if one contains the other
// Check if rectangle a contains rectangle b
// Each object (a and b) should have 2 properties to represent the
// top-left corner (x1, y1) and 2 for the bottom-right corner (x2, y2).
function contains(a, b) {
return !(
b.x1 < a.x1 ||
b.y1 < a.y1 ||
b.x2 > a.x2 ||
b.y2 > a.y2
);
@Bhavdip
Bhavdip / sketch-never-ending.md
Created October 6, 2016 15:53
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com

// @copyright
// © 2009-2012 Nicholas C. Zakas
// © 2012-2016 Jarosław Foksa
//
// @doc
// https://drafts.csswg.org/css-syntax
//
// @info
// CSS tokenizer based on TokenStream.js and Tokens.js from CSSLint.
@hsleonis
hsleonis / better-font-smoothing.css
Last active June 13, 2024 18:26
Better font smoothing in cross browser
html {
/* Adjust font size */
font-size: 100%;
-webkit-text-size-adjust: 100%;
/* Font varient */
font-variant-ligatures: none;
-webkit-font-variant-ligatures: none;
/* Smoothing */
text-rendering: optimizeLegibility;
-moz-osx-font-smoothing: grayscale;
@19h
19h / reset.js
Created February 19, 2013 22:51
Node.js — Clear Terminal / Console. Reset to initial state.
console.reset = function () {
return process.stdout.write('\033c');
}