Skip to content

Instantly share code, notes, and snippets.

View stasyanko's full-sized avatar
😀

Stanislav Yankovskiy stasyanko

😀
View GitHub Profile
@stasyanko
stasyanko / Caddyfile
Created June 2, 2025 09:37 — forked from evokelektrique/Caddyfile
How to deploy Laravel + Vite to Caprover
:80 {
root * /srv/app/public
@websockets {
header Connection *upgrade*
header Upgrade websocket
}
reverse_proxy @websockets 127.0.0.1:6001 {
header_down -X-Powered-By
}
@stasyanko
stasyanko / FsCsInterop.md
Created October 6, 2021 14:46 — forked from swlaschin/FsCsInterop.md
F# to C# interop tips

Tips on exposing F# to C#

Api and Methods

I suggest that you create one or more Api.fs files to expose F# code in a C# friendly way.

In this file:

  • Define functions with PascalCase names. They will appear to C# as static methods.
  • Functions should use tuple-style declarations (like C#) rather than F#-style params with spaces.
@stasyanko
stasyanko / json_postgres.js
Created June 6, 2018 14:39 — forked from lucdew/json_postgres.js
Example of json document storage in postgresql and querying (with knex.js)
var connectionString = 'postgres://localhost:5432/postgres';
var Promise=require('bluebird');
var knex = require('knex')({
client: 'pg',
connection: {
user: 'postgres',
database: 'postgres',
port: 5432,
@stasyanko
stasyanko / window_rank.sql
Created March 19, 2018 13:54 — forked from tokumine/window_rank.sql
calculating windowed rank in postgresql for a scoreboard or leaderboard
-- this SQL can be used to calculate the rank of a given user in a game,
-- and the names/scores of those just above and below him.
-- This is useful in online games or citizen science projects where you
-- just want to see the 'proximity' of other users around you, not the entire global rank
-- I want to find the rank and score for user_3, and other users 3 above and 3 below.
WITH global_rank AS (
SELECT name, score, rank() OVER (ORDER BY score DESC) FROM scores
)
SELECT * FROM global_rank
@stasyanko
stasyanko / goroutine_err_handling.go
Created November 16, 2017 10:25 — forked from burdenless/goroutine_err_handling.go
Handle errors in goroutines with a single channel
package main
import "fmt"
import "time"
// Goroutines Error Handling
// Example with same channel for Return and Error
type ResultError struct {
res Result
@stasyanko
stasyanko / interval.js
Created October 17, 2017 14:54 — forked from manast/interval.js
Accurate Javascript setInterval replacement
function interval(duration, fn){
this.baseline = undefined
this.run = function(){
if(this.baseline === undefined){
this.baseline = new Date().getTime()
}
fn()
var end = new Date().getTime()
this.baseline += duration
@stasyanko
stasyanko / node_crypto.js
Created October 5, 2017 12:42 — forked from rojan/node_crypto.js
Encrypt in nodejs and decrypt in php or vice versa
var crypto = require('crypto');
var key = 'MySecretKey12345';
var iv = '1234567890123456';
var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
var text = 'plain text';
var encrypted = cipher.update(text, 'utf8', 'binary');
encrypted += cipher.final('binary');
hexVal = new Buffer(encrypted, 'binary');
@stasyanko
stasyanko / mgoExample.go
Created July 18, 2017 12:25 — forked from border/mgoExample.go
mgo example
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"time"
)
type Person struct {
@stasyanko
stasyanko / gist:b0d0f80a9e8d07f89a88f7232c7da676
Created February 18, 2017 06:20 — forked from jfromaniello/gist:8418116
Example of authenticating websockets with JWTs.
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 8080});
var jwt = require('jsonwebtoken');
/**
The way I like to work with 'ws' is to convert everything to an event if possible.
**/
function toEvent (message) {
try {
@stasyanko
stasyanko / LoginController.js
Created February 17, 2017 14:10 — forked from psi-4ward/LoginController.js
Sails.JS JWT Auth
// controllers/LoginController.js
module.exports = {
index: function(req, res) {
var email = req.param('email');
var password = req.param('password');
// delay everthing to prevent bruteforce, dos and timing attacks
setTimeout(function() {