Skip to content

Instantly share code, notes, and snippets.

View jtomaszewski's full-sized avatar

Jacek Tomaszewski jtomaszewski

View GitHub Profile
@jtomaszewski
jtomaszewski / rt-stateful-component.ts
Created January 11, 2019 11:05
Example implementation of StatefulComponent in Angular
// Code authored by [Recruitee](https://recruitee.com)
// License: MIT
import { Injectable, ChangeDetectorRef } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
const immutableStateInvariantMiddleware = process.env.NODE_ENV !== 'production'
? require('redux-immutable-state-invariant').default
: null;
export interface RtStatefulComponent<State> {
flatten = array => {
return array.reduce((sum, x) => {
if (Array.isArray(x)) {
return [...sum, ...flatten(x)];
} else {
return [...sum, x];
}
}, [])
};
// wrong (impure)
class DateTimePickerComponent {
timeZone: string = "Europe/Warsaw";
constructor(private account: AccountService) {
if (this.account.currentUser) {
this.timeZone = this.account.currentUser.timeZone;
}
}
<div class="sidebar">
<my-search-page-sidebar
[filters]="state.filters"
(filtersChange)="changeFilters($event)">
</my-search-page-sidebar>
</div>
<div class="content">
<h2>Search</h2>
<my-search-page-query-input
[value]="state.query"

Code formatting & linting

In Recruitee, enforce correct formatting of our files with js-beautify for all src/ng2/**/*.html files and prettier for all **/*.{ts,js,css,less} files.

We also lint all **/*.ts files (and components' .html templates) code style with TSLint, although during the automatic linting, we ignore legacy files listed in ./tslint.without-legacy.json.

During npm install, husky automatically sets up a pre-commit hook in this repository, that will check your code before each commit and fail if it's wrong. If you want to skip the pre-commit hook, you can run git commit --no-verify.

Additionally, our CI will also check your code with npm run format-test &amp;&amp; npm run lint command and fail if it's badly formatted or its' non-legacy fi

@jtomaszewski
jtomaszewski / 015-disable_bitcode_on_ios.sh
Last active January 5, 2016 07:59
hooks/after_platform_add/015-disable_bitcode_on_ios.sh
#!/bin/sh
# Exit, if there's no ios here.
[[ $CORDOVA_PLATFORMS == *"ios"* ]] || exit 0
# This is needed until https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1116 gets fixed.
XCCONFIG_FILE="platforms/ios/cordova/build.xcconfig"
if ! cat $XCCONFIG_FILE | grep -q "ENABLE_BITCODE"; then
echo "\nENABLE_BITCODE = NO" >> $XCCONFIG_FILE
fi
@jtomaszewski
jtomaszewski / deploy.rb
Last active October 21, 2015 17:22
Eye configuration for unicorn && sidekiq
# ...
namespace :deploy do
desc 'Restart application'
task :restart => ["eye:reload", "eye:restart"]
after :published, :restart
end
@jtomaszewski
jtomaszewski / app_run.coffee
Created January 7, 2015 15:47
Ionic Framework: Turn off animations on Android and iOS 6 devices.
app.config ($injector) ->
model = ionic.Platform.device().model or ""
animateNavigation = ionic.Platform.grade == "a"
unless animateNavigation
defaults =
'$ionicNavBarConfig':
transition: 'no-animation'
'$ionicNavViewConfig':
transition: 'no-animation'
@jtomaszewski
jtomaszewski / ionicVerticalSlideBox.js
Created November 5, 2014 10:45
A cloned `ionic.views.Slider` and `slideBox` directive to `ionic.views.verticalSlider` and `verticalSlideBox`: it was done just by renaming "x, y, left, right" strings into "y, x, top, bottom". It works correctly ;)
var IonicModule = angular.module('ionic'),
extend = angular.extend,
forEach = angular.forEach,
isDefined = angular.isDefined,
isString = angular.isString,
jqLite = angular.element;
/**
* @ngdoc directive
* @name ionVerticalSlideBox
@jtomaszewski
jtomaszewski / ng_http_transform_request_to_form_data.coffee
Created April 17, 2014 14:45
Method that transforms data[Hash] into FormData object.
angular.module 'gulliver'
# This will transform data[Hash] into FormData object.
# Supports nested objects and FileList (file input's value).
#
# Note: This won't work on browsers not supporting FormData and FileList (f.e. IE 8-9).
.service 'httpTransformRequestToFormData', ->
(data) ->
return data unless data