Skip to content

Instantly share code, notes, and snippets.

View itzikbenh's full-sized avatar

Isaac Ben Hutta itzikbenh

View GitHub Profile
@itzikbenh
itzikbenh / commands.txt
Last active December 14, 2022 13:44
Install wkhtmltopdf in Ubuntu 16.04.1 so you can use Laravel Snappy.
//Get package
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
sudo apt install wkhtmltopdf
//create symlink.
sudo ln -s /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
//At this point you can run this command to test that everything works.
/usr/local/bin/wkhtmltopdf google.com google.pdf
@itzikbenh
itzikbenh / show.blade.php
Last active December 21, 2018 03:58
DOMPDF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Industrial.</title>
<link href="css/invoice.css?v=1.0" rel="stylesheet">
@itzikbenh
itzikbenh / contact.js
Last active January 9, 2020 20:11
WordPress contact form using the API
(function($) {
$(".submit-contact-form").on("click", function(e) {
e.preventDefault();
$.ajax({
url: theme_data.site_url + 'wp-json/send-contact-form/v1/contact',
method: 'POST',
data: data
}).done(function(data){
@itzikbenh
itzikbenh / validate.js
Last active December 22, 2016 21:53
Validate floats and ints in JavaScript
//Removes all dots after the first one.
function removeExtraDots(str) {
return str.replace( /^([^.]*\.)(.*)$/, function ( a, b, c ) {
return b + c.replace( /\./g, '' );
});
}
function dotsCount(number) {
return (number.match(/[.]/g) || []).length;
}
@itzikbenh
itzikbenh / TicketController.php
Last active March 9, 2022 14:43
Laravel server side processing for Datatables.
<?php
use Illuminate\Pagination\Paginator;
//This example is a bit more comlex since I have columns that are foreign keys of the Ticket table.
public function index(Request $request)
{
if($request->ajax()) {
$columns = ['tickets.id', 'client_name', 'location', 'priority_name', 'status_name', 'date'];
$draw = $request->draw;
$start = $request->start; //Start is the offset
$length = $request->length; //How many records to show
@itzikbenh
itzikbenh / controller.php
Created December 7, 2016 17:52
Laravel validations
<?php
//One way
$this->validate($request,
[
'data.*.name' => 'unique:priorities'
],
[
'data.*.name.unique' => 'Priority name exists already, please pick a different name.'
]
);
@itzikbenh
itzikbenh / event.php
Last active January 9, 2020 20:11
Custom taxonomy
<?php
function ath_register_event_taxonomies()
{
$ath_taxonomy = new Ath_Taxonomy();
$ath_taxonomy->create_hierarchical_taxonomy( "event", "event_category", "Event Categories", "Event Category", "event-category" );
$ath_taxonomy->create_taxonomy( "event", "event_tag", "Event Tags", "Event Tag", "event-tag" );
}
add_action( 'init', 'ath_register_event_taxonomies' );
@itzikbenh
itzikbenh / main.php
Last active January 9, 2020 20:11
WordPress API login
<?php
//Register login route
//Test in postman with - www.yourdomain.com/wp-json/login-user/v1/user
function uab_register_endpoints()
{
register_rest_route('login-user/v1', '/user/', array(
'methods' => 'POST',
'callback' => 'uab_login_user'
));
@itzikbenh
itzikbenh / post.php
Last active October 18, 2016 04:48
Twitter share on text highlight. Inspired by theguardian.com. Tested on latest Chrome, Firefox, and Safari.
<!-- Add this anywhere in the page. It assumes your content is inside an <article> tag. -->
<a class="floating-twitter-share-link" href="#" title="Share this" target="_blank">
<i class="fa fa-twitter floating-twitter-share"></i>
</a>
@itzikbenh
itzikbenh / a-theme-auth.php
Last active January 9, 2020 20:17
WordPress class for registering users via Linkedin
<?php
function a_theme_auth_options_page()
{
add_options_page( "A-Theme Auth options", "A-Theme Auth", "manage_options", "a-theme-auth", "a_theme_auth_options" );
}
add_action( 'admin_menu', 'a_theme_auth_options_page' );
function register_a_theme_auth_settings()
{