Skip to content

Instantly share code, notes, and snippets.

View gkucmierz's full-sized avatar
💻

Grzegorz Kućmierz gkucmierz

💻
View GitHub Profile
// usefull object, to clip array in O(1) when we don't want to make copies of it (slice)
const ClipArray = arr => {
let low = 0;
let up = arr.length;
const length = () => up - low;
return {
clipHead: n => {
low += n;
if (low > up) low = up;
const collatz = n => {
const res = [n];
while (n !== 1) {
if (n % 2 === 0) {
n /= 2;
} else {
n = n * 3 + 1;
}
res.push(n);
var silent = false;
var mute = () => silent = true;
var unmute = () => silent = false;
var loop = () => {
const play = (frequency = 300, duration = 1e3) => {
const context = new AudioContext();
const gainNode = context.createGain();
const oscillator = context.createOscillator();
// const Sunday = 0;
// const Monday = 1;
const TUESDAY = 2;
// const Wednesday = 3;
// const Thursday = 4;
// const Friday = 5;
// const Saturday = 6;
const firstDayOfMonth = (year, month, weekDay) => {
@gkucmierz
gkucmierz / macbook_setup.md
Last active September 25, 2020 09:56 — forked from hrishimittal/macbook_setup.md
Setting up a new MacBook for Ruby on Rails web development
  1. Install Google Chrome
  2. Install Homebrew - http://brew.sh/
  3. Install GnuPG - brew install gnupg2
  4. Generate SSH key - ssh-keygen -t rsa -b 4096 -C "gkucmierz@gmail.com"
  5. Install node, npm, n
  6. Git - brew install git
  7. Add SSH public key to Github, Bitbucket.
  8. Restore pgp key https://dev.to/gkucmierz/how-to-make-my-git-contributions-verified-2e76
  9. To delete words with alt+backspace in Terminal, go to Preferences > (your profile) > Keyboard > Use option as meta key.
  10. Sublime Text shortcut: sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
// find_value.js
const arr = ['a', 'b', 'c', 'd'];
const stopAt = 'c';
console.log(
arr.findIndex((...args) => {
console.log('args', args);
if (args[0] === stopAt) return true;
return false;
const BYTE = 8;
const BITS = 64;
const SEGMENTS = 8;
const SEGMENT = BITS / SEGMENTS;
const METHODS_MAP = {
8: ['getUint8', 'setUint8', 'getInt8', 'setInt8'],
16: ['getUint16', 'setUint16', 'getInt16', 'setInt16'],
32: ['getUint32', 'setUint32', 'getInt32', 'setInt32'],
};
const solveFor = (target, input, solveFn) => {
let solved = false;
const sort = arr => arr.sort((a, b) => a-b);
const nums = input.map(n => +n);
const ops = [...'+*'];
const fns = {
'+': (a, b) => a + b,
'*': (a, b) => a * b,
@gkucmierz
gkucmierz / mortgage_register_checksum.js
Created May 5, 2020 17:13
MortgageRegister calculate and verify checksum
// https://ekw.ms.gov.pl/
class MortgageRegister {
static check(str) {
const m = str.match(/([A-Z0-9]{4}\/[0-9]{8})\/([0-9])/);
if (m) {
return this.checksum(m[1]) === +m[2];
}
return false;
@gkucmierz
gkucmierz / alphametic_solver.js
Last active May 4, 2020 03:24
alphametic puzzle solver (brute force)
// alphametic puzzle solver (brute force)
const solve = (a, b, c, s) => {
const uniq = [...new Set([...(a+b+c+s)])];
const res = [];
const rec = nums => {
if (nums.length >= uniq.length) {
const an = +[...a].map(l => nums[uniq.indexOf(l)]).join``;
const bn = +[...b].map(l => nums[uniq.indexOf(l)]).join``;
const cn = +[...c].map(l => nums[uniq.indexOf(l)]).join``;