Skip to content

Instantly share code, notes, and snippets.

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

Sergii Stotskyi stalniy

🏠
Working from home
View GitHub Profile
@stalniy
stalniy / 1. Intro.md
Last active March 28, 2024 09:10
Ebusd Vaillant Eloblock

Прошивка Wemos D1 mini для ebusd адаптера

Зазначені нижче кроки будуть актуальні для linux (ubuntu) та macos, вінда на "відпочинку" не мав змоги перевірити це там. Для прошивки будемо використовувати esptool.py

Вимоги: ubuntu : встановлений пайтон 3.8.10, або вище (має бути доступний за замовчанням, перевіряємо: python3 -V) macos : встановлений brew, за допомогою якого доставимо все необхідне

Установка esptool: MacOS:

@stalniy
stalniy / custom-pick.js
Created January 16, 2019 20:13
Custom pick with support for arrays using asterisk
function get(object, path) {
const fields = Array.isArray(path) ? path : path.split('.')
let cursor = object
for (let i = 0; i < fields.length; i++) {
if (fields[i] === '*') {
// TODO: validation of cursor being an array
const newPath = fields.slice(i + 1)
return cursor.map(item => get(item, newPath))
} else {
@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 / Appfile.rb
Created August 31, 2016 11:32 — forked from ravishtiwari/Appfile.rb
Ionic Build IPA with Fastlane tool
app_identifier "com.yourorganization.mytodoapp" # The bundle identifier of your app
apple_id "<You Apple Id>" # Your Apple email address
# You can uncomment any of the lines below and add your own
# team selection in case you're in multiple teams
# team_name "CAMobileApp"
# team_id "Q2CBPJ58CA"
# you can even provide different app identifiers, Apple IDs and team names per lane:
# https://github.com/KrauseFx/fastlane/blob/master/docs/Appfile.md
@stalniy
stalniy / index.js
Created August 10, 2020 12:52
CASL + Objection
const { defineAbility } = require('@casl/ability');
const { rulesToQuery } = require('@casl/ability/extra');
const Knex = require('knex');
const { Model } = require('objection');
const { interpret } = require('@ucast/objection')
const { CompoundCondition } = require('@ucast/core')
const knex = Knex({
client: 'sqlite3',
connection: ':memory:'
@stalniy
stalniy / cordova-upload-transport.js
Created November 1, 2016 10:18
Ionic/Cordova file upload
import { Inject } from 'lib/angular2'
import { File, Transfer } from 'ionic-native'
import { Events } from 'events'
import { Config } from 'config/env'
@Inject(Events, Config)
export class CordovaUploadTransport {
get cacheDirectory() {
return cordova.file.tempDirectory || cordova.file.cacheDirectory
}
@stalniy
stalniy / eslint-pushed-changes.sh
Created October 12, 2016 13:06
ESLINT + pre-receive git hook
#!/bin/bash
TEMPDIR=`mktemp -d`
ESLINTRC=$TEMPDIR/.eslintrc
COMMAND="eslint --color -c $ESLINTRC --rule 'import/no-unresolved: 0' --rule 'import/no-duplicates: 0' --rule 'import/export: 0'"
git show HEAD:.eslintrc > $ESLINTRC
echo "### Ensure changes follow our code style... ####"
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html#pre-receive
@stalniy
stalniy / example.js
Created October 16, 2020 19:01
UCAST dot notation
const test = guard({ 'author.id': 1 });
const sifter = sift({ 'author.id': 1 });
console.log(test({ author: { id: 1 } })) // true
console.log(sifter({ author: { id: 1 } })) // true
@stalniy
stalniy / example.js
Created October 16, 2020 18:58
ucast and sift.js difference
import { guard } from '@ucast/mongo2js';
import sift from 'sift';
const test = guard({ author: { id: 1 } });
const sifter = sift({ author: { id: 1 } });
console.log(test({ author: { id: 1 } })) // false
console.log(sifter({ author: { id: 1 } })) // true
@stalniy
stalniy / example.js
Created October 16, 2020 18:56
MongoDB query parser + JS interpreter
import { MongoQueryParser, allParsingInstructions } from '@ucast/mongo';
import { createJsInterpreter, allInterpreters } from '@ucast/js';
const parser = new MongoQueryParser(allParsingInstructions);
const interpret = createJsInterpreter(allInterpreters);
const ast = parser.parse({ authorId: 1, status: 'published' });
console.log(interpret(ast, { authorId: 1, status: 'published' })); // true
console.log(interpret(ast, { authorId: 2, status: 'published' })); // false