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
@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);
<?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);
}
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.
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()">
/*
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});
}
@pointofpresence
pointofpresence / cookieLib.js
Last active December 28, 2019 10:15
get / set / erase cookies
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
@pointofpresence
pointofpresence / cookieLib_ES6.js
Created December 28, 2019 10:29
get / set / erase cookies (ES6)
export function setCookie(name, value, days) {
let expires = ''
if(days) {
const date = new Date()
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
expires = '; expires=' + date.toUTCString()
}