Skip to content

Instantly share code, notes, and snippets.

View itzikbenh's full-sized avatar

Isaac Ben Hutta itzikbenh

View GitHub Profile
@itzikbenh
itzikbenh / button.php
Last active August 12, 2016 02:26
A-theme bootstrap components
<button class="ath-btn ath-btn-default">
DEFAULT
</button>
<button class="ath-btn ath-btn-info">
INFO
</button>
<button class="ath-btn ath-btn-primary">
PRIMARY
</button>
<button class="ath-btn ath-btn-success">
@itzikbenh
itzikbenh / db-class.php
Last active October 5, 2016 22:23
Simple WordPress query builder. In progress.
<?php
class Ath_DB
{
protected static $table = null;
function __construct()
{
global $wpdb;
$this->db = $wpdb;
@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 / 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 / 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 / table.js
Created February 7, 2017 18:57
datatables
var invoicesTable = $('table.invoices-table').DataTable({
processing: true,
serverSide: true,
lengthChange: true,
rowId: 'id',
"ajax": {
"url": '/invoices',
"dataSrc": "data.data",
data: function ( d ) {
var dateType = $('#dateType').val();
@itzikbenh
itzikbenh / BackupCRM.php
Created February 9, 2017 17:36
Laravel backup command to amazon S3
<?php
namespace App\Console\Commands;
use Aws\S3\MultipartUploader;
use Aws\Exception\MultipartUploadException;
use Illuminate\Console\Command;
use Storage;
class BackupCRM extends Command
@itzikbenh
itzikbenh / media.js
Created February 19, 2017 14:51
Test
//Helper function for getting the exif data.
function base64ToArrayBuffer (base64) {
base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
var binaryString = atob(base64);
var len = binaryString.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
@itzikbenh
itzikbenh / admin.js
Created February 27, 2017 01:45
Webpack config
import '../scss/admin.scss';
<?php
function api_register_user( WP_REST_Request $request ) {
$username = sanitize_text_field( trim( $request['username'] ) );
$email = sanitize_email( trim( $request['email'] ) );
$password = sanitize_text_field( trim( $request['password'] ) );
$confirm_password = sanitize_text_field( trim( $request['confirm_password'] ) );
$captcha = $request['captcha'];
$errors = [];
if( ! $captcha ) {