Skip to content

Instantly share code, notes, and snippets.

View danielhaim1's full-sized avatar

Daniel Haim danielhaim1

View GitHub Profile
@danielhaim1
danielhaim1 / getNaturalDimensions.js
Created November 15, 2022 13:14
Return the natural dimensions of an image.
/**
* Return the natural dimensions of an image.
* @string img - The image to get the dimensions of.
* @return {object} - The natural width of the image.
* @return {null} - If the image has no natural dimensions.
*/
function getNaturalDimensions({ naturalWidth, naturalHeight }) {
// get the image format from the src attribute.
let width = naturalWidth;
@danielhaim1
danielhaim1 / README.md
Last active November 15, 2022 13:54
Return a slugified version of the string with the specified separator.

Slugify

This script takes a string in different languages and returns a slugified version of it.

It is used to generate slugs for the blog posts, and is also used to generate the slugs for ids from the headings in the blog posts.

Language Support:

German, Danish, Dutch, Finnish, French, Hungarian, Italian, Norwegian, Portuguese, Romanian, Russian, Spanish, Swedish, Turkish, Greek, Bulgarian, Serbian, Croatian, Czech, Polish, Slovak, Slovenian, Latvian, Lithuanian, Estonian, Persian, Arabic, Hebrew, Hindi, Thai, Chinese, Japanese, Korean, Vietnamese, and Ukrainian, as well as Emoji

Slugify as Heading Attribute

@danielhaim1
danielhaim1 / scrapeExport.md
Last active January 25, 2023 11:21
Scraping HTML List & Export to Excel

Scrape List w/ Pagination with Export to Excel

Example HTML

<ul class="list">
    <li class="list-item">
        <a class="list-item__username" href="/profile/john-doe">John Doe</a>
        <div class="list-item__comment">...</div>
    </li>
    <li class="list-item">
@danielhaim1
danielhaim1 / detectie.js
Last active January 11, 2019 10:22
Returns version of IE or false, if browser is not Internet Explorer
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
@danielhaim1
danielhaim1 / PubMaticCollapse.html
Created November 26, 2018 12:04
Programmatically collapse PubMatic space in empty div if no ads are inside
<script type="text/javascript">
// Site Data
var pubId=;
var siteId=;
var kadId=;
var kadwidth=;
var kadheight=;
var kadtype=1;
var kadpageurl= "";
@danielhaim1
danielhaim1 / README.md
Last active November 6, 2022 13:50
Return numbers in human readable format according to the Metric (SI) Prefixes

Human Readable Numbers

Return numbers in human readable format according to the Metric (SI) Prefixes

SI Prefixes

// convert an integer to a string with a metric (IS) prefix + suffix
function convertToMetric(number) {
    const x = ['', 'k', 'M', 'B', 'T', 'P', 'E']
    const tier = Math.log10(number) / 3 | 0;
    if (tier == 0) return number;
    const prefix = x[tier];
@danielhaim1
danielhaim1 / integers.json
Last active March 5, 2018 22:50
Jekyll page.variables as operator in conditional statements w/ JSON
### data/integers.json
{
"100": { "value": true }
}
@danielhaim1
danielhaim1 / find-unused-sass-variables.sh
Last active March 19, 2023 22:25
This script searches for unused Sass variables in a given directory by finding occurrences and counting them. Could benefit from optimization.
#!/bin/bash
# Usage: ./unused.sh
read -p "Enter a directory: " dir
if [ ! -d "$dir" ]; then
echo "Not a valid directory."
exit 1
fi
@danielhaim1
danielhaim1 / autoappender.php
Created July 20, 2017 13:57
Auto Appender & Nav Builder
<?php
// The PHP version of AutoAppender.js,
// @author Daniel Haim
// @url https://codepen.io/danielhaim1/pen/pwXJLp?editors=1010
class Page {
public $header = array();
public $sections = array();
@danielhaim1
danielhaim1 / responsive-layouts.scss
Created May 29, 2017 22:23
Responsive Margin & Padding Shortcuts
// Margin and Padding
@each $breakpoint in map-keys($grid-breakpoints) {
@include media-breakpoint-up($breakpoint) {
$infix: breakpoint-infix($breakpoint, $grid-breakpoints);
@each $prop, $abbrev in (margin: m, padding: p) {
@each $size, $lengths in $spacers {
$length-x: map-get($lengths, x);
$length-y: map-get($lengths, y);