Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
forsvunnet / bankid.tampermonkey.js
Last active August 3, 2020 14:42
Bank ID userscript
// ==UserScript==
// @name Bank ID
// @namespace http://tampermonkey.net/
// @version 0.1
// @description no more username pass for bankid
// @author eivin
// @match https://csfe.bankid.no/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant none
// ==/UserScript==
@forsvunnet
forsvunnet / woocommerce-checkout-customizer.php
Created November 27, 2019 14:54
Custom text field in woocommerce checkout customizer
<?php
/**
* Add our Customizer content
*/
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->add_setting( 'delivery_address_text',
array(
'default' => 'By default we deliver the products to the billing address. If you want the shipment delivered on a different location please select this option:', // Optional.
'type' => 'theme_mod',
)
@forsvunnet
forsvunnet / backtracer.php
Created October 3, 2019 09:11
Backtracer - simple debug backtrace without risk of recursion
<?php
if ( ! function_exists( 'backtracer' ) ) {
function backtracer( $die = true ) {
$db = debug_backtrace();
echo '<pre>';
foreach ( $db as $record ) {
echo "{$record['file']}:{$record['line']}\n";
}
echo '</pre>';
@forsvunnet
forsvunnet / hash-deleter.php
Last active October 2, 2019 08:05
Delete files that are from a specific commit
<?php
function rglob($pattern, $flags = 0) {
// https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
}
return $files;
}
@forsvunnet
forsvunnet / bring-shipping-class-filter.php
Created September 17, 2019 07:35
Black list shipping classes for bring shipping rates
<?php
/**
* Filter the bring shipping rates.
*/
add_filter('bring_shipping_rates', function( $rates ) {
$shipping_classes = [
'halvpall',
'pall',
'stein',
'uuni-shipping',
@forsvunnet
forsvunnet / simple-debug-backtrace.php
Created September 4, 2019 14:22
Simple debug backtrace
<?php
echo'<ul>';
$db = debug_backtrace();
foreach ($db as $r) {
echo "<li>{$r['file']}:{$r['line']}</li>";
}
die;
@forsvunnet
forsvunnet / create-attribute.php
Created September 4, 2019 11:54
Create a WooCommerce product attribute programatically
<?php
// return;
add_action('init', function() {
$attribute_name = 'New a';
$attribute_id = 'new_a';//wc_attribute_taxonomy_id_by_name($attribute_name);
$attribute_slug = wc_attribute_taxonomy_name($attribute_id);//wc_attribute_taxonomy_id_by_name($attribute_name);
/*
* @type int $id Unique identifier, used to update an attribute.
* @type string $name Attribute name. Always required.
* @type string $slug Attribute alphanumeric identifier.
@forsvunnet
forsvunnet / Leaderboard.pde
Last active June 24, 2019 21:31
Processing leaderboard
import processing.serial.*;
Serial myPort;
ArrayList<Integer>[] lapTimes = new ArrayList[2];
void setup() {
lapTimes[0] = new ArrayList<Integer>();
lapTimes[1] = new ArrayList<Integer>();
myPort = new Serial(this, "/dev/tty.wchusbserial1410", 9600);
@forsvunnet
forsvunnet / scroll-animation.js
Created June 24, 2019 07:20
Add classes to elements on scroll when they are in view
var suffix = '-x';
var windowHeight;
var products = $('.animate' + suffix);
products.addClass('animate' + suffix);
var checkPosition = function () {
products.each(function() {
var elem = $(this);
var top_of_element = elem.offset().top;
var bottom_of_element = elem.offset().top + elem.outerHeight();
var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
@forsvunnet
forsvunnet / inject-magento-admin-1x.php
Last active October 23, 2018 09:17
Inject a admin account on a magento 1.x installation
<?php
$mageFilename = 'public/app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Mage::app();