Skip to content

Instantly share code, notes, and snippets.

View martintajur's full-sized avatar

Martin Tajur martintajur

View GitHub Profile
@martintajur
martintajur / simple-lockfile-for-nodejs.js
Created January 19, 2012 14:36
Simple lock-file mechanism for nodeJS
var fs = require('fs');
var path = require('path');
if (typeof exports === 'undefined') var exports = {};
exports.exists = function(filename) {
try {
return (fs.lstatSync(filename) ? true : false);
}
catch (err) {
@martintajur
martintajur / gist:3539777
Created August 30, 2012 20:14
Convert selected emails from Apple Mail app to files on Desktop
# taken from http://macscripter.net/viewtopic.php?id=17655
# be sure to replace [username] with your username folder!
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Finder" to set ptd to (path to desktop folder) as string
tell application "Finder" to set pathToAttachments to "iMac:Users:[username]:Desktop:" & "Attachments:"
tell application "Mail"
repeat with theMessage in theMessages
set theText to (all headers of theMessage & content of theMessage)
@martintajur
martintajur / gist:5413664
Created April 18, 2013 15:30
Basic Pipedrive person renamer (splits person's names into 2 and flips the sides, giving the ability to flip first names and last names of persons)
/*
* Basic Pipedrive person renamer (splits person's names into 2 and flips the sides, giving the ability to flip first names and last names of persons)
*
* Usage
* =====
* First, install pipedrive npm module:
* npm install pipedrive
*
* Then run the script:
* node personNamer.js
@martintajur
martintajur / mergePhones.js
Last active August 29, 2015 14:03
Pipedrive people phone fields merger script (it can be used to combine multiple phone field values inside the single, multi-valued phone field)
/*
Pipedrive people phone fields merger script
It can be used to combine existing, multiple separate phone field values inside the single, multi-valued phone field.
MIT Licence.
*/
var P = require('pipedrive');
var _ = require('lodash');
var p = new P.Client('PUT_YOUR_API_TOKEN_HERE');
@martintajur
martintajur / list-licenses.sh
Last active August 29, 2015 14:18
List all licenses used across all npm modules recursively
# You need to have licensecheck npm module installed globally in order this to work.
# Install it via: npm install -g licensecheck
find . -name "package.json" | sed 's/package.json$//g' | xargs licensecheck
@martintajur
martintajur / deal-participants-fields-converter.js
Last active August 29, 2015 14:23
Convert Pipedrive deals' custom person-type fields into deal participants
/*
Pipedrive person type field as participants linker
MIT Licence.
*/
var Pipedrive = require('pipedrive');
var pipedrive = new Pipedrive.Client('PUT_YOUR_API_TOKEN_HERE');
var personTypeFields = ['0196e433d44471e3cad7306209bc70ed623abd95','dd0e6438e2082ed2a6cdced28aeb7aff3557d3c6'],
batchSize = 200,
var Pipedrive = require('pipedrive'),
pipedrive = new Pipedrive.Client('YOUR_API_TOKEN_HERE'),
async = require('async'),
q = [],
pageSize = 500,
transformDeal = function(deal) {
// Only update deals in BYR currency that have 0 products attached:
if (deal.currency === 'BYR' && !deal.products_count) {
console.log('Updating ' + deal.title + '...');