Skip to content

Instantly share code, notes, and snippets.

View davidglezz's full-sized avatar
😃
Happy

David Gonzalez davidglezz

😃
Happy
View GitHub Profile
Seven different types of CSS attribute selectors
// This attribute exists on the element
[value]
// This attribute has a specific value of cool
[value='cool']
// This attribute value contains the word cool somewhere in it
[value*='cool']
@Rich-Harris
Rich-Harris / index.js
Last active January 22, 2020 22:21
whatwg stream utils
const fs = require('fs');
const { ReadableStream, TransformStream, WritableStream} = require('web-streams-polyfill/ponyfill/es2018');
function createReadStream(file, opts) {
return new ReadableStream({
start(controller) {
const stream = fs.createReadStream(file, opts);
stream.on('readable', () => {
const data = stream.read();
controller.enqueue(data);
@androideveloper
androideveloper / pre-commit
Last active October 2, 2023 21:10
Git hook to enforce branch naming policy
#!/usr/bin/env bash
LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(feature|bugfix|improvement|library|prerelease|release|hotfix)\/[a-z0-9._-]+$"
message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."
if [[ ! $local_branch =~ $valid_branch_regex ]]
@mikowl
mikowl / oneliners.js
Last active February 19, 2025 05:20
👑 Awesome one-liners you might find useful while coding.
// Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
@jherax
jherax / configure.md
Last active April 22, 2025 11:00
VS Code: Debugging with Jest

VS Code: Debugging Jest

Sometimes, debugging with console.log is not enough to find out what is happening in the code, as console.log prints only plain objects but neither functions nor objects with circular references. Besides, it's possible you may need to know the context and flow of the code.

Read more about debugging with VS Code in VS Code: Debugging.

<?php declare(strict_types=1);
// this may be defined in the enviroment, not in the code.
// or can we find a system path for auto setup persistent cache ?
define('CACHE_FILE_TEMPLATE','/home/seb/.cache/test_php_{file}.txt');
// usage : get some data : get('the key') // return some string content
print 'get("the stuff to fetch") -> "'.get('some stuffx.').'"'.PHP_EOL;
// you can also use the 'tool' functions
@SebSept
SebSept / stdLog.php
Last active March 15, 2020 10:38
non verbose way to send output to stderr or stdout
<?php declare(strict_types=1);
/**
* Writes messages to stderr or stdout.
*
* @author Sébastien Monterisi <https://gist.github.com/SebSept/>
* @throws FailureToWriteToFile
*/
function stdErr(string $message): void { stdLog('php://stderr', $message); }
function stdOut(string $message): void { stdLog('php://stdout', $message); }
@subversivo58
subversivo58 / GithubApiPush.js
Last active May 31, 2023 16:30 — forked from iktash/GithubApiPush.js
Upload a binary data to your repository
/**
* Wraper to upload binary files to GitHub repo
* Uses the modified GitHub library under the hood and exposes it as `GHInstance` property for get instance of all methods
* @note:
* -- inspired at article: @see <https://medium.freecodecamp.org/pushing-a-list-of-files-to-the-github-with-javascript-b724c8c09b66>
* -- issue (not yet resolved): @see issue <https://github.com/github-tools/github/issues/417>
* @copyright Copyright (c) 2020 Lauro Moraes <https://github.com/subversivo58>
* @license MIT License <https://github.com/subversivo58/subversivo58.github.io/blob/master/LICENSE>
*/
const GithubAPI = function(auth) {
@SebSept
SebSept / custom.php
Last active March 15, 2020 10:39
php functionnal playground
<?php
/**
* playground
*
* functionnal use is at the bottom.
*
* Don't damn me, that's a playground.
*/
class Pipe {