Skip to content

Instantly share code, notes, and snippets.

View RinatValiullov's full-sized avatar
👷‍♂️
Looking for a job

Rinat Valiullov RinatValiullov

👷‍♂️
Looking for a job
View GitHub Profile
#!/usr/bin/env node
// Usage:
// cat my-file.md | ./gist-toc.mjs
// pbpaste | ./gist-toc.mjs | pbcopy # clipboard -> clipboard (macOS)
function createSlug(str) {
str = str.replace(/[?%:`]/g, '');
str = str.replace(/ +/g, '-');
return str.toLowerCase();
@yann2192
yann2192 / vimrc
Last active September 11, 2021 01:30
set shell=/bin/bash
if $TERM == "xterm"
set t_Co=256 " 256 colors
endif
set nocompatible " be iMproved
let mapleader="," " change the leader to be a comma vs slash
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
@acdlite
acdlite / flux.js
Last active October 7, 2021 17:19
A Redux-like Flux implementation in <75 lines of code
/**
* Basic proof of concept.
* - Hot reloadable
* - Stateless stores
* - Stores and action creators interoperable with Redux.
*/
import React, { Component } from 'react';
export default function dispatch(store, atom, action) {
@xiaochengh
xiaochengh / cascade-layer.md
Last active December 8, 2021 00:35
CSS cascade layer explainer

Use case: Set base style with a 3rd party library, and then override some style.

With cascade layers (spec), this can be done by simply putting 3rd party rules and author's own rules in different layers, so that author's own rules have higher priority than the 3rd party library.

There is no need to tweak selector specificity or source ordering.

3rd party style library:

function hyphenize(str) {
// /y is to make sure that there are no characters between the matches
// /g is so that .match() works the way we need here
// /u is not strictly necessary here, but generally a good habit
return str.match(/([a-z]{1,2})/uyg).join('-');
}
assert.equal(
hyphenize('hello'), 'he-ll-o'
);
@Nooshu
Nooshu / simplified-wpt-font-injection.js
Created February 23, 2020 03:32
Simplified script for injecting fonts into WebPageTest
(function(){
// this will trigger a font load
var customFont1 = new FontFace('custom font name', 'url([FONT_URL_HERE])', {
display: 'block', // display setting to test here
weight: '700' // font-weight
// other font properties here
});
// IMPORTANT: add the font to the document
document.fonts.add(customFont1);

From Fabrice Bellard, with minor name change (umulh):

// return the high 32 bit part of the 64 bit addition of (hi0, lo0) and (hi1, lo1)
Math.iaddh(lo0, hi0, lo1, hi1)

// return the high 32 bit part of the 64 bit subtraction of (hi0, lo0) and (hi1, lo1)
Math.isubh(lo0, hi0, lo1, hi1)

// return the high 32 bit part of the signed 64 bit product of the 32 bit numbers a and b
@cferdinandi
cferdinandi / README.md
Created January 17, 2019 19:12
Find a Pet app project template from https://learnvanillajs.com.

Project Details

Use the Petfinder API to get a list of available pets from a shelter and display them on a web page.

Bonus: Dynamically create filters for things like age, gender, breed, and type of animal, and let users filter out pets that don't match their criteria.

Quick heads up: The Petfinder API is buggy and poorly maintained, so you may run into some hiccups along the way.

Considerations

@demisx
demisx / gulpfile.js
Last active July 14, 2022 16:06
Gulp 4 gulpfile.js
// Gulp 4
var gulp = require('gulp');
var using = require('gulp-using');
var grep = require('gulp-grep');
var changed = require('gulp-changed');
var del = require('del');
var coffee = require('gulp-coffee');
var less = require('gulp-less');
var coffeelint = require('gulp-coffeelint');
var sourcemaps = require('gulp-sourcemaps');