Skip to content

Instantly share code, notes, and snippets.

@krishna19
krishna19 / UndoStack.js
Created Nov 12, 2018 — forked from dsamarin/UndoStack.js
Easy undo-redo in JavaScript.
View UndoStack.js
function UndoItem (perform, data) {
this.perform = perform;
this.data = data;
}
/**
* UndoStack:
* Easy undo-redo in JavaScript.
**/
@krishna19
krishna19 / functions.php
Created Sep 27, 2018 — forked from mikaelz/functions.php
WooCommerce auto-update cart when quantity changed, relates with https://gist.github.com/mikaelz/418a337dace188ba95b476ce65abfe0c
View functions.php
/**
* Auto update cart after quantity change
*
* @return string
**/
add_action( 'woocommerce_after_cart', 'custom_after_cart' );
function custom_after_cart() {
echo '<script>
jQuery(document).ready(function($) {
@krishna19
krishna19 / animatedScrollTo.js
Created Sep 22, 2018 — forked from andjosh/animatedScrollTo.js
ScrollTo animation using pure javascript and no jquery
View animatedScrollTo.js
document.getElementsByTagName('button')[0].onclick = function () {
scrollTo(document.body, 0, 1250);
}
function scrollTo(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20;
View es6-ajax-request.js
export default class Ajax {
get(url, callback) {
let xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
xhr.open('GET', url);
xhr.onreadystatechange = () => {
if (xhr.readyState > 3 && xhr.status === 200) {
callback(xhr.responseText);
}
};
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
View php-convert-color-code-from-hex-to-rgba
<?php
function ak_convert_hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
if (empty($color))
return $default;
if ($color[0] == '#')
$color = substr($color, 1);
@krishna19
krishna19 / problems.js
Created Feb 8, 2017 — forked from leocaseiro/problems.js
Frontend Masters - Javascript: The Good Parts by Douglas Crockford
View problems.js
/*
* @link https://frontendmasters.com/courses/javascript-the-good-parts/
Problems 1-5
A sequence of problems will be presented followed by a solution. Each problem builds on the last so if you get a problem wrong, use the solution to begin the next problem. First, a quick quiz: What is x?
3:19:33 - 3:32:25
Problems 6-9
o Problem 6: Write a function that takes a function and an argument, and returns a function that can supply a second argument.
o Problem 7: Without writing any new functions, show three ways to create the inc function.
o Problem 8: Write methodize, a function that converts a binary function to a method.
o Problem 9: Write demethodize, a function that converts a method to a binary function.
@krishna19
krishna19 / hnl.taphover.js
Created Jan 24, 2017 — forked from c-kick/hnl.taphover.js
jQuery - Mouse hover on touch devices
View hnl.taphover.js
//taphover - a solution to the lack of hover on touch devices.
//more info: http://www.hnldesign.nl/work/code/mouseover-hover-on-touch-devices-using-jquery/
$('a.taphover').on('touchstart', function (e) {
'use strict'; //satisfy the code inspectors
var link = $(this); //preselect the link
if (link.hasClass('hover')) {
return true;
} else {
link.addClass('hover');
$('a.taphover').not(this).removeClass('hover');
@krishna19
krishna19 / header.php
Created Jan 19, 2017 — forked from jameskoster/header.php
WooCommerce - Checkout link (when cart is not empty)
View header.php
global $woocommerce;
if ( sizeof( $woocommerce->cart->cart_contents) > 0 ) :
echo '<a href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __( 'Checkout' ) . '">' . __( 'Checkout' ) . '</a>';
endif;
@krishna19
krishna19 / ssl-support.php
Created Dec 14, 2016 — forked from thomasmb/ssl-support.php
Simple filter for adding https support to wp_get_attachment_url in WordPress
View ssl-support.php
<?php
add_filter( 'wp_get_attachment_url', function( $url, $id ){
if( is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
return $url;
});
You can’t perform that action at this time.