Skip to content

Instantly share code, notes, and snippets.

View jrencz's full-sized avatar

Jarek Rencz jrencz

  • Wonga
  • Warsaw, Poland
View GitHub Profile
@jrencz
jrencz / angular-angular
Last active August 29, 2015 14:01
Funny names across JS projects
https://github.com/angular/angular.js/blob/25a476ea096b200fb4f422aaa9cd7215e2596ad3/src/ng/directive/select.js#L145-L146
//000011111111110000000000022222222220000000000000000000003333333333000000000000004444444444444440000000005555555555555550000000666666666666666000000000000000777777777700000000000000000008888888888
var NG_OPTIONS_REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/,
@jrencz
jrencz / register-many-event-handlers-angular
Created May 16, 2014 08:48
Simple way to register many event handlers to AngularJS scope.
function traverse(scope, level, rootPath, delimiter) {
rootPath = rootPath || [];
Object.keys(level).forEach(function (key) {
const path = rootPath.slice(0);
path.push(key);
if (angular.isFunction(level[key])) {
scope.$on(path.join(delimiter), level[key]);
return;
}
traverse(scope, level[key], path, delimiter);
@jrencz
jrencz / Gruntfile.js
Last active August 29, 2015 14:04
Grunt task to strip unnecessary imports from the sass files
grunt.registerMultiTask('sassStripImports',
'Strips @import statements from the top of SCSS files',
// Stripping imports prevents code duplication yet still allows IDEs to properly resolve variables.
function () {
var options = this.options();
this.files.forEach(function (mapping) {
grunt.file.expand(mapping.src).forEach(function (path) {
grunt.file.write(path, grunt.file.read(path).replace((options.pattern || /@import\s\".+\";/), ''));
});
});
@jrencz
jrencz / Grunfile-part.js
Created August 20, 2014 08:27
Cofiguration dump for issue #5 on jubalm/grunt-fontello
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
fontello: {
share: {
options: {
config: 'fontello-config.json',
fonts: 'app/fonts',
styles: 'app/core-styles',
@jrencz
jrencz / finally.js
Created January 7, 2016 11:49
Quick sketch of Angular1 attribute directive that calls a function after a promise returned by ngClick handler is resolved or rejected
(function () {
'use strict';
angular
.module('finally', [])
.directive('finally', function (
$parse
) {
return {
@jrencz
jrencz / angular-di-tests-short-syntax.es6
Created January 21, 2016 10:43
An idea of shorter syntax for loading services in angular1
let $log,
let $q;
// currently:
beforeEach(inject(function (_$log_, _$q_) {
$log = _$log_;
$q = _$q_;
}));
// maybe:
@jrencz
jrencz / mergePaths.js
Created June 1, 2016 14:04
Lodash: merge property paths given as strings or arrays into one
/**
* @param {...(string|Array)} paths
*
* @example
* > mergePaths('a.b.c', 'd');
* // ['a', 'b', 'c', 'd']
*
* > mergePaths('a.b.c', ['d']);
* // ['a', 'b', 'c', 'd']
*
@jrencz
jrencz / dont-try-this-at-home.js
Created August 17, 2016 16:07
How can one tell well written angular app? When he sees this and it's still ~60fps on a decent laptop
$($window).on('scroll', function () {
scope.$apply(function () {
if ($window.pageYOffset > offsetTop) {
elem.css('left', offsetLeft + 'px');
elem.css('width', width + 'px')
// position: fixed; top: 100px;
elem.addClass('sticky');
} else {
elem.removeClass('sticky');
@jrencz
jrencz / SassMeister-input.scss
Last active September 15, 2016 10:32
variable interpolations in Sass
// ----
// Sass (v3.4.21)
// Compass (v1.0.3)
// ----
$color-rebeccapurple: rebeccapurple;
$color-red: red;
$color-blue: blue;
@mixin color(
@jrencz
jrencz / package.json
Last active December 27, 2016 10:08
Stats file to be used across many project-related packages. Autoprefixer compatible.
{
"name": "stats",
"version": "0.0.1"
}