Skip to content

Instantly share code, notes, and snippets.

@meoyawn
meoyawn / xml.kt
Last active February 29, 2024 16:17
fast XML DSL in 70 lines
package lib.xml
import org.apache.commons.text.StringEscapeUtils
fun StringBuilder.put(attrs: Array<out Pair<String, Any?>>) {
for ((k, v) in attrs) {
if (v == null) continue
append(' ')
append(k)
/*
MIT License
Copyright (c) 2015 Adel Nizamutdinov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
const productContainer = document.querySelector('div[data-qa-locator="general-products"]');
const sortedEls = Array.from(productContainer.children)
.flatMap(product => {
const salesInfo = product.querySelector('._1cEkb');
if (!salesInfo) return [];
const salesText = salesInfo.innerText;
const [soldStr] = salesText.split(' ')
const salesCount = parseInt(soldStr.replace(",", ""));
@meoyawn
meoyawn / EmptyRecyclerView.java
Created November 1, 2014 11:20
RecyclerView doesn't have an emptyView support, we gotta fix that
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EmptyRecyclerView extends RecyclerView {
@Nullable View emptyView;
@meoyawn
meoyawn / Makefile
Created April 8, 2022 14:12
generate TS client
DIR:=gen/
openapi:
rm -rf $(DIR)
openapi-generator generate -g typescript-fetch -i http://localhost:8080/openapi.json -o $(DIR) --remove-operation-id-prefix --additional-properties=typescriptThreePlus=true,modelPropertyNaming=original,nullSafeAdditionalProps=true,enumPropertyNaming=original,supportsES6=true,useSingleRequestParameter=false
grep -rl "? undefined" $(DIR) | xargs sed -i '' 's/? undefined/? null/g'
@meoyawn
meoyawn / pyproject.toml
Created July 30, 2020 13:02
gpt-2 dependencies
[tool.poetry]
version = "1.0.0"
name = "gpt-2"
description = ""
authors = []
[tool.poetry.dependencies]
fire = "^0.1.3"
regex = "2017.4.5"
requests = "2.21.0"
@meoyawn
meoyawn / yarn.sh
Created July 24, 2020 17:43
update package.json using yarn
jq '.dependencies | keys | .[]' package.json | xargs yarn add
jq '.devDependencies | keys | .[]' package.json | xargs yarn add --dev
! 2/5/2020 https://twitter.com
twitter.com##div[aria-label$="Your Home Timeline"]
twitter.com##div[aria-label$="Trending now"]
twitter.com##aside[aria-label$="Who to follow"]
twitter.com##a[aria-label^="Home"]
twitter.com##a[aria-label$="explore"]
twitter.com##a[aria-label^="Notifications"]
twitter.com##a[aria-label^="Bookmarks"]
twitter.com##a[aria-label^="Lists"]
twitter.com##a[aria-label^="Profile"]
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.time.delay
import mu.KotlinLogging
import java.time.Duration
private val log = KotlinLogging.logger { }
data class PeriodicJob(
@meoyawn
meoyawn / cli.kt
Last active October 28, 2019 07:33
Calling CLI tools using kotlin coroutines with cancellation support
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import java.io.StringWriter
sealed class Cli {
data class Ok(val stdout: String) : Cli()
data class Err(val stderr: String) : Cli()