View loadscript.js
function loadScript(url, callback) | |
{ | |
// Adding the script tag to the head as suggested before | |
var head = document.getElementsByTagName('head')[0]; | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = url; | |
// Then bind the event to the callback function. | |
// There are several events for cross browser compatibility. |
View getNumeredResources.php
<?php | |
ini_set('max_execution_time', 0); | |
set_time_limit(0); | |
for($i=0; $i<6000; $i++) { | |
file_put_contents("$i.png", file_get_contents("http://vk.com/images/stickers/$i/256.png")); | |
usleep(500000); | |
} |
View cssClassManipulations.js
function addClass(cls) { | |
this[0].classList.add(cls); | |
} | |
function removeClass(cls) { | |
this[0].classList.remove(cls); | |
} | |
function hasClass(cls) { | |
return this[0].classList.contains(cls); |
View debounceRequest.js
import _ from 'lodash' | |
export function debounceRequest({ context, cb, debounceId = 'debounceId', interval = 1000 }) { | |
const id = `__debounce__${ debounceId }__` | |
if(_.isFunction(cb)) { | |
context[id] && context[id].cancel() | |
context[id] = _.debounce(cb, interval, false) | |
context[id]() | |
} |
View submitOnEnterKeyPress.html
<input type="password" name="passwd" id="passwd" class="text" | |
onkeypress="if (event.keyCode==13) this.form.login_form.click()"> |
View Tampermonkey_add_css_style.js
GM_addStyle ( " \ | |
#SAMPLE_ID { \ | |
margin: 0; \ | |
padding: 0; \ | |
} \ | |
" ); |
View DeepDiffMapper_deep_objects_compare.js
export default class DeepDiffMapper { | |
static VALUE_CREATED = 'created' | |
static VALUE_UPDATED = 'updated' | |
static VALUE_DELETED = 'deleted' | |
static VALUE_UNCHANGED = 'unchanged' | |
static map(obj1, obj2, changedOnly = true) { |
View getFormData.php
<?php | |
// Получение данных из тела запроса | |
function getFormData($method) { | |
// GET или POST: данные возвращаем как есть | |
if ($method === 'GET') return $_GET; | |
if ($method === 'POST') return $_POST; | |
// PUT, PATCH или DELETE |
View output_inline_svg.js
/* | |
1. get inline svg element to output. | |
2. get svg source by XMLSerializer. | |
3. add name spaces of svg and xlink. | |
4. construct url data scheme of svg by encodeURIComponent method. | |
5. set this url to href attribute of some "a" element, and right click this link to download svg file. | |
*/ | |
//get svg element. | |
var svg = document.getElementById("svg"); |
View encodeSassVariable.scss
//does not work with colors containing alpha | |
@function encodecolor($string) { | |
@if type-of($string) == 'color' { | |
$hex: str-slice(ie-hex-str($string), 4); | |
$string:unquote("#{$hex}"); | |
} | |
$string: '%23' + $string; | |
@return $string; | |
} |
OlderNewer