Skip to content

Instantly share code, notes, and snippets.

View alexesDev's full-sized avatar

Alexey Yurchenko alexesDev

  • nonono
View GitHub Profile
@alexesDev
alexesDev / .dockerignore
Last active May 17, 2019 09:45
Multi-stage Dockerfile for Rails 5.2
.git
.gitignore
Dockerfile
log
tmp
public/system
#include "GridRenderer.h"
#include <Magnum/SceneGraph/Camera.h>
#include <Magnum/DebugTools/ResourceManager.h>
using namespace Magnum;
Color3 getLineColor(Float i, const Color3 &baseColor, const Color3 &axesColor, const Color3 &subColor) {
if (i == 0) {
return axesColor;
@alexesDev
alexesDev / main.go
Last active October 18, 2018 19:52
golang http server template
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"sync/atomic"
"time"
function calculateInterceptShotPosition(pShooter, pTarget0, vTarget, sProjectile)
local R = pTarget0 - pShooter
local a = vTarget.x^2 + vTarget.y^2 - sProjectile^2
local b = 2 * (R.x * vTarget.x + R.y * vTarget.y)
local c = R.x^2 + R.y^2
if R:len2() < 1 then
return nil
end
#!/bin/bash
read -r -d '' CHECK_QUERY <<-EOM
create extension if not exists plpgsql_check;
SELECT
(pcf).functionid::regprocedure, (pcf).lineno, (pcf).statement,
(pcf).sqlstate, (pcf).message, (pcf).detail, (pcf).hint, (pcf).level,
(pcf)."position", (pcf).query, (pcf).context
@alexesDev
alexesDev / ProgressButton.js
Created August 15, 2018 12:10
antd + recompact: If the function passed in via the onClick prop return a Promise or if a promise is passed as an argument of the loading method, the component will automatically transition to its success or error states based on the outcome of the Promise without the need for external manipulation of state using a ref.
import { Button } from 'antd';
import { compose, omitProps, withState, withHandlers } from 'recompact';
const enhance = compose(
withState('loading', 'setLoading', false),
withHandlers({
onClick: props => e => {
if (!props.onClick) {
return;
}
@alexesDev
alexesDev / search.sql
Created August 13, 2018 12:35
PostgreSQL: search a top-level root parent id
with recursive r as (
select id, parent_id
from products
where id = 100
union
select p.id, p.parent_id
from products p
join r on p.id = r.parent_id
)
select id from r where parent_id is null;
@alexesDev
alexesDev / deploy.tmpl
Created August 4, 2018 20:18
createteable sqitch template ~/ .sqitch/templates
-- Deploy [% project %]:[% change %] to [% engine %]
[% FOREACH item IN requires -%]
-- requires: [% item %]
[% END -%]
[% FOREACH item IN conflicts -%]
-- conflicts: [% item %]
[% END -%]
BEGIN;
@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,