Skip to content

Instantly share code, notes, and snippets.

View mzahor's full-sized avatar

Marian Zagoruiko mzahor

  • LeanyLabs
  • Lviv, Ukraine
  • X @mzahor
View GitHub Profile
@mzahor
mzahor / js_proto_method_overloading.js
Last active September 7, 2015 15:50
Method overloading in js
var Person = function () {
this.name = "unnamed";
};
Person.prototype.getName = function () {
return this.name;
};
var Student = function () {
this.name = "Student";
@mzahor
mzahor / throttling_queue.cs
Last active May 23, 2017 02:01
Throttling task queue
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
namespace YammerCrawlSync
{
public class ThrottlingQueue : IDisposable
@mzahor
mzahor / squash.sh
Last active March 23, 2016 14:06
Branch squasher
#!/bin/bash
set -e
current_br=$(git name-rev --name-only HEAD)
tmp_br=${current_br}_temp
# remove temp branch if already exists
if [[ $(git br | grep ${tmp_br}) != '' ]]; then
git br -D ${tmp_br}
fi
@mzahor
mzahor / rx_stream_control.html
Last active March 1, 2016 13:18
Controlling one stream with another stream in RxJS
<!DOCTYPE html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script>
</head>
<body>
<label><input id="chb" type="checkbox">Run</label>
<div id="output"></div>
</body>
table { display: table }
tr { display: table-row }
thead { display: table-header-group }
tbody { display: table-row-group }
tfoot { display: table-footer-group }
col { display: table-column }
colgroup { display: table-column-group }
td, th { display: table-cell }
caption { display: table-caption }
@mzahor
mzahor / click-outside.directive.js
Created May 14, 2016 10:16
Click outside angular directive
let hookInstalled = false;
function ClickOutsideDirective($window, $rootScope, $parse) {
'ngInject';
return {
restrict: 'A',
link: function(scope, elem, attr) {
if (!hookInstalled) {
$window.document.addEventListener('click', function(event) {
@mzahor
mzahor / brute.py
Created December 10, 2017 13:28
RFID bruteforce
import itertools
import re
alphabet = '0123456789abcdef'
def crack():
for combination in itertools.combinations_with_replacement(alphabet, 12):
combostring = ''.join((combination))
bites = [int(bite, 16) for bite in re.findall('..', combostring)]
@mzahor
mzahor / webpack.config.js
Last active June 11, 2018 19:47
SourceMapDevToolPlugin demo
const webpack = require('webpack');
const path = require('path');
const isProd = NODE_ENV === 'production';
const ifProd = x => isProd && x;
const removeEmpty = arr => arr.filter(Boolean);
module.exports = {
entry: './index.js',
output: {
@mzahor
mzahor / StateProvider.js
Created March 14, 2019 22:59
Super-simple react state management
import React, { createContext, useReducer, useContext } from "react";
export const StateContext = createContext();
export const useStateContext = () => useContext(StateContext);
export const StateProvider = ({ reducer, initialState, children }) => (
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
);