Skip to content

Instantly share code, notes, and snippets.

View ahmadthedev's full-sized avatar

Muhammad Ahmad ahmadthedev

View GitHub Profile
@mrizwan47
mrizwan47 / pandas_df_to_csv_in_chunks.py
Created January 26, 2023 11:30
Save Pandas dataframe to csv in chunks
import pandas as pd
df = pd.read_csv('large_file.csv')
n = 49000 # Max number of rows you want each chunk to have
chunks = [df[i:i+n].copy() for i in range(0,df.shape[0],n)]
k = 1
for chunk in chunks:
chunk.to_csv('data/chunk_{}.csv'.format(k), index=False)
@devidw
devidw / wc-variation-linking.js
Last active May 7, 2023 07:57
WooCommerce direct variation URL for variable products
/**
* Little JS snippet to automatically update the WooCommerce single product page URL with the needed parameters for the active variations' selection.
*
* Each time the user changes the variation selection, the URL is updated with the new parameters, so on hard refresh the selected variation is displayed.
*
* Also, fast way to get the direct URL to the selected variation.
*
* Paste it into your browser console and run it. Or use it in your theme/plugins.
*
* @see https://stackoverflow.com/a/73138077/13765033
@mrizwan47
mrizwan47 / lazy-load.html
Last active April 12, 2022 19:30
Minimal VanillaJS LazyLoad Images using Intersection Observer
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<img loading="lazy" data-lazy
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkqAcAAIUAgUW0RjgAAAAASUVORK5CYII="
@jeffreyvr
jeffreyvr / README.md
Created December 21, 2021 21:13
TailPress - Gutenberg Blocks with Laravel Mix

An example of creating custom blocks from a TailPress theme using Laravel Mix.

Webpack file

Example of a block in your webpack.mix.js file:

mix.js('/resources/blocks/example/block.js', '/blocks/example/block.build.js').react();
@bagerathan
bagerathan / woo-events.js
Last active April 26, 2024 18:43
[Woocommerce Javascript events] #woo
//Woocommerce Checkout JS events
$( document.body ).trigger( 'init_checkout' );
$( document.body ).trigger( 'payment_method_selected' );
$( document.body ).trigger( 'update_checkout' );
$( document.body ).trigger( 'updated_checkout' );
$( document.body ).trigger( 'checkout_error' );
//Woocommerce cart page JS events
$( document.body ).trigger( 'wc_cart_emptied' );
$( document.body ).trigger( 'update_checkout' );
@martijn94
martijn94 / wp-admin-add-posts-state.php
Last active May 2, 2023 04:43
Snippet to add post state to a WordPress page
<?php
//======================================================================
// Add post state to the projects page
//======================================================================
add_filter( 'display_post_states', 'ecs_add_post_state', 10, 2 );
function ecs_add_post_state( $post_states, $post ) {
@SleepWalker
SleepWalker / swipe.js
Created September 30, 2015 04:59
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;
@anam-hossain
anam-hossain / modal-video-full.html
Created May 8, 2015 01:49
Full example - autoplay youtube video in a Modal (Bootstrap + Jquery)
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
$(function() {
$(".video").click(function () {
var theModal = $(this).data("target"),
videoSRC = $(this).attr("data-video"),
@irazasyed
irazasyed / spintax.php
Last active February 21, 2024 17:29
PHP: Text Spinner Class - Nested spinning supported.
<?PHP
/**
* Spintax - A helper class to process Spintax strings.
*/
class Spintax
{
/**
* Set seed to make the spinner predictable.
*/
@corsonr
corsonr / gist:9152652
Last active January 19, 2023 22:41
WooCommerce : add custom fields to product variations
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 );
/**