Skip to content

Instantly share code, notes, and snippets.

@mvasilkov
mvasilkov / power.py
Created Nov 20, 2011
Tail recursive power function
View power.py
from functools import partial, wraps
def power_tail(x, a, n):
assert n >= 0
if n == 0:
return x
elif n & 1:
return partial(power_tail, x * a, a, n - 1)
else:
return partial(power_tail, x, a * a, n >> 1)
View react_samples_list.md
@mvasilkov
mvasilkov / count_regions.js
Last active Feb 19, 2020
Count isolated regions in a table
View count_regions.js
'use strict'
// The following table has 6 connected regions:
const tab = `
111100000000000000000
111000000001110011000
110000000000011111100
000000000111111100000
110000011111000000000
View task_operators_100.js
'use strict'
const assert = require('assert').strict
/**
* Write a program that outputs all possibilities to put + or - or nothing
* between the numbers 1, 2, ..., 9 (in this order) such that the result
* equals 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
*/
@mvasilkov
mvasilkov / task_numbers.js
Last active Feb 11, 2020
Programming assignment №2
View task_numbers.js
'use strict'
/**
* Write a function that given a list of non negative integers,
* arranges them such that they form the largest possible number.
* For example, given [50, 2, 1, 9], the largest formed number is 95021.
*/
/* 1. Straightforward solution: get all permutations of numbers.
* Then find the largest of those.
@mvasilkov
mvasilkov / print_ipv4.js
Last active Feb 11, 2020
Programming interview question
View print_ipv4.js
'use strict'
// Take a valid octet from a string. Octet can be 1-3 characters
function takeOctet(octets, string) {
// If we have 4 octets, and nothing is left on the string, we're done
if (octets.length === 4) {
if (string.length === 0) {
console.log(`${octets[0]}.${octets[1]}.${octets[2]}.${octets[3]}`)
}
// Return anyway
@mvasilkov
mvasilkov / somoto_task.html
Last active Nov 26, 2019
Вороны клюют твою задачу, Джузеппе!
View somoto_task.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf8">
<title>Crows peck at your crops, Giuseppe!</title>
<style>
#thing {
height: 100px;
width: 100px;
}
@mvasilkov
mvasilkov / auth_form.js
Created Jun 25, 2019
Ant.design modal form with wrappedComponentRef
View auth_form.js
import React from 'react'
import { Form, Input } from 'antd'
import lang from '../app/lang'
export default Form.create({ name: 'auth' })(
class AuthForm extends React.Component {
render() {
const { getFieldDecorator } = this.props.form
@mvasilkov
mvasilkov / cleanup.sh
Created Mar 15, 2013
Recursively remove trailing whitespace from all files in the working directory.
View cleanup.sh
#!/bin/bash
LANG=C LC_ALL=C \
find . -not \( -name .git -prune -o -name .hg -prune -o -name .svn -prune \) \
-type f -exec sed -i '' 's/[[:blank:]]*$//' '{}' \;
View music_formula_collection.txt
Collection of oneliner music formulas. Version 2011-10-18
I've tried to collect all the formulas in the related threads etc.
(excluding those that clearly sound like random first experiments or total
crap; when several variants are available, i've chosen the shortest one)
If you think I've missed something that should be here, please let me know.
====== 1ST ITERATION ======