Skip to content

Instantly share code, notes, and snippets.

Avatar

Isaac Ben Hutta itzikbenh

View GitHub Profile
@itzikbenh
itzikbenh / webpack.config.js
Last active Dec 8, 2017
Webpack slow config
View webpack.config.js
module.exports = env => {
const config = {
devServer: {
hot: true,
inline: true,
headers: { 'Access-Control-Allow-Origin': '*' },
port: 8080,
host: 'localhost',
},
entry: {
View app.js
import Vue from 'vue';
import posts from './components/posts.vue';
window.axios = require('axios');
window.Vue = Vue;
Vue.component('posts', posts);
const app = new Vue({
el: '#app',
View app.js
class Picky {
constructor(element) {
let self = this;
this.$el = element;
this.select = this.$el.querySelector('select');
this.dropdown = this.$el.querySelector('ul');
this.input = this.$el.querySelector('input');
this._open = false;
View cron-commands
0 * * * * /usr/bin/env bash /root/backup/db-backup.sh &>> /root/backup/backup.log
0 0 * * * /usr/bin/env bash /root/backup/uploads-backup.sh &>> /root/backup/backup.log
View admin.js
$('#update-cat-featured-img, #add-cat-featured-img').click(function(e) {
e.preventDefault();
var custom_uploader = wp.media({
title: 'Featured Image',
button: {
text: 'Insert image'
},
multiple: false // Set this to "add" to allow multiple files to be selected
})
@itzikbenh
itzikbenh / example.md
Created Aug 2, 2017
Stripe basic class
View example.md

NOTE

Always handle errors when you use stripe functions. You don't want to make mistakes when it comes to people's money.

Create a customer

$stripe_client = new Stripe_Client( $user, $stripe_secret, $token );

try {
  $customer = $stripe_client->create_customer();
} catch (Exception $e) {
@itzikbenh
itzikbenh / app.js
Created Aug 1, 2017
WordPress - Insert file into tinymce in the frontend via the REST API
View app.js
let $body = $('body');
let $error_field = $('.file-error');
function hasExtension(file_name, exts) {
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', "i")).test(file_name);
}
function fileSizeInMB(file_size) {
return (file_size / (1024*1024)).toFixed(2);
@itzikbenh
itzikbenh / functions.php
Created Jul 31, 2017
WordPress - show current user attachments
View functions.php
<?php
//Besides administrator show only the current user media files
function show_current_user_attachments( $query ) {
if( ! current_user_can( 'manage_options' ) ) {
$user_id = get_current_user_id();
if ( $user_id ) {
$query['author'] = $user_id;
}
return $query;
@itzikbenh
itzikbenh / errors.php
Last active Jul 31, 2017
WordPress simple validator class. Still in the work
View errors.php
<?php if( isset( $_SESSION['errors'] ) ): ?>
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<ul>
<?php foreach ($_SESSION["errors"] as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
@itzikbenh
itzikbenh / company.js
Last active Oct 11, 2017
WP repeater field
View company.js
function generate_key_person_fields(newId) {
return `
<div class="key-person-container">
<div class="form-group-admin-inline">
<label>Name</label><br>
<input type="text" name="key_person[name][${newId}][]" value="" required>
</div>
<div class="form-group-admin-inline">
<label>Title</label><br>