Skip to content

Instantly share code, notes, and snippets.

View Oziabr's full-sized avatar

Yury Tvardovsky Oziabr

View GitHub Profile
@Oziabr
Oziabr / htmx_pug_showcase.md
Last active August 5, 2025 07:41
htmx with pug/jade showcase (for r/htmx)

htmx with pug/jade showcase

Origin of this story is me being lazy, using JS for every practical application because it's cheap. Naturally, JS has the best template engine for the web (almost exclusively; Golang has an analog, but it’s painful to use). The beauty of Pug/Jade is its YAML-like indentation-based structure, which guarantees valid HTML output. The only way to break HTML in Pug is to render raw, unescaped output - a rare necessity if you know what you’re doing. This is what stopped me from adopting Golang’s tmpl: I never figured out how to validate templates without resorting to an overly costly e2e test suite.

Here is the essential example of how I'm using it:

@Oziabr
Oziabr / no_squat_testing.js
Created December 8, 2022 01:33
async testing with jest without extra squats
describe('sync', () => {
test('value', () => expect(100500).toBe(100500))
test('throw', () => expect(() => { throw 100500 }).toThrow('100500'))
})
describe('async', () => {
describe('.resolves', () => {
test('sleep', () => expect(
new Promise(resolve => setTimeout(() => resolve(100500), 1))
).resolves.toBe(100500))

продукты

  • вино - 5 бут
  • мясо готовое
  • мясо маринованное
  • сыр
  • крекеры
  • томаты
  • овощи-зелень
{
"data": [
{
"os_type": "mobile",
"country": "KW",
"ssp_id": 360,
"maxbid": 12.28427727968510824
}
]
}
d = { v: i for i, v in enumerate('zero one two three four five six seven eight nine ten eleven twelve thirteen'.split())}
d.update({v+'teen': i+10 for v, i in d.items() if 3 < i < 10})
d.update({'fifteen': 15, 'eighteen': 18})
d.update({v: (i+2)*10 for i, v in enumerate('twenty thirty forty fifty sixty seventy eighty ninety'.split())})
def parse_int(s):
if 'million' in s: return 1E6
s = s.replace('thousand', '|').replace('and ', '').replace('-', ' ').replace('hundred', '-')
keys =[[sum([ d[k] for k in x.strip().split()]) for x in a.split('-')[::-1]] for a in s.split('|')[::-1]]
return sum([sum([100**j*1000**i*a for j, a in enumerate(b)]) for i, b in enumerate(keys)])
@Oziabr
Oziabr / ng2-resolver.js
Created June 2, 2017 10:48
angular2 resolver helper
let resolver = (sbj, ctx = {}) => Observable.zip( ...Object.keys(sbj).map(k => sbj[k]), (...args) =>
args.reduce((r, a, n) => Object.defineProperty(r, Object.keys(sbj)[n], {value: a, enumerable: true})
, ctx))
input = [0,1,2,3,4,5,6,7,8,9]
len = 3
resort = function(input, len) {
count = len
while(count--) {
last = input.length-(len-count)
id = parseInt(Math.random()*last)
el = input[id]
input[id] = input[last]