Skip to content

Instantly share code, notes, and snippets.

View brakmic's full-sized avatar
🏠

Harris Brakmić brakmic

🏠
View GitHub Profile
@brakmic
brakmic / modify_part_of_a_state.ts
Created April 11, 2017 09:16
modifying part of a state
return (<any>Object).assign({}, state, {
customer: action.payload
});
@brakmic
brakmic / app_state.ts
Last active April 11, 2017 10:14
application state
// Application state is like a database.
// Currently our 'database' comprises of a single table
// that can be modified by a certain reducer.
// The sub-state's name in IAppState corresponds to
// reducer's name in reducers object.
export interface IAppState {
customerState: fromSubstates.ICustomerState
};
// and we have only a single reducer here
@brakmic
brakmic / combine_reducers.ts
Created April 11, 2017 10:20
combine all of the reducers into one meta-reducer
const developmentReducer: ActionReducer<IAppState> = compose(storeFreeze, combineReducers)(reducers);
const productionReducer: ActionReducer<IAppState> = combineReducers(reducers);
// our meta-reducer will take care of forwarding all actions
export function AppReducer(state: any, action: any) {
if (String('<%= BUILD_TYPE %>') === 'dev') {
return developmentReducer(state, action);
} else {
return productionReducer(state, action);
}
@brakmic
brakmic / customer_effects.ts
Created April 11, 2017 10:47
handling customer effects
@Injectable()
export class CustomerEffects {
@Effect() customerSelected$: Observable<Action> = this.actions$
.ofType(CustomerActionTypes.SELECTED)
.map(action => {
let customer: ICustomer = _.cloneDeep(action.payload);
customer.active_debt = this.paymentService.activeDebt(customer.id);
customer.picture = this.imageService.imageUrl(customer.id);
return this.customerActions.customerInitialized(customer);
@brakmic
brakmic / heper_methods_state_extraction.ts
Last active April 11, 2017 11:14
helper methods for state extraction
export function getCustomerState(state$: Observable<IAppState>): Observable<ICustomerState> {
return state$.select(state => state.customerState);
}
export const getCustomer: (obs: Observable<IAppState>) => Observable<ICustomer> = compose(fromSubstates.getCustomer, getCustomerState);
@brakmic
brakmic / dispatch_action.ts
Created April 11, 2017 11:21
dispatching an action
this.customerTable.on('select', (e: Event, dt: DataTables.DataTable,
type: string, indexes: number[]) => {
let row: INWCustomer = dt.rows(indexes[0]).data()['0'];
const customer = this.toLocalCustomer(row);
this.store.dispatch(this.customerActions.customerSelected(customer));
});
@brakmic
brakmic / get_observable.ts
Created April 11, 2017 11:50
get customer observable
private getCustomerObservable() {
this.customer = getCustomer(this.store);
}
@brakmic
brakmic / alternative_customer_state_selection.ts
Created April 11, 2017 11:55
alternative way of selecting customer state
this.store.select(appState => appState.customerState).subscribe(subState => {
const customerInstance = subState.customer; // not an observable but a concrete instance
});
@brakmic
brakmic / WannaLaugh.ps1
Created May 12, 2017 22:57
stop WannaCry from spreading
# open powershell and execute this file
# let the window open
# if the script won't start because of local execution policy restrictions you can use "Set-Execution-Policy Bypass"
$createdNew = $False;
$mutex = New-Object -TypeName System.Threading.Mutex($true, "MsWinZonesCacheCounterMutexA", [ref]$createdNew);
0x094f3723c13E9ee24de4AEb5b358FdD94D34315C