Skip to content

Instantly share code, notes, and snippets.

@Xatenev
Xatenev / userscript.js
Created April 10, 2021 10:37
Lichess study enhancement user script
// ==UserScript==
// @name Lichess study enhancement
// @author Xatenev
// @match https://*.lichess.org/*
// ==/UserScript==
(function() {
'use strict';
console.log("Lichess study userscript loaded");
@Xatenev
Xatenev / command.bash
Created March 4, 2021 12:49
Only get non-static functions in ctags.
$ gcc -E main.c | ./filter.py > temp.c && ctags --c-types=f -x --file-scope=no temp.c
main function 25 temp.c int main(void) {
test function 17 temp.c int test() {
@Xatenev
Xatenev / 3v4l.php
Created July 15, 2019 11:33
Sqlite sample for 3v4l to demonstrate PDO problems - https://3v4l.org/TbeZc
<?php
$db = new PDO("sqlite::memory:");
$db->exec('CREATE TABLE test_table (test_column TEXT)');
$stmt = $db->prepare('INSERT INTO test_table (test_column) VALUES (?)');
$stmt->execute(array("val1"));
$stmt->execute(array("val2"));
$stmt->execute(array("val3"));
@Xatenev
Xatenev / example.txt
Created February 25, 2016 10:40
Example Problem
Input
Array1 = [1,2]
Array2 = [3,4]
Output
Array3 = [1,2,3,4]
Code
Array3 = Array1.concat(Array2);
$args = array(
'orderby' => 'title',
'order' => 'ASC',
);
$wp_query = new WP_Query($args); ?>
@Xatenev
Xatenev / index.php
Created July 15, 2015 12:53
Weird PHP stuff gg
$downloadFields = explode(',', $this->settings['download']['fields']);
$contactFields = explode(',', $this->settings['contact']['fields']);
$fields = array();
foreach($downloadFields as $field) {
$fields[] = array(
'field' => trim($field),
'type' => 'download'
);
}
foreach($contactFields as $field) {
@Xatenev
Xatenev / whoincludedthisfile.php
Created May 13, 2015 14:46
WhoIncludedThisFile
function whoIncludedThisFile() {
$bt = debug_backtrace();
$includedMe = false;
while (count($bt) > 0) {
$set = array_shift($bt);
if (
array_key_exists('function', $set) === true &&
in_array($set['function'], array('require', 'require_once', 'include', 'include_once'))
){
$includedMe = array('file'=>$set['file'], 'line'=>$set['line']);
@Xatenev
Xatenev / index.php
Created April 23, 2015 15:36
Array 1 holds keys which are allowed in Array 2.
foreach($articles->category->devices as $device) { // Iterate through all objects
foreach ($device as $key => $value) { // Iterate through all properties
if (!in_array($key, $allowedFields)) { // Find property in pre-defined array with the properties which are allowed for this object
unset($device->$key); // unset the properties which doesn't match the array
}
}
}
@Xatenev
Xatenev / typo3.rb
Created March 27, 2015 14:03
TYPO3 Cache Clear Script
set :typo3_maindir, '/html/typo3/'
set :php_cli, '/usr/local/bin/php_cli'
task :typo3_flushcache do
queue %[echo "------> TYPO3: flushing cache"];
queue %[cd #{typo3_maindir} && rm -R typo3temp/*];
queue %[
cd #{typo3_maindir} && #{php_cli} -r '
$GLOBALS["TYPO3_CONF_VARS"] = require(dirname(__FILE__)."/typo3conf/LocalConfiguration.php");
$ac = dirname(__FILE__)."/typo3conf/AdditionalConfiguration.php";
if(file_exists($ac)){
@Xatenev
Xatenev / file.js
Created March 27, 2015 14:02
jQuery Query String
(function($) {
$.QueryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}