Skip to content

Instantly share code, notes, and snippets.

View airarm's full-sized avatar

Arman Hayrapetyan airarm

View GitHub Profile
@airarm
airarm / Base64.js
Created February 22, 2019 18:36
Base64 javascript component
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
export default Base64 = {
btoa: (input) => {
input = input || '';
if(typeof input !== 'string'){
throw new Error("Input must be string but you given "+(typeof input));
}
let str = input;
let output = '';
<?php
function get_remote_content($url)
{
return file_get_contents($url, false, stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
)));
}
<?php
function cleanHtml($html_source)
{
$html_source = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $html_source);
$html_source = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html_source);
$html_source = preg_replace('#<link(.*?)>#is', '', $html_source);
$html_source = preg_replace('#<meta(.*?)>#is', '', $html_source);
$html_source = preg_replace('~<(?:!DOCTYPE|/?(?:html|body))[^>]*>\s*~i', '', $html_source);
return $html_source;
<?php
function DOMInnerHTML(DOMNode $element)
{
$innerHTML = "";
$children = $element->childNodes;
foreach ($children as $child){
$innerHTML .= $element->ownerDocument->saveHTML($child);
}
<?php
function url_format($value, $https = false)
{
if(is_string($value))
{
if(preg_match('#^\/\/#', $value)){
$value = ($https ? 'https:' : 'http:') . $value;
}else if(preg_match('#^[w]{3}#', $value)){
$value = ($https ? 'https://' : 'http://') . $value;
}
@airarm
airarm / wp_get_remote_content_and_check.php
Last active January 5, 2020 11:26
Wordpress get remote content with checking
<?php
$remote_response = wp_remote_get(
add_query_arg(array(
), 'https://jsonplaceholder.typicode.com/todos/1'),
array(
'sslverify' => false,
'headers' => array(
'Content-Type' => 'application/json'
)
<?php
function get_wc_cart_shop_info()
{
$item_quantities = WC()->cart->get_cart_item_quantities();
return array(
'cart' => array(
'count' => WC()->cart->get_cart_contents_count(),
'total' => WC()->cart->get_cart_contents_total(),
'weight' => WC()->cart->get_cart_contents_weight(),
<?php
function arr_end(array $array)
{
if(!empty($array) && is_array($array))
{
if(function_exists('end')){
return end($array);
}else{
return $array[count($array) - 1];
}