Skip to content

Instantly share code, notes, and snippets.

@joaoneto
joaoneto / login.test.js
Created Mar 13, 2013
Login session test with mocha
View login.test.js
var request = require('supertest'),
should = require('should'),
app = require('../server');
var Cookies;
describe('Functional Test <Sessions>:', function () {
it('should create user session for valid user', function (done) {
request(app)
.post('/v1/sessions')
@joaoneto
joaoneto / client_oauth.sh
Created Apr 11, 2013
Authorize and get token
View client_oauth.sh
#!/bin/bash
COOKIE_TMP_FILE=".tmp_cookie"
USER_EMAIL="foo@example.com"
USER_PASSWORD="123"
CLIENT_ID="XXXXXXXXXXXXXXXXXXXXXXXX"
CLIENT_SECRET="abc123"
REDIRECT_URI="http://localhost:3000"
@joaoneto
joaoneto / async-serial.js
Last active Jun 11, 2020
Javascript example of asynchronous and serial processing flow in async/await reduce function
View async-serial.js
const mockAsyncProcess = (objToProcess) => {
console.time(objToProcess.id)
console.log(`BEGIN: ${objToProcess.id}`)
return new Promise((resolve) => {
setTimeout(() => {
resolve(`RESULT -> ${objToProcess.id}`);
console.timeEnd(objToProcess.id)
console.log(`END: ${objToProcess.id}`)
}, Math.random() * 1000)
})
View startproject.sh
#!/usr/bin/env bash
mkdir -p ./app
echo '{
"name": "my-project",
"version": "0.0.0",
"scripts": {
"dev": "webpack-recipes devserver 9000",
"build": "webpack-recipes build --mode=production"
},
"devDependencies": {
View dynamicStates.js
(function() {
'use strict';
var dynamicStates = function ($stateProvider, $urlRouterProvider) {
var addRoute = function (name, definition) {
$stateProvider.state(name, definition);
};
$urlRouterProvider.deferIntercept();
View dynamic-states.json
{
"state-one": {
"controller": "stateOneController",
"template": "<h1>State One</h1>"
},
"state-two": {
"controller": "stateTwoController",
"template": "<h1>State Two</h1>"
}
}
@joaoneto
joaoneto / correios.js
Last active Jul 27, 2017
Track para os correios
View correios.js
var http = require('http');
var parseTrack = function (data) {
var trackLines = data.replace(/[\r\n]/g, '').replace(/<\/tr>/gi, '</tr>\n').match(/<tr.*?>(.*)<\/tr>/gi);
trackLines.shift();
var parsed = [], parts = [];
var length = trackLines.length;
var details, date, track;
while (length--) {
View custom_events.js
(function () {
var _eventsStack = {};
window.Events = {
emit: function (eventName, message) {
if (!_eventsStack.hasOwnProperty(eventName)) {
_eventsStack[eventName] = [];
}
_eventsStack[eventName].forEach(function (fn) {
fn(message != undefined ? message : {});
});
@joaoneto
joaoneto / crosswalk.js
Created Nov 1, 2014
Gulp tasks to download and update a existent cordova project with crosswallk
View crosswalk.js
var gulp = require('gulp');
var gutil = require('gulp-util');
var shell = require('gulp-shell');
var download = require('gulp-download');
var unzip = require('gulp-unzip');
var clean = require('gulp-clean');
var runSequence = require('gulp-run-sequence');
var fs = require('fs');
var path = require('path');
var et = require('elementtree');
@joaoneto
joaoneto / README.md
Last active May 23, 2016
Improve your curl with pretty formmated json responses
View README.md

Improve your curl with pretty formmated json responses

requirements node.js

add in your .zshrc

[[ -s $HOME/bin/prettycurl.sh ]] && . $HOME/bin/prettycurl.sh
You can’t perform that action at this time.