Skip to content

Instantly share code, notes, and snippets.

View nikolaymatrosov's full-sized avatar

Nikolay Matrosov nikolaymatrosov

View GitHub Profile
@nikolaymatrosov
nikolaymatrosov / gist:f8bda2f66f848b3eec7d
Created December 30, 2014 13:01
Lua redirects based on backend response
server {
listen 7777;
location / {
root /tmp/www;
index index.html;
try_files $uri @lua;
}
location /api {
@nikolaymatrosov
nikolaymatrosov / gist:e78672a17ab45a58b882
Created July 7, 2015 09:27
Pre-commit hook (check for forgotten `only`, run client tests only on client code changes)
#!/bin/sh
SRC=$(git rev-parse --show-toplevel)/src/client
#==========================================================
# Check if I forgot to remove 'only' keyword from tests.
# To make sure that before commit run all tests
only=`grep -c -h -r --include "*.spec.js" -E "(describe|it)\.only" $SRC/src | awk -F ':' '{x +=$0}; END {print x}'`
if (( $((only)) > 0 ))
then
echo 'Remove ONLY from tests.'
@nikolaymatrosov
nikolaymatrosov / package.json
Created August 5, 2015 11:38
Mocha test setup for testing React using JsDOM
{
...
"scripts": {
"test": "mocha --recursive --require test_setup.js src/**/*.spec.js",
},
"devDependencies": {
"babel": "5.6.14",
"babel-core": "5.6.20",
"babel-plugin-rewire": "0.1.5",
"chai": "3.0.0",
@nikolaymatrosov
nikolaymatrosov / fixed-data-table.d.ts
Last active December 7, 2015 08:29
Definiton file to fixed-data-table 0.6.0. Made based on component props types.
// Type definitions for fixed-data-table 0.6.0
// Project: https://github.com/facebook/fixed-data-table
/// <reference path="../react/react.d.ts"/>
declare module FixedDataTable {
export var version: string;
export interface TableProps extends __React.Props<Table> {
/**
@nikolaymatrosov
nikolaymatrosov / Counter.tsx
Created June 9, 2016 16:55
Arrow function example
export class Counter extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {count: props.initialCount};
}
tick = () => {
this.setState({count: this.state.count + 1});
}
render() {
return (
@nikolaymatrosov
nikolaymatrosov / index.ts
Created September 23, 2016 08:03
Typescript and Immutable.js Record usage example.
import * as Immutable from 'immutable';
const UserRecord = Immutable.Record({
id: '',
age: 0
}, 'User');
class User extends UserRecord {
public readonly id: string;
public readonly age: number;
using System;
using System.IO;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@nikolaymatrosov
nikolaymatrosov / build.yaml
Created April 21, 2020 17:09
Github Action to build and publish static Gatsby site
name: Gatsby Build and Publish
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
@nikolaymatrosov
nikolaymatrosov / diagram.py
Created September 26, 2020 13:44
Yandex cloud diagram
from diagrams import Diagram
from diagrams import Group
from diagrams.yc.infrastructure import Compute
from diagrams.yc.serverless import ServerlessFunctions
from diagrams.yc.serverless import ServerlessTriggers
from diagrams.yc.serverless import YMQ
with Diagram("Create Snapshots", show=False, direction="LR", curvestyle="polyline"):
cron = ServerlessTriggers("Cron Trigger")
spawn = ServerlessFunctions("Spawn Function")
@nikolaymatrosov
nikolaymatrosov / index.ts
Last active November 12, 2020 20:12
Yandex Cloud Cron Snapshot
import {DiskService, SnapshotService} from "yandex-cloud/api/compute/v1";
const FOLDER_ID = process.env.FOLDER_ID;
export async function handler(event, context) {
const snapshotService = new SnapshotService();
const diskService = new DiskService();
const diskList = await diskService.list({
folderId: FOLDER_ID,