Skip to content

Instantly share code, notes, and snippets.

View awps's full-sized avatar
🎯
Focusing

Andrei Surdu awps

🎯
Focusing
View GitHub Profile
@awps
awps / anyToArray.ts
Last active June 6, 2022 09:40
Convert any value to array. Typescript
export const anyToArray = (value: any) => {
if (!value){
return [];
}
if (Array.isArray(value)){
return [...value];
}
if (typeof value === 'object'){
@awps
awps / pixelToPercent.tsx
Created August 9, 2022 14:19
Pixel to Percent TypeScript/Javascript
export const pixelToPercent = (pixelNumber: number, containerSize: number) => {
const percent = 100 / containerSize * pixelNumber;
if (percent > 100) {
return 100;
} else if (percent < 0) {
return 0;
}
return Math.round((percent + Number.EPSILON) * 100) / 100;
@awps
awps / sassas.md
Last active February 14, 2023 09:11 — forked from AdamMarsden/sassas.md
Sass Architecture Structure

Sass Architecture Structure

sass/
|
|– base/
|   |– _reset.scss       # Reset/normalize
|   |– _typography.scss  # Typography rules
|   ...                  # Etc…
|
@awps
awps / get_page_by_title_wp_query.php
Created June 25, 2023 23:39
Alternative to the deprecated `get_page_by_title`, using WP_Query
<?php
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query(
array(
'post_type' => $post_type,
'title' => $page_title,
'post_status' => 'all',
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,