Skip to content

Instantly share code, notes, and snippets.

View andris9's full-sized avatar
🇪🇪

Andris Reinman andris9

🇪🇪
View GitHub Profile
@andris9
andris9 / jitsu.js
Created November 20, 2012 08:21
Nodemailer usage in Nodejitsu
var http = require('http'),
nodemailer = require('nodemailer');
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "{user}",
pass: "{pass}"
}
});
@andris9
andris9 / oauth1.js
Last active December 14, 2015 11:58
var crypto = require("crypto"),
urllib = require("url");
/**
* Wrapper for new OAuthGenerator.
*
* Usage:
*
* var OAuthgen = createOAuthGenerator({});
* OAuthgen.getToken(function(err, OAuthtoken){
@andris9
andris9 / input.eml
Created March 26, 2013 08:46
Parse win-1251 e-mail. The source of the e-mail is not UTF-8 so the file shown here is encoded to base64 to keep the integrity of the file
UmVjZWl2ZWQ6IGZyb20gMTkyLjE2OC4wLjEyMCBieSBydS1ib2FyZC5jb20gZm9yIDxyYXp1aGFAbWFpbC5jb20+OyBNb24sIDI1IE1hciAyMDEzIDE2OjI4OjI4IC0wNTAwClJlY2VpdmVkOiAoZnJvbSBmb3J1bUBsb2NhbGhvc3QpCiAgICBieSBydS1ib2FyZC5jb20gKDguMTQuMi84LjE0LjIvU3VibWl0KSBpZCByMlBMU1BqdTAwMjE3MDsKICAgIE1vbiwgMjUgTWFyIDIwMTMgMTY6Mjg6MjUgLTA1MDAKRGF0ZTogTW9uLCAyNSBNYXIgMjAxMyAxNjoyODoyNSAtMDUwMApNZXNzYWdlLUlkOiA8MjAxMzAzMjUyMTI4LnIyUExTUGp1MDAyMTcwQHJ1LWJvYXJkLmNvbT4KVG86IHJhenVoYUBtYWlsLmNvbQpSZXBseS10bzogUnUtQm9hcmQgPGZvcnVtQG1haWwucnUtYm9hcmQuY29tPgpGcm9tOiBSdS1Cb2FyZCA8Zm9ydW1AbWFpbC5ydS1ib2FyZC5jb20+CkNvbnRlbnQtVHlwZTogdGV4dC9wbGFpbjsgY2hhcnNldD1XaW5kb3dzLTEyNTEKWC1NYWlsZXI6IFJVLkJvYXJkIG1haWxlciAoZm9yIGFueSBxdWVzdGlvbnMgY29udGFjdCB3aXRoIHN1cHBvcnQgdGVhbSkKU3ViamVjdDog0e/g8ejh7iDn4CDw5ePo8fLw4Pbo/iDiIMru7O/8/vLl8O376SD07vDz7CBSdS5Cb2FyZApYLUdyZXlsaXN0OiBTZW5kZXIgSVAgd2hpdGVsaXN0ZWQsIG5vdCBkZWxheWVkIGJ5IG1pbHRlci1ncmV5bGlzdC00LjAgKHJ1LWJvYXJkLmNvbSBbMTI3LjAuMC4xXSk7IE1vbiwgMjUgTWFyIDIwMTMgMTY6Mjg6MzIgLTA1MDAgKENEVCkKCgrK7uzv/P7y5fDt++kg9O7w8+wg
@andris9
andris9 / upload.js
Created June 10, 2013 12:02
Upload file
var inputName = "uploadedfile",
fileName = "test.txt",
fileContents = "hello world!", // UTF-8
targetUrl = "http://example.com/post.php"
require("fetch").fetchUrl(targetUrl, {
method: "post",
agent: false,
headers:{
@andris9
andris9 / utf7.js
Created August 16, 2013 11:38
Decode utf7
// npm install iconv iconv-lite
var Iconv = require("iconv").Iconv,
iconv = require("iconv-lite");
var str = "abc&AOQA9gD8-";
function convertFromUTF7_old(str){
var fromUTF7 = new Iconv("UTF-16", "UTF-8//TRANSLIT//IGNORE")
// default string encoding by inbox is binary
@andris9
andris9 / gmail-test.js
Last active December 22, 2015 03:48
Gmail IMAP bug example testcase. If run, the output should include an invalid BODYSTRUCTURE string for message/rfc822 attachments
// GMAIL BUG:
// If a message has an message/rfc822 attachment then In-Reply-To value in the embedded envelope
// is forced to string even if the value was missing (the value is "NIL" instead of NIL)
// Usage: this is a node.js script, so you should have node installed (www.nodejs.org)
// replace USERNAME and PASSWORD values and run `node gmail-test.js`
// the output of this script is an IMAP log, see below for an example
// this script appends and removes a message with message/rfc822 attachments
var tls = require("tls");
@andris9
andris9 / client.js
Last active June 21, 2021 12:55
udp broadcats client
var dgram = require("dgram");
var port = 18432,
multicastIP = "224.3.56.114";
var client = dgram.createSocket('udp4');
client.bind(port, "0.0.0.0");
client.on("listening", function(){
client.setBroadcast(true);
@andris9
andris9 / imap.js
Last active December 23, 2015 17:39
node-imap with hoodiecrow
// Install dependencies:
// npm install imap hoodiecrow
var Imap = require('imap'),
hoodiecrow = require("hoodiecrow"),
inspect = require('util').inspect;
var
// Message store for hoodiecrow
@andris9
andris9 / parser.php
Last active December 23, 2015 23:49
Parses query string
<?php
$str = "/v1/combinedObjects:(id,user_id,value,title,person:(id,name,activities_count,owner_id:(name),activities_count),organization:(id,name))";
print_r(queryParser($str));
function queryParser($query){
// split tokens
$tokens = preg_split('/,|(?=:\\(|\\))|(?<=:\\(|\\))/', $query, -1, PREG_SPLIT_NO_EMPTY);
@andris9
andris9 / mail.json
Created September 27, 2013 08:16
mail
{
"meta": {
"mail": true,
"message_id": "B35481CB-4CE9-4DE8-9FD7-72A9932F3455@pipedrive.com",
"type": "Dropbox",
"date": "Fri, 27 Sep 2013 11:02:10 +0300",
"user_id": 25,
"company_id": 25
},
"data": {