Skip to content

Instantly share code, notes, and snippets.

Hey hey people, Mark here, and today I wanted to share with you a very small library for js13k games called natlib. It consists of (refactored and improved!) parts lifted from my previous years' js13k submissions, some of those were in top-20 or something.

Included in this version are:

  • Fixed-step mainloop code that I use everywhere

    • Decouples world updates from rendering
    • Prevents floating-point error accumulation
    • Interpolate between the previous and the current state for smooth animation, especially noticeable when the rendering performance is low or inconsistent.
  • Mulberry32, a great little 32-bit PRNG

@mvasilkov
mvasilkov / count_regions.js
Last active February 19, 2020 20:10
Count isolated regions in a table
'use strict'
// The following table has 6 connected regions:
const tab = `
111100000000000000000
111000000001110011000
110000000000011111100
000000000111111100000
110000011111000000000
'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 February 11, 2020 15:38
Programming assignment №2
'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 February 11, 2020 08:50
Programming interview question
'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 November 26, 2019 15:54
Вороны клюют твою задачу, Джузеппе!
<!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 June 25, 2019 08:41
Ant.design modal form with wrappedComponentRef
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 / react_samples_list.md
Created August 8, 2017 10:05 — forked from jpalala/react_samples_list.md
React Samples List
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)
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) {