Skip to content

Instantly share code, notes, and snippets.

View stalniy's full-sized avatar
🏠
Working from home

Serhii Stotskyi stalniy

🏠
Working from home
View GitHub Profile
@stalniy
stalniy / Can.jsx
Last active February 2, 2018 10:24
React Permissions with CASl
<Can run="delete" on={this.props.todo}>
<button onClick={this.deleteTodo.bind(this}>Delete</button>
</Can>
@stalniy
stalniy / disable.sh
Created January 20, 2018 05:19
Disable bunch of #$!@ in Sierra (Version 2.1)
#!/bin/bash
# IMPORTANT: You will need to disable SIP aka Rootless in order to fully execute this script, you can reenable it after.
# WARNING: It might disable things that you may not like. Please double check the services in the TODISABLE vars.
# Get active services: launchctl list | grep -v "\-\t0"
# Find a service: grep -lR [service] /System/Library/Launch* /Library/Launch* ~/Library/LaunchAgents
# Agents to disable
TODISABLE=('com.apple.security.keychainsyncingoveridsproxy' 'com.apple.personad' 'com.apple.passd' 'com.apple.screensharing.MessagesAgent' 'com.apple.CommCenter-osx' 'com.apple.Maps.mapspushd' 'com.apple.Maps.pushdaemon' 'com.apple.photoanalysisd' 'com.apple.telephonyutilities.callservicesd' 'com.apple.AirPlayUIAgent' 'com.apple.AirPortBaseStationAgent' 'com.apple.CalendarAgent' 'com.apple.DictationIM' 'com.apple.iCloudUserNotifications' 'com.apple.familycircled' 'com.apple.familycontrols.useragent' 'com.apple.familynotificationd' 'com.apple.gamed' 'com.apple.icloud.findmydeviced.findmydevi
@stalniy
stalniy / jasmine-this-vars.md
Last active January 9, 2018 05:59 — forked from traviskaufman/jasmine-this-vars.md
Better Jasmine Tests With `lazy vars`

Better Jasmine Tests With lazy vars

All of my unit tests are written using Jasmine or Mocha, an awesome BDD libraries. Recently I switched how data for tests is set up from declaring and assigning to closures, to defining lazy variables using bdd-lazy-var, and I've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test looked something like this:

var BaseClass = require('../../www/BaseClass')
@stalniy
stalniy / abilities.js
Created January 5, 2018 20:58
CASL Vue routes
import { AbilityBuilder, Ability } from 'casl'
// Alternatively this data can be retrieved from server
export default function defineAbilitiesFor(user) {
const { rules, can } = AbilityBuilder.extract()
can('read', 'User')
can('update', 'User', { id: user.id })
if (user.role === 'doctor') {
@stalniy
stalniy / main.js
Created November 17, 2017 11:23
Vue authorization (CASL + Vue)
import ability from '/ability'
import abilitiesPlugin from './ability-plugin'
Vue.use(abilitiesPlugin, ability)
@stalniy
stalniy / casl-vue-plugin.js
Created November 17, 2017 11:12
CASL vuejs auhtorization plugin
export default function abilitiesPlugin(Vue, ability) {
const bus = new Vue()
const update = ability.update
ability.update = function updateAndNotify(...args) {
const result = update.apply(this, args)
bus.$emit('ability:update')
return result
}
@stalniy
stalniy / ability.js
Created November 16, 2017 16:06
Todo app abilities
import { AbilityBuilder } from 'casl'
/**
* Defines how to detect object's type: https://stalniy.github.io/casl/abilities/2017/07/20/define-abilities.html
*/
function subjectName(item) {
if (!item || typeof item === 'string') {
return item
}
@stalniy
stalniy / infinite-scroll.ts
Created September 13, 2017 19:22
Ionic infinite scroll
import { Directive, ElementRef, EventEmitter, Input, NgZone, Output, forwardRef, Renderer } from '@angular/core';
import { Content, ScrollEvent, DomController, InfiniteScroll as IonicInfiniteScroll } from 'ionic-angular';
// TODO: remove this when https://github.com/ionic-team/ionic/pull/12599 is merged
@Directive({
selector: 'my-infinite-scroll',
providers: [
{ provide: IonicInfiniteScroll, useExisting: forwardRef(() => InfiniteScroll) }
]
})
@stalniy
stalniy / factory-adapter-direct-usage.js
Last active September 6, 2017 18:48
FactoryGirl Factory adapter
const { factory, ObjectAdapter } = require('factory-girl');
class FactoryAdapter {
constructor(adapter) {
this.defaultAdapter = adapter;
['save', 'destroy', 'get', 'set'].forEach(method => {
this[method] = adapter[method].bind(adapter);
})
}
@stalniy
stalniy / server.js
Created September 5, 2017 06:17
Proxy between 2 http servers in nodejs (one server is created asynchronously)
const request = require('supertest');
const http = require('http');
const originalServer = http.createServer(function(req, res) {
if (req.url === '/test') {
res.end('opa');
} else if (req.method === 'POST') {
let body = '';
console.log(req.headers)
req.on('data', (chunk) => body += chunk)