Skip to content

Instantly share code, notes, and snippets.

Avatar

я котик пур-пур mvasilkov

View GitHub Profile
@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
View react_samples_list.md
View foo.py
import Image, ExifTags
try:
image=Image.open(os.path.join(path, fileName))
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation': break
exif=dict(image._getexif().items())
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
View content_script.js
var res = []
parse(document.documentElement)
chrome.runtime.sendMessage(res)
function parse(node) {
var i, a, name = node.tagName.toLowerCase()
res.push({type: 'o', name: name})
for (i = 0; i < node.attributes.length; ++i) {
@mvasilkov
mvasilkov / bash jmp
Created Feb 21, 2015
Bash jmp script
View bash jmp
function jmp { cd -P "$JMP_PATH/$1" 2>/dev/null || echo Not found; }
function setjmp { ln -s "`pwd`" "$JMP_PATH/$1"; }
function deljmp { rm -i "$JMP_PATH/$1"; }
export JMP_PATH="$HOME/.jmp"
You can’t perform that action at this time.