Skip to content

Instantly share code, notes, and snippets.

View ptasker's full-sized avatar
:fishsticks:
Fishsticks FTW

Peter Tasker ptasker

:fishsticks:
Fishsticks FTW
View GitHub Profile
mymodel.findOne({
'user': this.req.user,
}, function(err, data){
doSomethingWithData(data, function(err, data){
doSomethingWithELSEWithData(data, function(err, data){
doSomethingMOREWithData(data, function(err, data){
haveAnaneurysm(data, function(err, data){
//die
@ptasker
ptasker / gist:6f1412a04813f1123157
Last active August 29, 2015 14:20
NodeJS Promises
function getTweets (req, res) {
var d = Q.defer();
T.get('statuses/user_timeline', {screen_name: 'petetasker', count: 2}, function (err, data, response) {
if (err) {
var error = new Error('Something went wrong trying to get Tweets');
error.innerError = err;
throw error;
@ptasker
ptasker / gist:9a5f736a3a3a24ed3719
Last active August 29, 2015 14:20
NodeJS promises issue
function authenticate() {
return getUsername()
.then(function (username) {
return getUser(username);
})
// chained because we will not need the user name in the next event
.then(function (user) {
return getPassword()
// nested because we need both user and password next
.then(function (password) {
@ptasker
ptasker / gist:835e91c7f8f22eee6883
Created May 7, 2015 15:23
NodeJS Callbacks fixed
var tweets = {
/**
*
* Responsible for running the call to Twitter API
*
* @param err
* @param result
* @returns {*}
*/
doTwitterCall: function (extraArg, err, result) {
//MOAR code here etc.
//extraArg is available here with a value of 'foo'
//return result
},
getResults: function (err, result) {
@ptasker
ptasker / gist:7b0457df5b9ac6bf20da
Created July 14, 2015 12:36
Git remove deleted files
git diff --diff-filter=D --name-only -z | xargs -0 git rm
@ptasker
ptasker / redhatpermissions.txt
Last active August 29, 2015 14:27
Apply permissions on RHEL (Redhat) for httpd
sudo setsebool -P httpd_unified 1
@ptasker
ptasker / Date range
Last active October 15, 2015 14:25
Date range
var monthArray = [];
for(var i in monthly){
var month = monthly[i].split('-')[1];
monthArray.push(months[month]);
}
currStartMonth = monthly[0];
@ptasker
ptasker / window.open.js
Created February 5, 2016 20:39
window.open in a callback
//Do this first!
window.open("about:blank", "sharer");
var params = {...}
ajaxFunction(function (data) {
var url = 'http://google.ca';
//Refer to the original window here...
var w = window.open(url, 'sharer');
@ptasker
ptasker / jetpack-form-ajax.js
Last active May 9, 2016 13:59
jQuery submit Jetpack Contact Form
//All the contact forms from Jetpack have the .contact-form class. This _should_ match all of them on a page and work correctly.
$(".contact-form").on('submit', function (e) {
//Wrapper for our form fields to submit via ajax
var formData = {};
var contact_form_id = $(this).find('input[name=contact-form-id]').val();
//Get our form fields here. New fields can be added here as well.
formData['g' + contact_form_id + '-name'] = $('input[name=g' + contact_form_id + '-name]').val();