Skip to content

Instantly share code, notes, and snippets.

function getCssElmClasses() {
const a = [...document.styleSheets]
.map((b) => [...b.cssRules])
.flat()
.map((b) => b instanceof CSSMediaRule ? [...b.cssRules] : [b])
.flat()
.map((b) => b.selectorText)
.filter((b) => b)
.map((b) => b.split(","))
.flat()
@pravdomil
pravdomil / Main.elm
Last active September 3, 2020 11:15
Elm for Node.js
port module Main exposing (..)
type alias Input =
{ argv : List String, stdin : String }
type alias Output =
{ code : Int, stdout : String, stderr : String }
@pravdomil
pravdomil / Process.js
Created April 9, 2020 19:49
Use micro task queue.
/*
import Elm.Kernel.Scheduler exposing (binding, succeed)
import Elm.Kernel.Utils exposing (Tuple0)
*/
function _Process_sleep(time)
{
export function app<Msg, Model>(model: Model, updateFn: (msg: Msg, model: Model) => Model) {
return (msg: Msg) => {
defer(() => {
model = updateFn(msg, model)
})
}
}
export function defer(fn: () => void): void {
Promise.resolve().then(fn)
@pravdomil
pravdomil / Learn TypeScript.md
Last active March 13, 2020 18:27
Learn all TypeScript features in 10 + 3min

Learn TypeScript

https://youtu.be/ctS2v9IBphs

//// What is TypeScript?
// ts is super set of js
// + types
// + typecheck
// + transpiler(like babel)
@pravdomil
pravdomil / elmTsRuntime.ts
Last active January 19, 2020 20:00
Elm runtime in TypeScript
export type List<A> = Array<A>
export type Maybe<A> = A | null
export type Cmd<Msg> = Maybe<(_: sendMsg<Msg>) => void>
type updateFn<Msg, Model> = (_: Msg) => (_: Model) => [Model, Cmd<Msg>]
type sendMsg<Msg> = (_: Msg) => void
export let elmTsRuntime: <Msg, Model>(_: [Model, Cmd<Msg>]) => (_: updateFn<Msg, Model>) => void
elmTsRuntime = ([model, cmd]) => update => {
const sendMsg = (msg: any) => {
@pravdomil
pravdomil / Elm.d.ts
Last active January 16, 2020 15:39
...  
declare const Elm: Elm
interface Elm {
Main: AppConstructor<unknown, { port1: SubscribePort<unknown>; port2: SendPort<unknown> }>
}
interface AppConstructor<Flags, Ports> {
init(options: { node?: HTMLElement; flags: Flags }): { ports: Ports }
}
@pravdomil
pravdomil / main.js
Created January 16, 2020 15:37
for Elm
try {
main()
} catch (e) {
document.body.textContent = ""
create(document.body, "h1", "m-3").textContent = "😔"
create(document.body, "pre", "m-3").textContent = e
throw e
}
function main() {
@pravdomil
pravdomil / createState.js
Last active November 25, 2019 11:53
you might not need redux
export function createState(reducer) {
const State = createContext([])
function getInitialState() {
return reducer(undefined, { type:"@@INIT" })
}
function StateProvider({ children }) {
return createElement(State.Provider, { value: useReducer(reducer, undefined, getInitialState), children })
}
<?php
if(get_current_user_id() == 1) {
$ids = get_all_page_ids();
foreach($ids as $id) {
$data = get_post_meta($id, 'panels_data');
if(!$data) { continue; }
$data = $data[0];
foreach($data['widgets'] as $key => $widget) {
if($widget['panels_info']['class'] == 'old_class') {
$data['widgets'][$key]['panels_info']['class'] = 'new_class';