Skip to content

Instantly share code, notes, and snippets.

View mkuklis's full-sized avatar
🏃‍♂️

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@mkuklis
mkuklis / zustand_actions.js
Created November 24, 2021 17:11
zustand middleware for actions
// Extends API with actions
const actionsMiddleware = fn => (set, get, api) => {
const _actions = {};
api.actions = () => _actions;
const state = fn(set, get, api);
Object.keys(state).forEach(key => {
if (typeof state[key] === 'function') {
@mkuklis
mkuklis / lambda-image-resizer.js
Created July 31, 2018 17:53
AWS Lambda for image resizing with sharp
const sharp = require('sharp');
const aws = require('aws-sdk');
const s3 = new aws.S3();
const Bucket = "BucketName";
const transforms = [
{ name: 'small', size: 85 },
{ name: 'medium', size: 160 },
{ name: 'large', size: 250 },
];
var storage = {
init: function (success, error) {
window.requestFileSystem(PERSISTENT, 100 * 1024 * 1024, success, error);
},
write: function (fileName, content, success, error) {
this.init(function (fs) {
fs.root.getFile(fileName, { create: true }, function (fileEntry) {
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = callback;
description "mongodb container"
author "ququplay"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
# Wait for docker to finish starting up first.
FILE=/var/run/docker.sock
while [ ! -e $FILE ] ; do
inotifywait -t 2 -e create $(dirname $FILE)

Keybase proof

I hereby claim:

  • I am mkuklis on github.
  • I am michal (https://keybase.io/michal) on keybase.
  • I have the public key with fingerprint 4CC4 26DF 45A8 5858 B8ED  A22C A674 443D E215 6841

To claim this, I am signing this object:

@mkuklis
mkuklis / run.js
Last active January 4, 2016 07:59
simple run
function run(genfun) {
var gen = genfun();
function next(err, answer) {
if (err) {
return gen.throw(err);
}
var res = gen.next(answer);
@mkuklis
mkuklis / gist:7587994
Created November 21, 2013 19:28
KitKat test for WebSocket
function hasWebSocket() {
var m = navigator.userAgent.match(/Android ([0-9]+)\.([0-9]+)/i);
if (m) {
var x = parseInt(m[1], 10);
var y = parseInt(m[2], 10);
return window.WebSocket && (x > 4 || (x == 4 && y >= 4));
}
# dump heroku db
heroku pgbackups:capture
# restore
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d database_name DUMP_PATH
@mkuklis
mkuklis / LICENSE.txt
Last active February 5, 2023 03:20 — forked from 140bytes/LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@mkuklis
mkuklis / gist:5942570
Created July 7, 2013 06:39
elo rating
function elo(oldRating, opponentRating, result) {
var kFactor;
var expected = 1.0 / (1.0 + Math.pow(10.0, ((opponentRating - oldRating) / 400)));
if (oldRating < 2100) {
kFactor = 32;
} else if (oldRating >= 2100 && oldRating <= 2400) {
kFactor = 24;
}
else if (oldRating > 2400) {