Skip to content

Instantly share code, notes, and snippets.

@pravdomil
pravdomil / chmod.php
Last active December 8, 2015 10:25
Changes permissions on files and directories
<?
header('Content-Type: text/plain');
function chmod_r($dir)
{
$dp = opendir($dir);
while($file = readdir($dp))
{
if (($file == ".") || ($file == "..")) continue;
<?php
class SiteOrigin_Widget_InlineCSS extends SiteOrigin_Widget {
function generate_and_enqueue_instance_styles($instance) {
if(empty($this->form_options)) $this->form_options = $this->initialize_form();
if(empty($instance)) return;
$instance = $this->add_defaults($this->form_options, $instance);
$css_name = $this->id_base . '-' . $this->get_style_name($instance) . '-' . $this->get_style_hash($instance);
$css = wp_cache_get($css_name, 'siteorigin_widgets');
<?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';
new class {
constructor() {
this.nodes = this.find('.position_sticky').map(el => { return { el, placeholder: null } })
window.addEventListener('scroll', e => this.go(), { passive: true })
this.go()
}
go() {
this.nodes.forEach(node => this.check(node))
}
@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 })
}
@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 / 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 / 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 / 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)