Skip to content

Instantly share code, notes, and snippets.

View eyy's full-sized avatar

Etai Peretz eyy

  • Israel
View GitHub Profile
export function createSetter<T extends Record<string, any>>(setState : Dispatch<SetStateAction<T>>) {
return <K extends keyof T>(key : K, value : SetStateAction<T[K]>) => setState((prev : T) => ({
...prev,
[key]: tryCall(value, prev[key])
}));
}
let r = 'αβσδεφγ῾ικλμνοπρστυξυζηω'.split('').reduce((o,curr,i) => {o['abcdefghiklmnoprstuxyzēō'[i]] = curr;return o}, {})
function gr(s) { return s.replace('th','θ').replace('ch','χ').replace(/./gui, a=>r[a]||a).replace(/σ /g, 'ς ') }
// replace selected
s=window.getSelection()
t=s.toString()
p=s.focusNode.parentNode;p.innerHTML=p.innerHTML.replace(t, gr(t))
@eyy
eyy / util.styl
Created May 8, 2021 12:12
stylus utilities classes
// `.mt-10` for `margin-top: 10`, etc.
// like in bootstrap
a = { m: margin, p: padding }
b = { '': '', t: '-top', r: '-right', b: '-bottom', l: '-left' }
for x, xx in a
for y, yy in b
for n in 0 5 10 15 20
.{x}{y}-{n}
{xx}{yy}: n px
@eyy
eyy / app.js
Last active April 3, 2021 18:57
Auto reload everything: stylus, browser-sync, express, nodemon
var app = express()
// browser sync
if (app.get('env') === 'development') {
var bs = require('browser-sync')({
logSnippet: false,
files: ['pub/*.html', 'pub/css/*.css', 'views']
})
app.use(require('connect-browser-sync')(bs))
}
@eyy
eyy / media-query-mixins.styl
Created August 4, 2015 13:13
Media query mixins for Stylus
// Media query mixins
mobile()
@media (max-width: 640px)
{block}
tablet()
@media (max-width: 800px)
{block}
@eyy
eyy / drop-right.html
Created May 28, 2019 08:12
Drop-right: a simple dropdown to the right
<div>
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li>
3 +
<ul class="drop-right">
<li><a href="#">3.1</a></li>
<li><a href="#">3.2</a></li>
<li>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>GitHub Users, A Selection</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
body {
@eyy
eyy / navigation.js
Created July 3, 2013 11:04
mongoose recursive schema
schema.statics.findRecursive = function(cb) {
this.find({ show: true, menu: true })
.select('order parent url title')
.sort({ parent: -1, order: 1 })
.lean()
.exec(function(err, items) {
if (err) cb(err);
var o = {},
arr = [];
@eyy
eyy / mobile-nav.js
Created January 19, 2014 16:20
mobile navigation
/*
Mobile navigation
*/
var nav = $('nav');
nav.on('click touchstart', function(e) {
if (!$(e.target).is('.active'))
return;
e.preventDefault();
e.stopPropagation();
@eyy
eyy / easy-parallax.js
Created January 9, 2014 21:45
easy parallax
// based on http://codepen.io/zitrusfrisch/pen/bJwhk
function easyParallax() {
var scrollPos = w.scrollTop();
$('#banner').css({
'background-position' : '50% ' + (-scrollPos/4)+"px"
});
$('#bannertext').css({
'margin-top': (scrollPos/4)+"px",
'opacity': 1-(scrollPos/250)
});