Skip to content

Instantly share code, notes, and snippets.

View anova's full-sized avatar

Necat Bolpaça anova

View GitHub Profile
@anova
anova / gulpfile-sass-and-pot.js
Created September 8, 2020 14:58
gulp-pot and gulp-sass
'use strict';
const { series, src, watch, dest } = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
sass.compiler = require('dart-sass');
const wpPot = require('gulp-wp-pot');
const sass_src = 'wp-content/themes/theme-name/scss/**/{*.scss,_*.scss}';
const sass_dest = 'wp-content/themes/theme-name/';
@anova
anova / csv-to-json.js
Created August 24, 2020 11:33
Basic csv to json convert with fetch, forEach
const SEARCH_DATA = `path/to/csv-file.csv`;
const Search = {
SEPARATOR_LINE: '\n',
SEPARATOR_COLUMN: ';',
jsonData: [],
initialize: () => {
fetch(SEARCH_DATA)
.then(response => response.text())
.then(data => {
//console.log(data);
@anova
anova / reducer-for-unique-values-es5.js
Created August 6, 2020 07:29
reducer for unique values (ES5)
function uniqueValues(accumulator, currentValue) {
return accumulator.indexOf(currentValue) < 0 ? accumulator.concat(currentValue) : accumulator;
}
//Example:
//[11,22,33,11,33,55].reduce(uniqueValues, []);
// -> Output: [11,22,33,55]
@anova
anova / gulpfile.js
Created July 25, 2020 16:40
gulpfile.js example for sass and autoprefixer. (I preferred dart-sass it is slower, but node-sass require lot of rebuilds)
'use strict';
const { series, src, watch, dest } = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
sass.compiler = require('dart-sass');
const sass_src = 'wp-content/themes/example-theme/sass/**/{*.scss,_*.scss}';
const sass_dest = 'wp-content/themes/example-theme/';
@anova
anova / asana-collapse-all-projects-bookmarklet.html
Last active July 8, 2020 11:07
When you look My Tasks sort by projects, all projects expanded. This bookmarklet can collapse all project with one click.
<a href="javascript:(function(){document.querySelectorAll('.TaskGroupHeader-toggleButton .DownTriangleIcon').forEach(function(element){ element.parentNode.click() })}());">Asana: Collapse All Projects</a>
@anova
anova / extract-youtube-block-gutenberg.php
Created April 29, 2020 08:18
(Wordpress gutenberg) Extracts youtube block metadata from the_content
<?php
// $yt_block_code = extract_youtube_block_gutenberg( get_the_content() );
function extract_youtube_block_gutenberg( $the_content ) {
$yt_begin_phrase = 'wp:core-embed/youtube';
if( strpos ($the_content, $yt_begin_phrase ) === false ){
return null;
}
$yt_embed_begin = strpos( $the_content, $yt_begin_phrase ) + strlen( $yt_begin_phrase );
$yt_embed_end = strpos( $the_content, '-->' );
$yt_block_code = json_decode(trim(substr( $the_content, $yt_embed_begin, $yt_embed_end - $yt_embed_begin )));
@anova
anova / wp-auto-cache-bust.php
Created April 16, 2020 20:06
auto cache bust functions for wordpress
<?php
// auto cache bust (style)
function acb_style( $name, $css, $deps = [] ) {
wp_enqueue_style( $name, get_template_directory_uri() . $css, $deps, filemtime( get_template_directory() . $css ) );
}
// auto cache bust (script)
function acb_script( $name, $js, $deps = [], $in_footer = false ) {
if( $in_footer ):
wp_enqueue_script( $name, get_template_directory_uri() . $js, $deps, filemtime( get_template_directory() . $js ), $in_footer );
@anova
anova / inject-style-and-html.js
Created April 3, 2020 08:00
Add some additional css and html on runtime. (I am using this method for landing pages)
(function () {
const base_path = 'https://example.com/base/path/';
function addStyle(name) {
const path = base_path + 'css/' + name + '?v=' + Date.now();
const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = path;
document.head.appendChild(link);
}
@anova
anova / jquery-ajax-json-request.js
Created March 26, 2020 20:38
Ajax request with json serialized data (.net service with object parameter serialization) needs contentType set to application/json
$.ajax({
'method': 'POST',
'url': '/path/to/api',
'dataType': 'json',
'contentType': 'application/json; charset=UTF-8',
'data': JSON.stringify({
"key": false
"key2": 'value',
"key3": 42
})
@anova
anova / bootstrap-padding-utility.scss
Last active May 28, 2022 23:13
Bootstrap has this padding values: (1 -> 0.25rem, 2 -> 0.5rem, 3 -> 1rem, 4 -> 1.5rem, 5 -> 3rem) I need some extra values, and wrote a sass loop for it. Generated by SassMeister.com.
// ----
// dart-sass (v1.18.0)
// ----
$breakpoints: (
"sm": 576px,
"md": 768px,
"lg": 992px,
"xl": 1200px
);