Skip to content

Instantly share code, notes, and snippets.

View mCzolko's full-sized avatar

Michael Czolko mCzolko

View GitHub Profile
@mCzolko
mCzolko / RightClick.js
Last active May 10, 2021 08:58
ReactJS right click (contextmenu) handler
import { createElement, useEffect, useRef } from 'react'
const RightClick = ({ as = 'div', onRightClick, children, ...rest }) => {
const ref = useRef()
useEffect(() => {
const handler = e => {
e.stopPropagation()
e.preventDefault()
onRightClick(e)
@mCzolko
mCzolko / .bash_profile
Last active October 8, 2019 11:33
NVM automatic switch
# Install NVM or FVM
# https://github.com/nvm-sh/nvm
# https://github.com/Schniz/fnm
cd () { builtin cd "$@" && chpwd; }
chpwd () {
NVM_PATH="$PWD/.nvmrc"
if test -f "$NVM_PATH"; then
nvm use
const CANVAS_WIDTH = 1000;
const CANVAS_HEIGHT = 800;
function resizeImage(imageWidth, imageHeight) {
const ratio = imageWidth / imageHeight;
let width = CANVAS_WIDTH;
let height = width / ratio;
if (height > CANVAS_HEIGHT) {
height = CANVAS_HEIGHT;
@mCzolko
mCzolko / undoable.js
Created October 23, 2018 15:12
Redux Immutable Undo with diffs instead of saving whole state.
import { Map, List } from 'immutable';
const diff = require('immutablediff');
const patch = require('immutablepatch');
export const ActionTypes = {
UNDO: 'undoable/UNDO',
REDO: 'undoable/REDO',
LOAD: 'undoable/LOAD',
CLEAR_PAST: 'undoable/CLEAR_PAST',
};
@mCzolko
mCzolko / font-responsive.scss
Created December 14, 2016 11:02
responsive font in specific viewport sizes
@mixin font-resposive($font-from, $font-to, $media-from, $media-to) {
@media screen and (max-width: $media-from) {
font-size: $font-from + 0px;
&:before { content: $font-from + ''; }
}
$iteration-count: $font-to - $font-from;
$divider: ($media-to - $media-from) / $iteration-count;
@mCzolko
mCzolko / swipe.js
Last active August 4, 2016 17:41
Swipe javascript handler
document.addEventListener('touchmove', handleTouchMove, false)
document.addEventListener('touchend', handleTouchEnd, false)
class Position {
constructor(x, y) {
this.x = x
this.y = y
}
@mCzolko
mCzolko / warmup.js
Last active January 5, 2016 18:22
HackerRank
// Solution for:
// Simple Array Sum
// A Very Big Sum
function main() {
var n = parseInt(readLine());
arr = readLine().split(' ');
console.log(arr.map(Number).slice(0, n).reduce( (a, b) => a + b ));
}
// Staircase
@mCzolko
mCzolko / ChainCommand.php
Last active October 22, 2015 19:50
It serves purpose decoupling logic into multiple Symfony2 commands and executing one after another.
<?php
namespace Railhard\ImportBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class ChainCommand extends Command
{
<?php
class DateTimeHelper {
/**
* @param array $dateintervals Array of \DateInterval
* @return \DateInterval
*/
public function calculateIntervalAverage($dateintervals)
{
<?php
namespace Duedil\Bundle\AppBundle\Command;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class PersistALotOfEntitiesCommand extends Command