Skip to content

Instantly share code, notes, and snippets.

View abachuk's full-sized avatar
✍️
dev manager by day, writing code at night

Alex Bachuk abachuk

✍️
dev manager by day, writing code at night
View GitHub Profile
@abachuk
abachuk / gist:5658751
Created May 27, 2013 19:41
getting blog posts with ajax request in JSON format
blog: function(){
$.ajax({
url: 'http://alexbachuk.com/api/get_recent_posts/',
type: 'GET',
dataType: 'json',
success: function(data){
console.log(data);
},
error: function(data){
console.log(data);
@abachuk
abachuk / wppb.login.php
Last active December 18, 2015 02:58
WP User Frontend Login with Email
<?php
/* wp_signon can only be executed before anything is outputed in the page because of that we're adding it to the init hook */
global $wppb_login;
$wppb_login = false;
function wppb_signon(){
global $error;
global $wppb_login;
@abachuk
abachuk / deferred-example.js
Created June 12, 2013 16:07
jquery deferred
var dfd = $.Deferred();
var endpoint = $.ajax({
url: 'http://yourdomain.com/data.json',
sucess: dfd.resolve
});
endpoint.success(function(data){console.log(data)});
var template = _.template($('#template-in-script').html());
$('#placeholder-container').html(template(data));
<!-- Main script file -->
<!-- when JSON object is received it's passed to template (id of script tag) -->
<!-- posts in the end is JSON object we received from AJAX -->
var template = _.template( $("#posts_template").html(), posts );
<!-- in HTML document -->
<!-- emplty placeholder -->
<div id="posts-container"></div>
<!-- compiled template adds html to empty placeholder -->
@abachuk
abachuk / swipe.js
Created September 26, 2013 18:18
simple swipe wvents
$.fn.swipeEvents = function() {
return this.each(function() {
var startX,
startY,
$this = $(this);
$this.bind('touchstart', touchstart);
// The actual grunt server settings
connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: 35729
},
proxies: [{
context: '/api', // the context of the data service
host: 'mydomain.com/apis/', // wherever the data service is running
@abachuk
abachuk / index.php
Created June 7, 2015 18:45
WordPress plugin extending CMB2 metaboxes
<?php
/*
Plugin Name: NDM metaboxes
Description: portfolio metaboxes for NDM
Version: 0.11
Author: Alex Bachuk
Author URI: http://alexbachuk.com
License: GPL2
*/
?>
function add (a,b) {
return a+b;
}
// Redux action
export function uploadSuccess({ data }) {
return {
type: 'UPLOAD_DOCUMENT_SUCCESS',
data,
};
}
export function uploadFail(error) {
return {