Skip to content

Instantly share code, notes, and snippets.

View antonlvovych's full-sized avatar

Anton Fedulov antonlvovych

View GitHub Profile
@gaearon
gaearon / connect.js
Last active June 24, 2024 09:43
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@antonlvovych
antonlvovych / _font-face.scss
Last active April 9, 2018 16:48
A Sass mixin to take the pain out of creating bullet-proof @font-face declarations.
// Generate @font-face
//
// $font-base-path {String} - path to fonts directory relative to CSS location
// $font-family {String} - font-family (w/o spaces)
// $font-weight {Number} - font-weight
// $font-style {String} - font-style (default: normal)
//
// File path & file name are based on font props which we include.
// Examples of path mapping:
// @include font-face("../../fonts/", "open-sans", 300); => ../../fonts/open-sans/300/open-sans-300.*
@branneman
branneman / better-nodejs-require-paths.md
Last active June 29, 2024 16:00
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

@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"