Skip to content

Instantly share code, notes, and snippets.

View smashercosmo's full-sized avatar

Vladislav Shkodin smashercosmo

View GitHub Profile
@smashercosmo
smashercosmo / index.html
Last active December 27, 2015 04:09
Quick implementation of angular's $route.reload() with ui-router. Ui-router has it's own $state.reload function, but it's behaviour differs from angular's. For example it can't reload a route (state) if it wasn't actually loaded. In this gist I use $locationChangeStart event to prevent route from being loaded, but then I reload it after 2 sec de…
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
<script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.min.js"></script>
</head>
<body>
<div ui-view></div>
@smashercosmo
smashercosmo / gist:7675442
Created November 27, 2013 13:15
Snippet to determine scrollbar width
/**
* Simple function to determine scrollbar width.
* Extracted from JqueryUI source and changed to get rid
* of jQuery dependency.
*/
function getScrollBarWidth() {
var w1, w2,
div = document.createElement('div'),
inner = document.createElement('div');
'use strict';
angular
.module('Decorators', [])
.config(function($provide){
/**
* Change $watchCollection due to bug #2621
* https://github.com/angular/angular.js/issues/2621
* remove after official fix
*/
import React from 'react';
import Router from 'react-router';
import routes from './routes';
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import intlReducer from './intl/intl.reducer'
const app = document.getElementById('app');
/** initalState contains very complicated object with all translations */
@smashercosmo
smashercosmo / example
Last active September 10, 2015 14:28
{
foo: "bar",
bar: "baz",
tmp: "test",
}
{
foo: "bar",
bar: "baz",
tmp: "test"
}
@smashercosmo
smashercosmo / cssModulesConfig.js
Last active April 22, 2016 12:21
css-modules on server
'use strict';
const path = require('path');
const sassAndScssLoader = indentedSyntax => (
(source, filename) => require('node-sass').renderSync({
file: filename,
indentedSyntax
}).css
);
@smashercosmo
smashercosmo / main.js
Created November 3, 2015 22:32
Server hot reload
import imports from './imports'; // <-- all your imports
import express from 'express';
const app = express();
if (__DEVELOPMENT__) require('./serverHotReload')(app, () => {
try {
imports = require('./imports');
} catch (error) {
console.log(error.stack)
@smashercosmo
smashercosmo / logger.js
Last active April 17, 2019 13:06
Batch actions logger
import createLogger from 'redux-logger';
const actionTransformer = action => {
if (action.type === 'BATCHING_REDUCER.BATCH') {
action.payload.type = action.payload.reduce((result, next) => {
const prefix = result ? result + ' => ' : '';
return prefix + next.type;
}, '');
return action.payload;
const injectMiddleware = (staticDeps, dynamicDeps) => ({ dispatch, getState }) => next => action => {
const deps = {...staticDeps};
Object.keys(dynamicDeps).forEach(key => {
deps[key] = dynamicDeps[key]();
});
return next(typeof action === 'function'
? action({ ...deps, dispatch, getState })
: action
);
}