Skip to content

Instantly share code, notes, and snippets.

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

Michał Kuklis mkuklis

🏃‍♂️
View GitHub Profile
@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 },
];
@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 / mongoid_rake.rake
Created November 12, 2010 18:12
few rake tasks to interact with mongodb via mongoid
namespace :mongo do
def confirm(message)
print "\n#{message}\nAre you sure? [y/n] "
# STDIN is not supported on heroku :/
raise 'Aborted' unless STDIN.gets.chomp == 'y'
end
desc "gets database"
task :db => :environment do
@mkuklis
mkuklis / zepto.simulate.js
Created September 10, 2012 02:55
zepto.simulate.js
(function ($) {
var matchers = {
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
};
var defaults = {
x: 0,
y: 0,
@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 / gist:5294248
Last active September 7, 2021 21:39
auto curry in JavaScript
function toArray(args) {
return [].slice.call(args);
}
function autocurry(fn) {
var len = fn.length;
var args = [];
return function next() {
args = args.concat(toArray(arguments));
return (args.length >= len) ?
@mkuklis
mkuklis / gist:3985606
Created October 31, 2012 07:27
scalable socket.io with redis and node-http-proxy
// balancer node
var httpProxy = require('http-proxy');
var uuid = require('node-uuid');
var Cookies = require('cookies');
var redis = require('redis');
var connect = require('connect');
var express = require('express');
var RedisStore = require('connect-redis')(express);
var redisClient = redis.createClient();
var port = 8000;
@mkuklis
mkuklis / gist:4056724
Created November 11, 2012 23:36
NamedViewSelector
//viewport for https://github.com/scttnlsn/backbone.viewkit
var NamedViewSelector = Backbone.ViewKit.ViewPort.extend({
constructor: function (options) {
options || (options = {});
this._views = options.views || {};
_.each(this._views, function(view) {
view.viewSelector = this;
}, this);
@mkuklis
mkuklis / gist:1024385
Created June 14, 2011 05:37
Douglas Crockford's memoizer
var memoizer = function (memo, formula) {
var recur = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = formula(recur, n); memo[n] = result;
}
return result;
};
return recur;
};
@mkuklis
mkuklis / gist:5835614
Last active June 12, 2016 07:44
run zepto.js animations in sequence
$.fn.queueAnim = function (steps, callback) {
var $selector = this;
function iterator(step) {
step.push(iterate);
$selector.animate.apply($selector, step);
}
function iterate() {
if (!steps.length) return callback && callback();