Skip to content

Instantly share code, notes, and snippets.

View zengabor's full-sized avatar
🐼
Building

Gabor Lenard zengabor

🐼
Building
View GitHub Profile
package csrf
import "errors"
// This is just an example on how to reduce redundant code in Go
// Original file: https://github.com/gofiber/csrf/blob/dde96da6711a2cc01709a66730c2e16328b22047/main.go
// csrfFromExtractor returns a function can be used to bind to a parameter name to extract a csrf token from a Ctx.
func csrfFromExtractor(errMessage string, extractor func(c *fiber.Ctx, param string) string) func(string) func(c *fiber.Ctx) (string, error) {
return func(param string) func(c *fiber.Ctx) (string, error) {
@liamnewmarch
liamnewmarch / convert.js
Created March 27, 2018 15:30
Conversion between camelCase and kebab-case, using the DOM.
/**
* Convert kebab-case to camelCase.
* @param {string} kebabString The kebab-case string to convert.
* @return {string} The string converted to camelCase.
*/
function camelCase(kebabString) {
const div = document.createElement('div');
div.setAttribute(`data-${kebabString}`, '');
return Object.keys(div.dataset)[0];
}
@elliotlarson
elliotlarson / color-go-test.bash
Last active August 3, 2018 23:11
Colorizing Golang Test Output
#!/bin/bash
# Colorizing Go test output:
# This is meant to be used in place of `go test`. Provided this script is in
# your PATH, calling `color-go-test` will call through to `go test` and then
# colorize and reformat the output.
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
@vasanthk
vasanthk / System Design.md
Last active July 15, 2024 10:23
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@kdzwinel
kdzwinel / main.js
Last active June 7, 2024 08:08
List all undefined CSS classes
/*
This script attempts to identify all CSS classes mentioned in HTML but not defined in the stylesheets.
In order to use it, just run it in the DevTools console (or add it to DevTools Snippets and run it from there).
Note that this script requires browser to support `fetch` and some ES6 features (fat arrow, Promises, Array.from, Set). You can transpile it to ES5 here: https://babeljs.io/repl/ .
Known limitations:
- it won't be able to take into account some external stylesheets (if CORS isn't set up)
- it will produce false negatives for classes that are mentioned in the comments.
@paulirish
paulirish / what-forces-layout.md
Last active July 17, 2024 00:51
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
@vote539
vote539 / flexbox_supported.js
Last active August 29, 2015 14:24
Tiny, lightweight function to detect Flexbox support.
// Expanded
var flexboxSupported = (function(){
var prop = "flex-basis:1px";
var el = document.createElement("div");
var prefixes = ["", "-webkit-", "-moz-", "-o-", "-ms-"];
for(var i=0; i<prefixes.length; i++){
el.style.cssText += prefixes[i]+prop;
if(!!el.style.length) return true;
}
return false;
@jbenet
jbenet / simple-git-branching-model.md
Last active June 17, 2024 14:53
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@CodeMonkeyKevin
CodeMonkeyKevin / gist:6407086
Created September 1, 2013 20:26
GoLang UUID pkgs benchmark
// github.com/nu7hatch/gouuid
BenchmarkV4 1000000 1426 ns/op
BenchmarkV5 2000000 910 ns/op
// github.com/streadway/simpleuuid
BenchmarkV5 5000000 689 ns/op
// github.com/tux21b/gocql/tree/master/uuid
BenchmarkRandomUUID 1000000 1470 ns/op
// We're going to use Breakpoint to handle our media queries
// http://github.com/team-sass/breakpoint
@import "breakpoint";
@mixin element-query($sizes...) {
@each $size in $sizes {
@include breakpoint(nth($size, 2)) {
#{nth($size, 1)} & {
@content;
}