Skip to content

Instantly share code, notes, and snippets.

@krmgns
krmgns / Default (Linux).sublime-mousemap
Last active November 2, 2019 22:12
Default (Linux).sublime-mousemap
[
// Change font size with ctrl+scroll wheel
{ "button": "scroll_down", "modifiers": ["ctrl"], "command": "null" },
{ "button": "scroll_up", "modifiers": ["ctrl"], "command": "null" }
]
@krmgns
krmgns / copy_function.php
Last active January 20, 2019 01:38
PHP: copy_function()
<?php
function copy_function($name) {
$reflection = new ReflectionFunction($name);
return function(...$arguments) use($reflection) {
return call_user_func_array([$reflection, 'invoke'], $arguments);
};
}
$fn = copy_function('is_int');
@krmgns
krmgns / Number.prototype.toNumberFormat.js
Last active February 23, 2024 01:30
PHP's number_format() implementation with JavaScript.
/**
* To number format.
* @param {Integer} decimals?
* @param {String} decimalsSeparator?
* @param {String} thousandsSeparator?
* @return {String}
* @links http://php.net/number_format, https://stackoverflow.com/q/2901102
*/
Number.prototype.toNumberFormat = function(decimals, decimalsSeparator, thousandsSeparator) {
decimalsSeparator = decimalsSeparator || '.';
@krmgns
krmgns / Element.prototype.classList.js
Last active October 28, 2020 01:25
Polyfill: Element.prototype.classList for IE8/9, Safari.
/**
* Element.prototype.classList for IE8/9, Safari.
* @author Kerem Güneş <[email protected]>
* @copyright Released under the MIT License <https://opensource.org/licenses/MIT>
* @version 1.2
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
*/
;(function() {
// Helpers.
var trim = function(s) {
@krmgns
krmgns / date_time_stuff.php
Last active March 7, 2016 13:36
Date time stuff.
<?php
function time_zone_offset_to_identifier(string $offset, int $offsetIndex = 0) {
static $timeZoneOffsets = [];
if (empty($timeZoneOffsets)) {
foreach(timezone_identifiers_list() as $timeZoneIdentifier) {
$dateTimeZone = new DateTimeZone($timeZoneIdentifier);
$dateTime = new DateTime('NOW', $dateTimeZone);
$timeZoneOffsets[$dateTimeZone->getOffset($dateTime)][] = $timeZoneIdentifier;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
Inspired GitHub Color Scheme for Sublime Text 3
Copyright 2015 Seth Lopez
Released under the MIT License <http://opensource.org/licenses/MIT>
https://github.com/sethlopezme/InspiredGitHub.tmtheme
-->
<plist version="1.0">
<dict>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
Inspired GitHub Color Scheme for Sublime Text 3
Copyright 2015 Seth Lopez
Released under the MIT License <http://opensource.org/licenses/MIT>
https://github.com/sethlopezme/InspiredGitHub.tmtheme
-->
<!--
ed6a43 > this
<?php
function trim_word_left($s, array $words) {
foreach ($words as $word) {
while (($p = mb_strpos($s, $word)) === 0) {
$s = mb_substr($s, $p + mb_strlen($word));
$s = trim($s);
}
}
return $s;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>comment</key>
<string>TODO:
• Try to improve parameters list syntax – scope numbers, ‘=’, ‘,’ and possibly be intelligent about entity ordering
• Is meta.function-call the correct scope? I've added it to my theme but by default it's not highlighted</string>
<key>fileTypes</key>
<array>
<!-- JavaScript.tmLanguage -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>comment</key>
<string>JavaScript Syntax: version 2.0</string>
<key>fileTypes</key>
<array>
<string>js</string>