Skip to content

Instantly share code, notes, and snippets.

View anchnk's full-sized avatar

ƇʘƁ̆ąƇ́ anchnk

View GitHub Profile
'use strict';
const { SinglyLinkedList, Node } = require('./../interview');
const assert = require('assert');
describe('SingleLinkedList.reverse', function() {
let linkedList;
beforeEach(() => {
@anchnk
anchnk / index.js
Last active February 25, 2019 16:18
#!/usr/bin/env node
'use strict';
const f = new Map();
f.set('availpro:1', {id: 1, provider: 'availpro', name: 'Hotel du sentier', rating: 3}); // delete
f.set('synxis:2', {id: 2, provider: 'synxis', name: 'Hotel Opera', rating: 0}); // update
f.set('fastbooking:3', {id: 3, provider: 'fastbooking', name: 'Hotel Garnier', rating: 5}); // skip
const s = new Map();
@anchnk
anchnk / jest-manual-mock-restore.js
Created December 24, 2018 14:10
failing example of restoring a manual mock
'use strict';
let neatCsv = require('neat-csv');
let { parseResponseToJson } = require('./neat-csv.js');
jest.mock('neat-csv', () =>
jest.fn().mockRejectedValueOnce(new Error('Error while parsing'))
);
const csv = 'type;part\nunicorn;horn\nrainbow;pink';
@anchnk
anchnk / jest-module-deps.js
Created December 24, 2018 14:01
A simple JS function with an npm dependency I am trying to test
'use strict';
const neatCsv = require('neat-csv');
async function parseResponseToJson(apiResponse) {
try {
const result = await neatCsv(apiResponse.body, {
separator: ';'
});
return result;
@anchnk
anchnk / jest-test-env-variables.md
Created November 5, 2018 11:17
Jest environment variable testing

Simple example that demonstrates how to test environment variables from Jest

describe('models/env unit tests', () => {
  function importTestedModule() {
    return require('../../../src').models; // eslint-disable-line
  }

  beforeEach(() => {
 jest.resetModules();
@anchnk
anchnk / ubuntu-trash-files-older-than.md
Created August 8, 2018 08:40
Command to move files to Ubuntu trash for files older than:

Command to move files to Ubuntu trash for files older than:

find . -type f -name '*.txt' -mtime +7 -exec gio trash {} \;

Where:

  • find .: search current folder
  • -type f: limit search to files
  • -name '*.txt*': limit search to files that have .txt extension
  • -mtime +7: last modification date is >= 7 days
@anchnk
anchnk / manning-dashboard-counters.md
Last active August 6, 2018 15:04
Extract manning dashboard metrics (books, videos, meaps)

Firefox Scratchpad that parse metrics from manning's dashboard:

function getElementsCount(attributeName) {
  return document.querySelectorAll(`#productTable > tbody > tr[${attributeName}=true]`).length;
}

var labelsMap = new Map([
  ['is-book', 'books'],
 ['is-meap', 'meaps'],
@anchnk
anchnk / vim-tips.md
Last active July 31, 2019 13:38
My (Neo)Vim workflow tips & tricks

JSON Data Manipulation

Format JSON

:%!python -m json.tool
:set ft=json
:%s/    /  /g
@anchnk
anchnk / list-cwd-dotfiles-desc-size.sh
Created June 3, 2017 17:07
Linux command line katas
#!/bin/sh
ls -pla | grep -v / | grep "^." | sort -k 5nr