Skip to content

Instantly share code, notes, and snippets.

View kosmiq's full-sized avatar

Tor Raswill kosmiq

  • KPMG Sweden Lighthouse
  • Sweden
View GitHub Profile
@kosmiq
kosmiq / cleanRawFiles.ps1
Last active January 15, 2024 21:39
PowerShell script for moving RAW-files with no accompanying JPG-files
# Simple PowerShell script to iterate files in a folder, look for the defined RAW-file extension and see if it has an accompanying .JPG-file
# If it does not, move it into the "clean"-folder
# Create folder selector
Add-Type -AssemblyName System.Windows.Forms
$browser = New-Object System.Windows.Forms.FolderBrowserDialog
$null = $browser.ShowDialog()
# Store selected path in var
$path = $browser.SelectedPath
@kosmiq
kosmiq / App.tsx
Last active December 12, 2022 13:51
MSALAuthWithProviderForGraph
import React from 'react';
import { Providers, ProviderState, SimpleProvider } from '@microsoft/mgt-element';
import { acquireGraphAccessToken } from 'authConfig';
import { authProvider } from 'index';
const provider = new SimpleProvider(() => acquireGraphAccessToken(authProvider));
Providers.globalProvider = provider;
Providers.globalProvider.setState(ProviderState.SignedIn);
@kosmiq
kosmiq / cloudSettings
Last active December 22, 2020 09:00
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-12-22T08:42:40.120Z","extensionVersion":"v3.4.3"}
@kosmiq
kosmiq / assets.php
Last active August 19, 2016 06:42
Roots Sage 8.4.2 PHP 5.3 assets loader
<?php
/**
* Roots Sage 8.4.2 Assets loader for PHP 5.3 in the off case that you have to be compatible with such old versions.
* Remember to replace [] arrays with array() in other files. And change short echo <?= to <?php echo.
* Other than that Sage is compatible with PHP 5.3
*/
namespace Roots\Sage\Assets;
/**
* Get paths for assets
@kosmiq
kosmiq / vc_filters.php
Created August 18, 2016 09:55
Visual Composer default to md columns instead of sm columns
/**
* An ugly hack to change Visual Composer default columns output to md instead of sm. Changes ALL of them so be careful.
* Still a better way than using the custom design options in Visual Composer that outputs a large, un-minified, custom-styles even if you only change the mobile breakpoint.
*/
add_filter( 'vc_shortcodes_css_class', 'custom_css_classes_for_vc_row_and_vc_column', 10, 2 );
function custom_css_classes_for_vc_row_and_vc_column( $class_string, $tag ) {
if ( $tag == 'vc_column' || $tag == 'vc_column_inner' ) {
$class_string = preg_replace( '/vc_col-sm-(\d{1,2})/', 'vc_col-md-$1', $class_string ); // This will replace "vc_col-sm-%" with "vc_col-md-%"
}
return $class_string; // Important: you should always return modified or original $class_string
@kosmiq
kosmiq / functions.php
Created October 27, 2015 22:54
WooCommerce force order_comments if product in cart has category
/*
* Tvinga order_comments om en produkt finns i korgen som har "ticket" som kategori. Annars släpp förbi utan information.
*/
add_action('woocommerce_checkout_process', 'order_notes_if_ticket');
function order_notes_if_ticket( $order_id ){
global $woocommerce;
//$categories[];
foreach ($woocommerce->cart->cart_contents as $key => $values ) {
$terms = wp_get_post_terms( $values['product_id'], 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
@kosmiq
kosmiq / functions.php
Last active October 29, 2018 10:04
Add custom checkout fields, validate if payment method cheque is selected. Validate organisational numbers.
// Remove if you're not checking the input in org_number
include_once( get_stylesheet_directory() . '/pnum.php'); // get from: https://github.com/gurre/php-personnummer/blob/master/pnum.php
add_action( 'woocommerce_after_checkout_billing_form', 'cheque_custom_checkout_field' );
function cheque_custom_checkout_field( $checkout ) {
echo '<div id="cheque_custom_checkout_field"><h3>' . __('Fakturauppgifter') . '</h3>';
woocommerce_form_field( 'org_number', array(
'type' => 'text',
'class' => array('org-number-field my-field-class form-row form-row-wide'),
'label' => __('Organisationsnummer'),
@kosmiq
kosmiq / isotope.filter.js
Created September 30, 2015 10:52
Use a text field to filter Isotope items based on whatever is in their "data-category" attribute.
$( function() {
// quick search regex
var qsRegex;
// init Isotope
var $grid = $('.grid').isotope({
itemSelector: '.element-item',
layoutMode: 'fitRows',
filter: function() {
return qsRegex ? $(this).data("category").match( qsRegex ) : true;
jQuery(document).ready(function($) {
var formfield = null;
$('#upload_image_button').click(function() {
$('html').addClass('Image');
formfield = $(this).prev('input').attr('name');
formfield_id = $(this).prev('input').attr('id');
tb_show( '', 'media-upload.php?type=image&TB_iframe=true' );
return false;
});
@kosmiq
kosmiq / functions.php
Created April 23, 2015 08:39
WordPress featured image in RSS feed
// Add to functions.php or wherever you extend your functionality.
function featuredtoRSS($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => '' ) ) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');