Skip to content

Instantly share code, notes, and snippets.

View neomen's full-sized avatar
🤪

Yaroslav neomen

🤪
View GitHub Profile
@neomen
neomen / function.php
Created January 12, 2022 03:20
URL prefix for default posts at WordPress
function add_rewrite_rules( $wp_rewrite ) {
$new_rules = array(
'blog/(.+?)?$' => 'index.php?post_type=post&name=' . $wp_rewrite->preg_index(1),
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', 'add_rewrite_rules');
function change_blog_links($post_link, $id=0) {
$post = get_post($id);
@neomen
neomen / handler.go
Created September 14, 2021 05:27 — forked from rjz/handler.go
Handle Github webhooks with golang
// Now available in package form at https://github.com/rjz/githubhook
package handler
// https://developer.github.com/webhooks/
import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"errors"
@neomen
neomen / httpStore.js
Created May 24, 2021 18:09 — forked from joshnuss/httpStore.js
A Svelte store backed by HTTP
import { writable } from 'svelte/store'
// returns a store with HTTP access functions for get, post, patch, delete
// anytime an HTTP request is made, the store is updated and all subscribers are notified.
export default function(initial) {
// create the underlying store
const store = writable(initial)
// define a request function that will do `fetch` and update store when request finishes
store.request = async (method, url, params=null) => {
@neomen
neomen / wmtt.sh
Created April 5, 2021 17:41 — forked from lanrat/wmtt.sh
run nested window-manager
#!/usr/bin/env bash
# wmtt: wm testing tool
# built from the awmtt script
#Default Variables
#TODO make this arg passable
WM="openbox-session"
ME=$(basename ${0})
# Display and window size
D=1
@neomen
neomen / PhpArrayToYaml.php
Created August 13, 2020 03:00 — forked from ArnaudLigny/array2yaml.php
Convert PHP array to YAML
#!/usr/local/bin/php
<?php
if (php_sapi_name() !== 'cli') {
return;
}
date_default_timezone_set('Europe/Paris');
require_once 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
try {
function array2csv($data, $delimiter = ',', $enclosure = '"', $escape_char = "\\"){
$f = fopen('php://memory', 'r+');
foreach ($data as $item) {
fputcsv($f, $item, $delimiter, $enclosure, $escape_char);
}
rewind($f);
return stream_get_contents($f);
}
$list = array (
@neomen
neomen / nl2p.php
Last active April 24, 2019 09:42
simple text 2 html test
<?php
function nl2p($string) {
$paragraphs = '';
foreach (explode("\n\n", $string) as $line) {
if (trim($line)) {
$paragraphs .= '<p>' . trim($line) . '</p>';
}
}
return nl2br($paragraphs);
}
@neomen
neomen / manual-gravity-forms
Created February 27, 2019 09:59 — forked from keithdevon/manual-gravity-forms
Manually create entries and send notifications with Gravity Forms
<?php
// Manually create entries and send notifications with Gravity Forms
$form_id = 10;
// add entry
$entry = array(
"form_id" => $form_id,
"1" => "Entry for field ID 1",
@neomen
neomen / convert.sh
Last active December 18, 2018 10:50
convert images
mkdir jpg1
convert "*-cabinet-*.png[580x]" -set filename:base "%[base]" -quality 90 -format jpg -background white -alpha remove "jpg1/%[filename:base].jpg"
convert "*-shell-*.png[580x]" -set filename:base "%[base]" -background white "jpg1/%[filename:base].png"
@neomen
neomen / wp-query-ref.php
Created November 27, 2018 03:28 — forked from luetkemj/wp-query-ref.php
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/