Skip to content

Instantly share code, notes, and snippets.

@qazd
qazd / Vector2.js
Last active September 25, 2023 13:14 — forked from Dalimil/Vector2.js
Basic Vector2 JavaScript Math Helper Class
class Vector2 {
x = 0;
y = 0;
constructor(x, y) {
this.set(x, y);
}
set(x, y) {
this.x = x || 0;
@qazd
qazd / UStringToHex.php
Last active July 9, 2018 16:49
Converts each character of a text string to its hexadecimal representation from the Unicode code table. Forms a sequence delimited by space. Speed and efficiency were not tested.
<?php
$string = 'è Ё𐐷-Xπ 🤔';
foreach (preg_split('//u', $string) as $char) {
if (!$char) continue;
$hex = base_convert(mb_ord($char, 'UTF-8'), 10, 16);
$pad = strlen($hex) > 4 ? 8 : 4;
$hex = str_pad($hex, $pad, '0', STR_PAD_LEFT);
@qazd
qazd / event-listeners.js
Last active June 20, 2018 09:20 — forked from danburzo/README.md
Get all event listeners on the page in Google Chrome
var items = Array.prototype.slice.call(
document.querySelectorAll('*')
).map(function(element) {
var listeners = getEventListeners(element);
return {
element: element,
listeners: Object.keys(listeners).sort().map(function(k) {
return { event: k, listeners: listeners[k] };
})
};
var horizonalLinePlugin = {
afterDraw: function(chartInstance) {
var yScale = chartInstance.scales["y-axis-0"];
var canvas = chartInstance.chart;
var ctx = canvas.ctx;
var index;
var line;
var style;
if (chartInstance.options.horizontalLine) {
@qazd
qazd / Remove 4 byte characters.php
Created December 17, 2016 05:11
Removes unicode characters with length larger than 3 bytes from string
<?php
$string = '🤔 THINKING 🤔 FACE 🤔';
$string = preg_replace_callback('/./u', function (array $match) {
return strlen($match[0]) > 3 ? null : $match[0];
}, $string);
@qazd
qazd / CellFeedInsert.php
Created December 13, 2016 09:01
Google Spreadsheet cell inserting memory overhead fix.
<?php
namespace Google\Spreadsheet;
use Google\Spreadsheet\CellFeed;
use Google\Spreadsheet\Worksheet;
/**
* Insert data to sheet without loading sheet's content to memory
* Work only with data you want to add to sheet.