Skip to content

Instantly share code, notes, and snippets.

View weestack's full-sized avatar

Alexander Høgh weestack

View GitHub Profile
@weestack
weestack / Dockerfile
Last active September 17, 2024 11:47
V8js compile for Linux 6.10 to be used for debian bookworm or ubuntu 2024
FROM php:7.3-fpm as BASE_PHP
ENV V8_VERSION=9.9.115.9
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js (see https://github.com/phpv8/v8js/blob/php7/README.Linux.md)
RUN apt-get install -y --no-install-recommends \
libtinfo5 libtinfo-dev \
build-essential \
curl \
@weestack
weestack / compile v8js for linux 6.10 (Debian bookworm)
Created September 17, 2024 11:40
# Once done copy /opt/v8 and /usr/local/lib/php/extensions/no-debug-non-zts-20180731/v8js.so to the server needing the binary into their respective places
FROM php:7.3-fpm as BASE_PHP
ENV V8_VERSION=9.9.115.9
RUN apt-get update -y --fix-missing && apt-get upgrade -y;
# Install v8js (see https://github.com/phpv8/v8js/blob/php7/README.Linux.md)
RUN apt-get install -y --no-install-recommends \
libtinfo5 libtinfo-dev \
build-essential \
curl \
def counting_sort(A, length):
# First fint the maximum value
k = max(A)
Aux = list()
for i in range(0, k+1):
Aux.insert(i, 0)
for i in range(0, length):
Aux[A[i]] += 1
# Prints out the time it takes for a function to run
def time_runtime(function):
@wraps(function)
def wrapper(*args, **kwargs):
start = time.time()
result = function(*args, **kwargs)
end = time.time()
print("Time to run in seconds: {}".format(end-start))
return result
return wrapper
# Big Theta (n^2)
def insertion_sort(A: list):
# Start loop from 1, as 0 wont be compared to it self
for j in range(1, len(A)):
#block 1
key = A[j]
# Block 2
i = j - 1
while i > -1 and A[i] > key:
/* Set default close message */
function default_give_form_closed_message($post_id, $post, $update){
if (! $update ) {
$meta_key = '_give_form_goal_achieved_message';
$meta_value = "Mange tak, vi har nået målet for indsamlingen!";
$current_close_message = get_post_meta( $post_id, '_give_form_goal_achieved_message', true );
if (empty($current_close_message))
update_post_meta($post_id, $meta_key, $meta_value, $prev_value=$current_close_message);
}
function add_donation_names_to_give_forms(){
global $post;
$content = "";
if (get_post_type( $post->ID) == "give_forms") {
ob_start();
?> <h2>Andre donation</h2> <?php
echo do_shortcode('[give_donor_wall form_id="'.$post->ID.'"]');
$content = ob_get_clean();
}
echo $content;
/* Get total earnings with currency */
function get_total_earnings($atts = []) {
/*
* Posible parameters for atts start_date and end_date:
* today
* yesterday
* this_week
* last_week
* this_month
* last_month
function set_default_featured_image($post_id, $post, $update){
if ( ! $update && ! ((bool) get_post_thumbnail_id($post_id))){
$img_id = 2675;
//$post_id = 2784;
set_post_thumbnail( $post_id, $img_id );
add_post_meta($post_id, '_thumbnail_id', $img_id);
}
}
/* Register user at checkout */
function wc_register_guests( $order_id ) {
// get all the order data
$order = new WC_Order($order_id);
//get the user email from the order
$order_email = $order->billing_email;
// check if there are any users with the billing email as user or email
$email = email_exists( $order_email );