Skip to content

Instantly share code, notes, and snippets.

View danpastori's full-sized avatar
✍️
Writing a book about building APIs and SPAs with @vuejs & @laravel

Dan Pastori danpastori

✍️
Writing a book about building APIs and SPAs with @vuejs & @laravel
View GitHub Profile
@danpastori
danpastori / transform_to_form_data.js
Created April 30, 2020 17:13
Transform a VueJS form to FormData for File Uploads with Axios
/**
* Simple transformation to form data for uploading files
* using VueJS and Axios.
*
* Assuming that you pass your entire form as the `form`
* paramter. For example:
*
* data(){
* return {
* form : {
@danpastori
danpastori / functions.js
Created November 9, 2018 04:19
Run Method When Song Is At Certain Time Amplitude 3.3.1
Amplitude.init({
debug: true,
songs: [
//Add songs here
],
callbacks: {
'time_update': function(){
var currentTime = Amplitude.getSongPlayedSeconds();
@danpastori
danpastori / custom_field_save.php
Created January 20, 2015 16:15
Custom field save
function page_save( $post_id ){
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( isset( $_POST['pre-content-text'] ) ){
update_post_meta( $post_id, 'pre-content-text', $_POST['pre-content-text'] );
}
if( isset( $_POST['post-content-text'] ) ){
update_post_meta( $post_id, 'post-content-text', $_POST['post-content-text'] );
}
@danpastori
danpastori / meta_box_render.php
Created January 20, 2015 16:13
Meta Box Render function
function custom_meta_box_render(){
global $post;
$custom_values = get_post_custom( $post->id );
$pre_content_text = isset( $custom_values['pre-content-text'][0] ) ? $custom_values['pre-content-text'][0] : '';
$post_content_text = isset( $custom_values['post-content-text'][0] ) ? $custom_values['post-content-text'][0] : '';
?>
<label style="font-size: 15px;">Pre Content Text</label><br>
<label style="font-size: 15px;">Pre Content Text</label><br>
<div style="margin-top: 20px;">
<?php wp_editor($pre_content_text, 'pre-content-text', array() ); ?>
</div>
<label style="font-size: 15px;">Post Content Text</label><br>
<div style="margin-top: 20px;">
<?php wp_editor($post_content_text, 'post-content-text', array() ); ?>
</div>
@danpastori
danpastori / add_custom_meta_boxes.php
Created January 20, 2015 16:09
Custom Meta Box initialization
<?php
add_action( 'add_meta_boxes', 'add_custom_meta_boxes');
function add_custom_meta_boxes(){
add_meta_box(
'my-meta-box',
'Example Meta Data',
'custom_meta_box_render',
'page',
'normal',
'high'
@danpastori
danpastori / example_return.json
Created October 28, 2014 23:51
Example JSON return
[{"id":2,"label":"Test Tag","value":"Test Tag"}]
@danpastori
danpastori / tags_input_autocomplete.js
Created October 28, 2014 23:50
Tags input with autocomplete functionality
$(document).ready(function(){
$('#tags-example').tagsInput({
autocomplete_url: function(request, response) {
var search_data = {
tags_example_search_param: $('#tags-example_tag').val()
}
var url = '/tags_example_autocomplete';
$.post(url, search_data, function(data){
response(data);
});
@danpastori
danpastori / tags_input.js
Created October 28, 2014 23:47
Apply the tags input function.
$(document).ready(function(){
$('#tags-example').tagsInput({
});
});
@danpastori
danpastori / tags_input.html
Created October 28, 2014 23:46
Just a tags input example
<input type="text" name="tags-example" id="tags-example"/>