Skip to content

Instantly share code, notes, and snippets.

View Aligator77's full-sized avatar

Aligator77

View GitHub Profile
@Aligator77
Aligator77 / elasticsearch.custom.sort.py
Created February 13, 2020 08:28 — forked from darklow/elasticsearch.custom.sort.py
ElasticSearch custom sort, based on provided ids array order. Original code from here: http://damienalexandre.fr/post/elasticsearch-ids-query-order Rewritten to new "function_score" syntax Note: You need to remove \n new lines from "script" field in order to get it work.
q = {
"query": {
"function_score": {
"boost_mode": "replace",
"query": {
"ids": {
"values": [
50,
80,
44,
@Aligator77
Aligator77 / jsx-dom.js
Created October 18, 2019 08:40 — forked from foxbunny/jsx-dom.js
JSX helper for creating DOM nodes
const h = (tag, attrs, ...children) => {
const elm = document.createElement(tag)
for (let key in attrs) {
if (key.slice(0, 2) == 'on') {
const evtName = key.slice(2)
const cb = attrs[key]
if (cb == null) continue // we can use null or undefnied to suppress
elm.addEventListener(evtName, cb)
} else if (['disabled', 'autocomplete', 'selected', 'checked'].indexOf(key) > -1) {
if (attrs[key]) {
@Aligator77
Aligator77 / php-excel-xlsx-xml.php
Created May 23, 2019 11:03 — forked from kasparsd/php-excel-xlsx-xml.php
Generate the most basic Excel XLSX and XML files in PHP, see https://kaspars.net/blog/wordpress/excel-xlsx-xml-php
<?php
// Note: there are some references to WordPress methods and functions
class cf7_export_excel {
protected $doc_prop = array(
'Author' => 'Name',
'Company' => 'Company',
'Created' => '',
@Aligator77
Aligator77 / gist:cc1368e95f046babb2ee23e8fc24d2e6
Created May 17, 2019 12:35 — forked from kurisuchan/gist:1262135
Moving MySQL databases to ramdisk on Ubuntu
# Tweaked from http://tomislavsantek.iz.hr/2011/03/moving-mysql-databases-to-ramdisk-in-ubuntu-linux
# Log in as root
# Mount ramdisk folder in RAM
mkdir /tmp/ramdisk
mount -t tmpfs -o size=128M tmpfs /tmp/ramdisk/
# Move MySQL data
mv /var/lib/mysql /tmp/ramdisk/mysql
ln -s /tmp/ramdisk/mysql/ /var/lib/mysql
@Aligator77
Aligator77 / wordpress-tinymce.js
Created July 6, 2018 12:07 — forked from RadGH/wordpress-tinymce.js
Get/Set content of a TinyMCE visual or text editor with JavaScript
/*
Based on: http://wordpress.stackexchange.com/questions/42652/#answer-42729
These functions provide a simple way to interact with TinyMCE (wp_editor) visual editor.
This is the same thing that WordPress does, but a tad more intuitive.
Additionally, this works for any editor - not just the "content" editor.
Usage:
@Aligator77
Aligator77 / add-wordpress-settings-page.php
Created July 6, 2018 12:07 — forked from DavidWells/add-wordpress-settings-page.php
WordPress :: Add Settings Page with All Fields
<?php
/*
Plugin Name: Homepage Settings for BigBang
Plugin URI: http://www.inboundnow.com/
Description: Adds additional functionality to the big bang theme.
Author: David Wells
Author URI: http://www.inboundnow.com
*/
// Specify Hooks/Filters
@Aligator77
Aligator77 / youtube-plater.js
Created June 20, 2018 11:55 — forked from vsko/youtube-plater.js
Управление видео на Youtube через iframe
// iframe
var youtubePlayer = document.getElementsByClassName('youtube-player')[0];
// play
youtubePlayer.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
// pause
youtubePlayer.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
// stop
@Aligator77
Aligator77 / virtualenv_execute.py
Created February 14, 2018 22:19 — forked from turicas/virtualenv_execute.py
Execute Python code in a virtualenv, return its stdout and stderr
#!/usr/bin/env python
# coding: utf-8
import os
import shlex
from subprocess import Popen, PIPE
def execute_in_virtualenv(virtualenv_name, commands):
'''Execute Python code in a virtualenv, return its stdout and stderr.'''
@Aligator77
Aligator77 / nginx.conf
Created November 21, 2017 23:36 — forked from jrom/nginx.conf
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";