Skip to content

Instantly share code, notes, and snippets.

View v1vendi's full-sized avatar

Ilya Komsa v1vendi

View GitHub Profile
@v1vendi
v1vendi / template.js
Last active June 28, 2016 21:53
A tiny js template engine using Template Strings and template tag (manually minified is 432 bytes long without gzip)
function compileTemplate(templateElement, data){
//hack to get unencoded symbols from HTML node
var textarea = document.createElement('textarea');
textarea.innerHTML = templateElement.innerHTML;
var text = eval("with(data){html`" + textarea.value + "`}");
var tmpElement = document.createElement('div');
tmpElement.innerHTML = text;
@v1vendi
v1vendi / gist:96c98641d2f36c09ed094c56aba4857d
Created November 3, 2017 12:52
Extract tar.bz2 to psql
tar -xOf FILE.tar.bz2 | psql -h HOST -U USER -d DATABASE
@v1vendi
v1vendi / gist:da0a9f94a5564540b3aed38ad2798ad8
Last active August 20, 2019 19:32
How to update Node on Windows
Download new binary from nodejs.org
@v1vendi
v1vendi / index.html
Last active October 21, 2018 21:27
React components for a page that does http request itself without redux
<title>Parcel demo</title>
<!-- <link rel=stylesheet href=./style.css /> -->
<style>
body {
max-width: 500px;
margin: auto;
}
#modal_holder:empty {
display: none;
}
@v1vendi
v1vendi / api_generator.js
Created August 20, 2019 19:19
REST API functional generator
const fetch = (...args) => console.log(...args) // mock
function httpRequest(url, method, data) {
const init = { method }
switch (method) {
case 'GET':
if (data) url = `${url}?${new URLSearchParams(data)}`
break
case 'POST':
case 'PUT':
case 'PATCH':
@v1vendi
v1vendi / button.js
Created September 5, 2019 17:19
Idea of React components composition
// i use bootstrap CSS classes for example
// class extension way:
const Button = ({ onClick, children, className }) => (
<button
class={`btn ${className}`.trim()}
onClick={onClick}
>
{children}
</button>
)
@v1vendi
v1vendi / case-insensitive-obj.js
Created February 13, 2020 12:09
Object wrapper for getting fields case-insensitively
const model = {
normalKey: 1,
coRRupTkey: 2,
innErKey: {
x: 3,
Y: 4
},
aRR: [
{ first: 5 }
]
@v1vendi
v1vendi / index.html
Last active April 10, 2023 05:42
Blender-like node editor
<title>JS node editor</title>
<link rel="stylesheet" href="style.css">
<div class=node style='left:50px; top: 50px;'>
<div class='in'>input label</div>
<div class='out'>output label</div>
</div>
<svg class=link width=50 height=127 style='left:350px;top: 95px'>
<path d="M 0 0, C 50 0, 00 127, 50 127" />
from random import randrange
from ortools.algorithms import pywrapknapsack_solver
PLAYERS_COUNT = 6
PLAYERS_IN_MATCH = 6
regions = {
'eu': 0,
'na': 1,
@v1vendi
v1vendi / hands_table.js
Created April 27, 2020 22:03
generate poker hands table
var values = Array.from('AKQJT98765432')
// values.map(j => `${values[Math.min(i,j)]}${values[Math.max(i,j)]}${i > j ? 's' : i < j ? 'o' : ''}`).join(', ')
var result = values.map(
(_,i) => values.map(
(_,j) => `${values[Math.min(i,j)]}${values[Math.max(i,j)]}${i > j ? 's' : i < j ? 'o' : ''}`.padEnd(4)
).join('')
).join('\n')
console.log(result)
/*