Skip to content

Instantly share code, notes, and snippets.

View tigran-sn's full-sized avatar

Tigran Soghomonyan tigran-sn

View GitHub Profile
@tigran-sn
tigran-sn / index.html
Created April 5, 2020 14:33
Neomorphic social icons (light and dark modes)
<div class="modeSwitcher">
<input type="checkbox" id="mode" />
<label for="mode"></label>
</div>
<div class="container">
<a href="javascript:void(0)" data-network="facebook" class="icon">
<i class="fa fa-facebook"></i>
</a>
<a href="javascript:void(0)" data-network="linkedin" class="icon">
<i class="fa fa-linkedin"></i>
@tigran-sn
tigran-sn / decode.js
Created April 5, 2020 13:43
Decode function
function decode(jwt) {
const [headerB64, payloadB64] = jwt.split('.');
const headerStr = base64UrlDecode(headerB64);
const payloadStr = base64UrlDecode(payloadB64);
return {
header: JSON.parse(headerStr),
payload: JSON.parse(payloadStr)
};
}
@tigran-sn
tigran-sn / encode.js
Created April 5, 2020 13:42
Encoding function
function encode(h, p, s) {
const header = base64UrlEncode(JSON.stringify(h));
const payload = base64UrlEncode(JSON.stringify(p));
const signature = s ? base64UrlEncode(JSON.stringify(p)) : "";
return `${header}.${payload}.${signature}`;
}
@tigran-sn
tigran-sn / social-icons.markdown
Last active August 18, 2019 10:15
Social Icons
@tigran-sn
tigran-sn / contentEditableOnPasteJS.js
Created April 26, 2019 12:55
Paste only plain text (JavaScript)
function isIE(){
return ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0;
}
document.querySelector("[contenteditable]").addEventListener("paste", function (e) {
e.preventDefault();
let text = "";
if (isIE()) {
text = window.clipboardData.getData('text');
e.target.innerText += text;
} else {
@tigran-sn
tigran-sn / contentEditableOnPastejQuery.js
Last active April 26, 2019 12:55
Paste only plain text (jQuery)
function isIE(){
return ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0;
}
$("body").off("paste", "[contenteditable]").on("paste", "[contenteditable]", function(e){
e.preventDefault();
let text = "";
if (isIE()) {
text = window.clipboardData.getData("text");
e.target.innerText += text;
} else {
@tigran-sn
tigran-sn / plainTextpaste.js
Last active March 25, 2019 11:18
Past only plain text (working on IE)
function isIE(){
var ua = window.navigator.userAgent;
return ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0;
}
document.querySelector("div[contenteditable]").addEventListener("paste", function (e) {
e.preventDefault();
var text = "";
if (isIE()) {
text = window.clipboardData.getData('text');
document.querySelector("div[contenteditable]").innerText += text;
@tigran-sn
tigran-sn / Contenteditable.css
Last active February 1, 2019 11:26
Content editable element with placeholder as attribute (Bug in Firefox).
.textarea {
min-height: 30px;
border: 1px solid #d6d6d6;
position: relative;
}
.textarea__placeholder {
content: attr(data-placeholderText);
color: #d6d6d6;
pointer-events: none;
position: absolute;
@tigran-sn
tigran-sn / input.css
Created January 7, 2019 12:52
Disable input "x" (clear) icon on focus (for example for IE)
input::-ms-clear { display: none; }
/* Or */
input::-ms-clear { visibility: hidden; }
/* A hackier hack might be to use the margin-right and overflow properties */
input { margin-right: -20px; overflow: hidden }
@tigran-sn
tigran-sn / random-color.js
Created June 18, 2018 13:11
The following code will create random color codes in given format as function attribute (RGB, RGBA, HEX). Default is HEX.
// Random RGB Code Generator
function randomRGB() {
var r = Math.floor(Math.random() * 255), g = Math.floor(Math.random() * 255), b = Math.floor(Math.random() * 255);
return "rgb(" + r + ", " + g + ", " + b + ")";
}
// Random RGBA Code Generator
function randomRGBA() {
var r = Math.floor(Math.random() * 255), g = Math.floor(Math.random() * 255), b = Math.floor(Math.random() * 255), a = Math.random();
return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";