Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
frozonfreak / inview.js
Created November 17, 2016 04:11
check if element in view with jquery - for infinite scroll
$.fn.inView = function(){
if(!this.length) return false;
var rect = this.get(0).getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
@frozonfreak
frozonfreak / gist:4a39dd294ed47e3129f8cdb4cbe12ad7
Created September 5, 2016 05:37 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@frozonfreak
frozonfreak / FileController.js
Created December 27, 2015 07:50 — forked from tkh44/FileController.js
Simple file upload for sails.js
module.exports = {
get: function (req, res) {
res.sendfile(req.path.substr(1));
},
_config: {
rest: false,
shortcuts: false
}
};
@frozonfreak
frozonfreak / fileformatcheck.js
Created December 21, 2015 02:08
Check for file format using magic numbers in file
var blob = $(this).get(0).files[0];
var fileReader = new FileReader();
fileReader.readAsArrayBuffer(blob);
fileReader.onloadend = function(e) {
var arr = (new Uint8Array(e.target.result)).subarray(0, 4);
var header = "";
for(var i = 0; i < arr.length; i++) {
header += arr[i].toString(16);
}
console.log(header);
@frozonfreak
frozonfreak / phpworker.conf
Created August 14, 2015 01:24
PHP daemon Ubuntu
# Info
description "My PHP Worker"
author "Jonathan"
# Events
start on startup
stop on shutdown
# Automatically respawn
respawn
@frozonfreak
frozonfreak / email_validate.php
Created February 1, 2015 12:47
Email validation PHP
<?php
class Email_Validate{
function __construct(){
}
//destructor
@frozonfreak
frozonfreak / shortner
Created January 13, 2015 08:19
Get short url from bitly and viceversa
/* returns the shortened url */
function get_bitly_short_url($url,$login,$appkey,$format='txt') {
$connectURL = 'http://api.bit.ly/v3/shorten?login='.$login.'&apiKey='.$appkey.'&uri='.urlencode($url).'&format='.$format;
return curl_get_result($connectURL);
}
/* returns expanded url */
function get_bitly_long_url($url,$login,$appkey,$format='txt') {
$connectURL = 'http://api.bit.ly/v3/expand?login='.$login.'&apiKey='.$appkey.'&shortUrl='.urlencode($url).'&format='.$format;
return curl_get_result($connectURL);
@frozonfreak
frozonfreak / speed
Created January 12, 2015 01:15
Get download speed of webserver
<?php error_reporting(E_ALL | E_STRICT);
// Initialize cURL with given url
$url = 'http://download.bethere.co.uk/images/61859740_3c0c5dbc30_o.jpg';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Sitepoint Examples (thread 581410; http://www.sitepoint.com/forums/showthread.php?t=581410)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
@frozonfreak
frozonfreak / clean_url.php
Created December 29, 2014 03:44
Clean URL PHP
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
@frozonfreak
frozonfreak / function.php
Last active November 20, 2018 15:54
WooCommerce apply coupon for regular price instead of sale price
add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_coupon_get_discount_amount', 10, 5 );
function woocommerce_coupon_get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
if ($coupon->type == 'percent_product' || $coupon->type == 'percent') {
global $woocommerce;
$cart_total = 0;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
$variable_product1= new WC_Product_Variation( $cart_item["variation_id"] );