Skip to content

Instantly share code, notes, and snippets.

@krishna19
krishna19 / UndoStack.js
Created November 12, 2018 12:52 — forked from dsamarin/UndoStack.js
Easy undo-redo in JavaScript.
function UndoItem (perform, data) {
this.perform = perform;
this.data = data;
}
/**
* UndoStack:
* Easy undo-redo in JavaScript.
**/
@krishna19
krishna19 / functions.php
Created September 27, 2018 11:29 — forked from mikaelz/functions.php
WooCommerce auto-update cart when quantity changed, relates with https://gist.github.com/mikaelz/418a337dace188ba95b476ce65abfe0c
/**
* 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 September 22, 2018 06:00 — forked from joshbeckman/animatedScrollTo.js
ScrollTo animation using pure javascript and no jquery
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;
@krishna19
krishna19 / es6-ajax-request.js
Created January 4, 2018 10:54 — forked from hsnaydd/es6-ajax-request.js
Es6 Ajax request
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');
@krishna19
krishna19 / php-convert-color-code-from-hex-to-rgba
Created September 12, 2017 03:49 — forked from alexkalh/php-convert-color-code-from-hex-to-rgba
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 February 8, 2017 17:30 — forked from leocaseiro/problems.js
Frontend Masters - Javascript: The Good Parts by Douglas Crockford
/*
* @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 January 24, 2017 05:03 — forked from c-kick/hnl.taphover.js
jQuery - Mouse hover on touch devices
//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 January 19, 2017 10:42 — forked from jameskoster/header.php
WooCommerce - Checkout link (when cart is not empty)
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 December 14, 2016 13:06 — forked from thomasmb/ssl-support.php
Simple filter for adding https support to wp_get_attachment_url in WordPress
<?php
add_filter( 'wp_get_attachment_url', function( $url, $id ){
if( is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
return $url;
});