Skip to content

Instantly share code, notes, and snippets.

@himalay
himalay / dom.js
Created August 3, 2017 14:43
Useful DOM methods
tinyurl.com/domfitc
//// Insert elements
el.insertAdjacentHTML(<location>, <HTML string>);
// locations
<!-- beforebegin -->
<div>
<!-- afterbegin -->
<p>some text</p>
var array = [1,2,3,4,5,6]; console.log(array.slice(-1)); // [6] console.log(array.slice(-2)); // [5,6] console.log(array.slice(-3)); // [4,5,6]
var array = [1,2,3,4,5,6]; console.log(array.length); // 6
array.length = 3; console.log(array.length); // 3 console.log(array); // [1,2,3]
Array.push.apply(arr1, arr2) which instead creates a new array – it will merge the second array in the first one reducing the memory usage.
var array1 = [1,2,3]; var array2 = [4,5,6]; console.log(array1.push.apply(array1, array2)); // [1,2,3,4,5,6];
NodeList to Array
var ps=document.querySelectorAll("p");
var solidus = { long: '̸', short: '̷' }
var stroke = { long: '̶', short: '̵' }
function strikeThrough(str, bar) {
return str.replace(/(\w)/g, '$1' + bar)
}
var a = '̴'
var underline = '͟'
function inKB(s) {
s = (new TextEncoder('utf-8').encode(s)).length / 1024
return s.toFixed(2)
}
@himalay
himalay / reset.css
Last active January 30, 2020 07:09
CSS mini reset
/* CSS Mini Reset */
html, body, div, form, fieldset, legend, label
{
margin: 0;
padding: 0;
}
table
{
@himalay
himalay / print.css
Last active January 30, 2020 07:10
CSS print framework
/* --------------------------------------------------------------
Hartija Css Print Framework
* Version: 0.8 (2008-03-10)
-------------------------------------------------------------- */
body {
width:100% !important;
margin:0 !important;
@himalay
himalay / oneliners.css
Last active January 30, 2020 07:10
css oneliners
/* reset */
* {margin: 0;padding: 0;box-sizing: border-box;}
/* css grid */
.dp50 {width:50%; float:left; display: inline; *margin-right:-1px; }
/* two line css grid http://www.vcarrer.com/2010/10/two-lines-css-framework.html */
.row { display:table; width:960px; margin:0 auto }
.cell { display:table-cell; vertical-align:top; padding-left:10px }
@himalay
himalay / bem.css
Last active January 30, 2020 07:10
BEM CSS
/*-------------------------------------
BEM (Block Element Modifier)
-------------------------------------*/
/*
<a href="http://css-tricks.com" class="btn btn--green btn--big">
<span class="btn__price">$9</span>
<span class="btn__text">Big button</span>
</a>
*/
@himalay
himalay / coercion.js
Created August 3, 2017 14:24
Coercion in JavaScript
function isNeg0 (n) {
return n===0 && (1/n)===-Infinity
}
if (!Number.isNaN) Number.isNaN = num => num !== num
// best way to do it in es6+
Object.is(0, -0)// false
Object.is(NaN, NaN)// true
var a = [1,5,3,4,8]
@himalay
himalay / compare.ps1
Created August 3, 2017 14:23
compare two folders' files in powershell
$folder1 = "C:\Users\himalay\projects\test\test1"
$folder2 = "C:\Users\himalay\projects\test\test2"
$firstFolder = Get-ChildItem -Recurse $folder1 | Where-Object { -not $_.PsIsContainer }
$firstFolder | ForEach-Object {
$secondFile = $_.FullName.Replace($folder1, $folder2)
If ( Test-Path $secondFile ) {
If ( (Get-FileHash $_.FullName).hash -eq (Get-FileHash $secondFile).hash ) {