Skip to content

Instantly share code, notes, and snippets.

View tinovyatkin's full-sized avatar
💭
I may be slow to respond.

Konstantin Vyatkin tinovyatkin

💭
I may be slow to respond.
View GitHub Profile
@branneman
branneman / better-nodejs-require-paths.md
Last active April 27, 2024 04:16
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@Sigmus
Sigmus / gulpfile.js
Last active November 15, 2017 11:55
gulpfile.js with browserify, reactify, watchify and gulp-notify.
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var notify = require("gulp-notify");
var scriptsDir = './scripts';
var buildDir = './build';
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active February 12, 2024 17:18
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

@jfairbank
jfairbank / fibonacci-generator.js
Last active December 4, 2023 12:23
Fibonacci ES6 Generator
function *fibonacci(n) {
const infinite = !n && n !== 0;
let current = 0;
let next = 1;
while (infinite || n--) {
yield current;
[current, next] = [next, current + next];
}
}
if(!("valueAsDate" in HTMLInputElement.prototype)){
Object.defineProperty(HTMLInputElement.prototype, "valueAsDate", {
get: function(){
var d = this.value.split(/\D/);
return new Date(d[0], --d[1], d[2]);
},
set: function(d){
var day = ("0" + d.getDate()).slice(-2),
month = ("0" + (d.getMonth() + 1)).slice(-2),
datestr = d.getFullYear()+"-"+month+"-"+day;
@dmvaldman
dmvaldman / promisesEM.md
Last active November 3, 2021 08:54
Promises as EventEmitters

Promises as EventEmitters

I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.

I read the spec, some blog posts, and looked through some code. I learned how to

@ckrack
ckrack / passkit-webservice-swagger.json
Created May 31, 2016 19:41
Passkit Webservice Swagger for Apple Wallet Webservice
{
"swagger": "2.0",
"info": {
"title": "Passkit Web Service",
"contact": {
"name": "Clemens Krack",
"email": "info@clemenskrack.com"
},
"version": "1.0.0"
},
@tinovyatkin
tinovyatkin / loadFont.js
Last active November 17, 2022 23:09
My function to async load web fonts (real WOFF and WOFF2, not base64 behemots), cache them to localStorage and reuse on next visits
/**
* This function load font from web, stores it in localStorage and reuses on next page loads
* Different to everything I found on the internet due to following facts
* 1. Checks if the font is installed in the system and spend no time if it is
* 2. Loads actual WOFF or WOFF2 fonts (if supported) and not bit base64 encoded version - so it faster
* 3. Uses fetch API and FontFace API if available - it's cool!
* 4. Return promises and uses jQuery for cases where native promises probably not available
*
* @param fontName (Field for font-face)
* @param fontUrl (full URL but without .woff nor .woff2 extensions - format will be selected automatically)
@at-daonguyen
at-daonguyen / $CIRCLE_PR_NUMBER
Last active December 24, 2018 02:13
Workaround $CIRCLE_PR_NUMBER for CircleCI
#!/bin/bash
if [[ -z "$CIRCLE_PR_NUMBER" ]]; then
if [[ -z "$CI_PULL_REQUEST" ]]; then
URL="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls?head=$CIRCLE_PROJECT_USERNAME:$CIRCLE_BRANCH"
RESULT="`curl -X GET -u $GITHUB_ACCESS_TOKEN:x-oauth-basic $URL | jq ".[0].url"`"
[[ "$RESULT" == 'null' ]] && CI_PULL_REQUEST='' || CI_PULL_REQUEST="${RESULT//\"}"
fi
CIRCLE_PR_NUMBER="$(basename "$CI_PULL_REQUEST")"
fi
@danieleggert
danieleggert / GPG and git on macOS.md
Last active May 3, 2024 12:26
How to set up git to use the GPG Suite

GPG and git on macOS

Setup

No need for homebrew or anything like that. Works with https://www.git-tower.com and the command line.

  1. Install https://gpgtools.org -- I'd suggest to do a customized install and deselect GPGMail.
  2. Create or import a key -- see below for https://keybase.io
  3. Run gpg --list-secret-keys and look for sec, use the key ID for the next step
  4. Configure git to use GPG -- replace the key with the one from gpg --list-secret-keys