Skip to content

Instantly share code, notes, and snippets.

View Morriz's full-sized avatar

Maurice Faber Morriz

View GitHub Profile
@Morriz
Morriz / proxyquire.js
Created August 12, 2013 23:05
proxyquire patch for late resolving stub paths
var stubsRegistry = {};
/**
* Loads a module using the given stubs instead of their normally resolved required modules.
* @param request The requirable module path to load.
* @param stubs The stubs to use. e.g., { "path": { extname: function () { ... } } }
* @return {*} A newly resolved module with the given stubs.
*/
Proxyquire.prototype.load = function (request, stubs) {
validateArguments(request, stubs);
@Morriz
Morriz / sg-acc.tf
Created March 23, 2016 21:41
Terraform AWS SG settings for kubernetes worker and controller
resource "aws_security_group" "controller-acc" {
name = "kube-controller-acc"
vpc_id = "${aws_vpc.vpc-acc.id}"
tags {
"KubernetesCluster" = "kube-acc"
}
}
resource "aws_security_group" "worker-acc" {
@Morriz
Morriz / remove-old-images.js
Last active June 15, 2016 10:31
Removes old docker tags, while keeping the last imagesToKeep number.
const http = require('https')
const url = require('url')
const repo = process.argv[2]
const imagesToKeep = 5
const baseUrl = `https://USERNAME:PASSWORD@reg.your.com/v2/${repo}/`
console.info('removing old images for repo: ', repo)
http.get(`${baseUrl}tags/list`, res => {
let body = ''
res.on('data', (d) => {
0x2aA23385dE61d1f754BE822a422445FDc0B3c12b
import { PersistGate } from 'redux-persist/integration/react'
import { configureStore, checkVersions } from '@store/store'
...
const { store, persistor } = configureStore()
export default class App extends Component {
...
render() {
const { hideSplash } = this.props
return (
/**
* Given:
*
* A non-empty array A consisting of N integers is given. A pair of integers (P, Q),
* such that 0 ≤ P < Q < N, is called a slice of array A (notice that the slice contains
* at least two elements). The average of a slice (P, Q) is the sum of
* A[P] + A[P + 1] + ... + A[Q] divided by the length of the slice. To be precise,
* the average equals (A[P] + A[P + 1] + ... + A[Q]) / (Q − P + 1).
*
* Implied assumption:
/**
* A DNA sequence can be represented as a string consisting of the letters A, C, G and T,
* which correspond to the types of successive nucleotides in the sequence. Each nucleotide
* has an impact factor, which is an integer. Nucleotides of types A, C, G and T have impact
* factors of 1, 2, 3 and 4, respectively. You are going to answer several queries of the form:
* What is the minimal impact factor of nucleotides contained in a particular part of the given DNA sequence?
*
* The DNA sequence is given as a non-empty string S = S[0]S[1]...S[N-1] consisting of N characters.
* There are M queries, which are given in non-empty arrays P and Q, each consisting of M integers.
* The K-th query (0 ≤ K < M) requires you to find the minimal impact factor of nucleotides contained
@Morriz
Morriz / longest-chain.js
Created February 11, 2019 15:43
My codility solution to find the longest chain in an array where A[i] -> A[A[i]]:
const solution = A => {
let longest = 0
let next = 0
let count = 1
while (count < A.length) {
let len = 0
while (A[next] !== -1) {
len++
const prev = next
next = A[next]
@Morriz
Morriz / grocery-store.js
Last active August 20, 2022 11:30
My solution to codility grocery store problem: https://app.codility.com/programmers/task/grocery_store/
/**
* There is no food in your fridge and you are hungry. You want to go to a local store and buy some food. You have to hurry as some of the shops will close soon.
*
* There are N squares in your neighborhood and M direct roads connecting them. The squares are numbered from 0 to N − 1. You are living in square 0 and can reach it in 0 seconds. The stores are located in the squares, one in each of them. You are given a map of the neighborhood in the form of four zero-indexed arrays A, B, C and D. Each of the arrays A, B, C contains M integers, while D contains N integers.
*
* For each I (0 ≤ I < M), the walking distance between squares A[I] and B[I] is C[I] seconds (in either direction).
* There can be multiple roads connecting the same pair of squares, or a road with both ends entering the same square.
* It is possible that some roads go through tunnels or over bridges (that is, the graph of squares and roads doesn't have to be planar).
* It is not guaranteed that you are able to reach all the squar
@Morriz
Morriz / handy-oneliners.sh
Created December 24, 2020 20:58
Mo'z handy oneliners
# wget list of urls simultaneously with xargs, 32 at a time
cat list.txt | xargs -n 1 -P 32 wget -q