Skip to content

Instantly share code, notes, and snippets.

View onurkerimov's full-sized avatar

Onur Kerimov onurkerimov

View GitHub Profile
@onurkerimov
onurkerimov / Ideal mental model for React.md
Last active March 2, 2023 10:52
My take on an ideal mental model for React (A React without hooks)
import create from 'xoid'
import React from 'react'

const App = ($props, { effect, read }) => {
  const $count = create(0)
  const increment = () => $count.update(state => state + 1)

 // conditionally callable context reader
@onurkerimov
onurkerimov / example.js
Created January 4, 2021 19:27
Dark mode detection with MutationObserver API
const htmlTag = document.querySelector('html')
const checkDarkMode = () => htmlTag.hasAttribute('dark')
const watchDarkMode = (onChange) => {
let isDark, isDarkBefore
isDark = checkDarkMode()
onChange(isDark)
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
@onurkerimov
onurkerimov / info.md
Last active March 4, 2024 01:41
Open idea: parser combinator API using regex

This is my take on building a parser combinator library API in JavaScript. This library would have a very low surface area, and would be easy to learn for those who already know already know regex.

Parser combinators often create their own DSL (domain-specific language) to provide a less verbose way of declaring parsers. These DSLs have to support operators for things such as repetition, alternation, optionality, lookahead, and more. Some of them don't create DSLs and provide these as helper functions.

In the following link, there are JSON parser implementations done by several parser combinatiors/generators: https://chevrotain.io/performance/ Some of them are verbose, some of them are concise.

This parser combinator API I'm proposing will not provide a DSL, however it will result in very short parser declarations.

const Tree = (props) => (
<ul>
{props.nodes.map((node, key) => (
<li key={key}>
<div className={'name'}>{node.name}</div>
{node.children && <Tree nodes={node.children} />}
</li>
))}
</ul>
);
@onurkerimov
onurkerimov / openFolderAsVSCodeProject.reg
Last active August 11, 2019 10:04
Open Folder as VSCode Project on contextmenu
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="Open Folder as &VS Code Project"
[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="\"C:\\Users\\REPLACE_THIS_WITH_YOUR_USERNAME\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"%1\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
@="Open Folder as &VS Code Project"
@onurkerimov
onurkerimov / simple-javascript-css-html-tokenizer.js
Created May 28, 2019 23:58
A simple javascript, css, html tokenizer/lexer. Taken from @lrsjng/lolight - Lightweight tokenizer and syntax highlighter. https://larsjung.de/lolight/
/**
* Code taken from @lrsjng/lolight - Lightweight tokenizer and syntax highlighter.
* https://larsjung.de/lolight/
*/
var KEYWORD_RE = /^(a(bstract|lias|nd|rguments|rray|s(m|sert)?|uto)|b(ase|egin|ool(ean)?|reak|yte)|c(ase|atch|har|hecked|lass|lone|ompl|onst|ontinue)|de(bugger|cimal|clare|f(ault|er)?|init|l(egate|ete)?)|do|double|e(cho|ls?if|lse(if)?|nd|nsure|num|vent|x(cept|ec|p(licit|ort)|te(nds|nsion|rn)))|f(allthrough|alse|inal(ly)?|ixed|loat|or(each)?|riend|rom|unc(tion)?)|global|goto|guard|i(f|mp(lements|licit|ort)|n(it|clude(_once)?|line|out|stanceof|t(erface|ernal)?)?|s)|l(ambda|et|ock|ong)|m(odule|utable)|NaN|n(amespace|ative|ext|ew|il|ot|ull)|o(bject|perator|r|ut|verride)|p(ackage|arams|rivate|rotected|rotocol|ublic)|r(aise|e(adonly|do|f|gister|peat|quire(_once)?|scue|strict|try|turn))|s(byte|ealed|elf|hort|igned|izeof|tatic|tring|truct|ubscript|uper|ynchronized|witch)|t(emplate|hen|his|hrows?|ransient|rue|ry|ype(alias|def|id|name|of))|u(n(checked|def(ined)?|ion|less|signed|til)|se|sing
@onurkerimov
onurkerimov / DA UI SublimeText Theme Settings
Created November 27, 2018 21:07
DA UI SublimeText Theme Settings
{
"accent_color": "#00bcab",
"background_color": "#394145",
"font_face": "Segoe UI",
"tab_font_size": ["subtract", "$font_size", 1],
"show_tab_dropdown_button": false,
"panel_border_width": [0, 0, 0, 0],
"scrollbar_flavor": "square",
"sidebar_heading_font_size": ["subtract", "$font_size", 2],
window.addEventListener("mousemove", function(e) {
debounce(200, fn.bind(this,e))
});
var waitFlag = false
function debounce(time,fn) {
if (!waitFlag) {
fn()
waitFlag = true
var cnv = $('canvas')[0];
var ctx = cnv.getContext('2d');
var ratio = window.devicePixelRatio
if (ratio) {
ratio *= 1.5;
var w = $(cnv).attr('width');
var h = $(cnv).attr('height');
@onurkerimov
onurkerimov / Beautiful_GUI_Fonts.css
Last active November 4, 2018 16:38
Note to self
html {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font: 400 16px/1.5 system-ui,-apple-system,BlinkMacSystemFont,"Helvetica Neue",Helvetica,Arial,sans-serif;
text-rendering: optimizeLegibility;
}