Skip to content

Instantly share code, notes, and snippets.

View pointofpresence's full-sized avatar
🏠
Working from home

ReSampled pointofpresence

🏠
Working from home
View GitHub Profile
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.
<?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);
}
@pointofpresence
pointofpresence / cssClassManipulations.js
Last active September 27, 2019 08:28
CSS class functions
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);
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]()
}
@pointofpresence
pointofpresence / submitOnEnterKeyPress.html
Last active September 27, 2019 15:17
Created with Copy to Gist
<input type="password" name="passwd" id="passwd" class="text"
onkeypress="if (event.keyCode==13) this.form.login_form.click()">
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) {
@pointofpresence
pointofpresence / getFormData.php
Last active March 31, 2024 11:45
Как получить данные из тела запроса PUT, PATCH или DELETE?
<?php
// Получение данных из тела запроса
function getFormData($method) { 
    // GET или POST: данные возвращаем как есть
    if ($method === 'GET') return $_GET;
    if ($method === 'POST') return $_POST;
 
    // PUT, PATCH или DELETE
    $data = array();
/*
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");
@pointofpresence
pointofpresence / encodeSassVariable.scss
Last active December 27, 2019 09:33
encode sass variable
//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;
}
@pointofpresence
pointofpresence / sassColorToCssVariable.scss
Last active December 27, 2019 09:35
sass color to css variable
@function color($color-name) {
@return var(--color-#{$color-name});
}