Skip to content

Instantly share code, notes, and snippets.

View alexesDev's full-sized avatar

Alexey Yurchenko alexesDev

  • Digital Nomad
View GitHub Profile
@alexesDev
alexesDev / app_change_notify_function.sql
Last active April 24, 2018 08:45
Postgres TRIGGER to call NOTIFY with a JSON payload
BEGIN;
create function app.change_notify()
returns trigger
language plpgsql
as $$
declare
channel_name text := coalesce(TG_ARGV[0], 'app_' || TG_TABLE_NAME || '_' || lower(TG_OP));
begin
if TG_OP = 'INSERT' or TG_OP = 'UPDATE' then
@alexesDev
alexesDev / enhance.js
Last active April 20, 2018 09:13
HOC: unchanged + recompact + antd
import { compose, withProps } from 'recompact';
import { Form } from 'antd';
import moment from 'moment';
import transform from 'utils/transform';
import withInitialFormValues from './withInitialFormValues';
export default compose(
Form.create(),
withProps(transform('data.node.birthday', moment)),
withInitialFormValues,
@alexesDev
alexesDev / withInitialFormValues.js
Last active April 8, 2018 08:10
Get initialValue from data.node for antd forms
import PropTypes from 'prop-types';
import { compose, withPropsOnChange, setPropTypes } from 'recompact';
export default compose(
setPropTypes({
data: PropTypes.shape({
node: PropTypes.object.isRequired,
}).isRequired,
form: PropTypes.shape({
getFieldDecorator: PropTypes.func.isRequired,
@alexesDev
alexesDev / upload.sh
Created March 16, 2018 17:03
Upload wp theme via ftp with bash and ci/cd
#!/bin/bash
find . -type f \
| grep -v 'node_modules\|semantic/src\|semantic/tasks' \
| xargs -P5 -L1 -I{} curl -s --user youruser:yourpassword --ftp-create-dirs -T {} ftp://xxx/blog/wp-content/themes/best/{}
@alexesDev
alexesDev / run.sql
Created March 13, 2018 09:31
Postgres security row polises with sessions vars
set role api; set session app.current_user_id to 1; select * from app_users;
id | first_name
----+------------
1 | john
2 | max
set role api; set session app.current_user_id to 2; select * from app_users;
id | first_name
@alexesDev
alexesDev / fancontrol.py
Last active March 12, 2018 09:38
just works, without comments, for applesmc.768
import time
import subprocess
def set_speed(val):
print(val)
subprocess.call('bash -c "echo 1 > /sys/devices/platform/applesmc.768/fan1_manual"', shell=True)
subprocess.call('bash -c "echo ' + str(val) + ' > /sys/devices/platform/applesmc.768/fan1_output"', shell=True)
while True:
print("start")
0xaa0a5080987b85575ef596f64f98ed229a3391d7
var { createStructuredSelector } = require("reselect")
const ide = {
tabs: [],
activeTab: null,
sidebarInitialSize: 100,
sidebarTab: 'schema',
contents: {},
};
@alexesDev
alexesDev / mouseray.cpp
Created January 25, 2018 08:23
Magnum engine: project mouse coords to XZ plane
Float screenX = event.position().x() / 1280.f;
Float screenY = event.position().y() / 1024.f;
Float nx = (2.0f * screenX) - 1.0f;
Float ny = 1.0f - (2.0f * screenY);
Vector4 midPoint(nx, ny, 0.0f, 1.0f);
Matrix4 inv = (_camera->projectionMatrix() * _camera->cameraMatrix()).inverted();
Vector3 eye = _cameraObject->transformation().translation();
@alexesDev
alexesDev / main.cpp
Last active January 8, 2018 21:40
Good Box2D plaformer movement
// ...
bool canJump = false;
bool canLeft = true;
bool canRight = true;
for (b2ContactEdge* ce = _playerBody->GetContactList(); ce; ce = ce->next) {
b2Contact* c = ce->contact;
if (c->IsTouching()) {