Skip to content

Instantly share code, notes, and snippets.

View willyarisky's full-sized avatar
🇮🇩
Working from paradise

Willy Arisky willyarisky

🇮🇩
Working from paradise
View GitHub Profile
@willyarisky
willyarisky / nl2br.js
Created March 17, 2019 08:51
nl2br for Javascript
function nl2br (str, is_xhtml) {
if (typeof str === 'undefined' || str === null) {
return '';
}
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
@willyarisky
willyarisky / hosts
Created February 1, 2019 08:54
/etc/hosts for Netflix
114.4.164.187 assets.nflxext.com
69.172.200.241 ir.netflix.com
52.84.49.252 media.netflix.com
54.71.111.34 www.netflix.com
52.38.152.174 help.netflix.com
54.187.232.55 jobs.netflix.com
114.4.164.187 codex.nflxext.com
34.233.159.233 netflix.com
52.27.34.11 api-global.netflix.com
54.68.31.82 ichnaea.netflix.com
@willyarisky
willyarisky / ForceSSL.php
Created November 8, 2018 08:42
Redirect to https laravel 5.*
<?php
namespace App\Http\Middleware;
use Closure;
class ForceSSL
{
/**
* Handle an incoming request.
@willyarisky
willyarisky / PreferredDomain.php
Last active November 8, 2018 08:48
Non www domain as primary on laravel 5.*
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Redirect;
class PreferredDomain
{
/**
@willyarisky
willyarisky / fb_url.js
Created October 30, 2018 14:56
Validate facebook url with javascript
var pattern = /^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]/;
var url = $("#facebook_url").val();
if( pattern.test(url) ){
$("#order").submit();
} else {
e.preventDefault();
alert('Your Facebook URL Invalid');
}
@willyarisky
willyarisky / set_active.php
Created October 30, 2018 12:14
Set active helper for Laravel 5.*
<?php
/**
* Set any link as active by adding active class
* @param [uri] $uri Current URI
* @param string $ouput CLASS class name
*/
function set_active($uri, $output = 'active')
{
if( is_array($uri) ) {
foreach ($uri as $u) {
@willyarisky
willyarisky / create-unique-slug.php
Created August 16, 2018 17:06
Create unique laravel slug
/**
* @param $name
* @param int $id
* @return string
* @throws \Exception
*/
public function createSlug($name, $id = 0)
{
// Normalize the name
$slug = str_slug($name);
@willyarisky
willyarisky / functions.php
Created May 7, 2018 06:03
WooCommerce: Custom text button on single page.
/**
* custom text button woocommerce single
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_text_button_woocommerce_single' );
function custom_text_button_woocommerce_single( $label ) {
global $product;
$product_type = $product->product_type;
@willyarisky
willyarisky / jcnk.sh
Created January 25, 2018 16:39
Bash script to check and auto restart apache2 when failure
#!/bin/sh
while [ true ]
do
THEDIR=/tmp/apache-watchdog
mkdir -p $THEDIR
if ( wget --timeout=10 -q -P $THEDIR https://yourdomain.com/)
then
# we are up
echo "Server up"
@willyarisky
willyarisky / get-city.php
Created June 12, 2017 09:35
Get city from zillow listing
<?php
$curl = curl_init();
$zillow_url = 'https://www.zillow.com/homedetails/5339-Summit-Hollow-Dr-Houston-TX-77084/89649115_zpid/';
curl_setopt_array($curl, array(
CURLOPT_URL => $zillow_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,