Skip to content

Instantly share code, notes, and snippets.

View acdcjunior's full-sized avatar
🌘
It's been a hard day's night

Antônio "acdc" Jr. acdcjunior

🌘
It's been a hard day's night
View GitHub Profile
@acdcjunior
acdcjunior / index.html
Created December 12, 2014 00:27
PouchDB/CouchDB Map/Reduce GROUP BY Example
<!DOCTYPE html>
<html>
<head>
<script src="//cdn.jsdelivr.net/pouchdb/3.2.0/pouchdb.min.js"></script>
<script src="pouchdbMapReduceGroupByExample.js"></script>
</head>
<body>
</body>
</html>
@acdcjunior
acdcjunior / index.html
Last active August 29, 2015 14:11
pdb2
<html>
<body>
<pre id="display"></pre>
<script src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.5/es5-shim.min.js"></script>
<script src="//cdn.jsdelivr.net/pouchdb/3.2.0/pouchdb.min.js"></script>
<script src="index.js"></script>
</body>
</html>
@acdcjunior
acdcjunior / UnitOfWork.java
Last active May 3, 2020 16:03
UnitOrWork + DAO + EntityManager programatic transaction handling suggestion
// NOTE: This is not a by-the-book implementation of the UnitOfWork pattern. If you don't feel it is
// OK, then you can call this class Transaction or anything like that
public class UnitOfWork {
// static reference to entityManagerFactory
public static UnitOfWork createUnitOfWork() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
return new UnitOfWork(entityManager);
}
var runAfterFiveSeconds = delayedAdd(2, 3);
var multiplication = function (result) {
return result * result
};
var printResult = function (result) {
console.log(result);
};
var multiplicationAfterFiveSeconds = runAfterFiveSeconds(multiplication);
multiplicationAfterFiveSeconds(printResult);
@acdcjunior
acdcjunior / SeleniumFileDownloadFirefox.java
Created June 30, 2015 18:00
Selenium Automatic File download using Firefox
FirefoxProfile fxProfile = new FirefoxProfile();
fxProfile.setPreference("browser.download.folderList",2);
fxProfile.setPreference("browser.download.manager.showWhenStarting",false);
fxProfile.setPreference("browser.download.dir","c:\\mydownloads");
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
WebDriver driver = new FirefoxDriver(fxProfile);
driver.navigate().to("http://www.foo.com/bah.csv");
@acdcjunior
acdcjunior / MockitoVsHandBuiltDoublesTest.java
Created January 23, 2016 22:16
Mockito vs. Hand-built test doubles (Mocks) small performance test
import org.junit.Test;
import org.mockito.Mockito;
import org.openqa.selenium.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@acdcjunior
acdcjunior / Dummies.java
Created January 23, 2016 23:36
Mockito: create a mock object that throws exception at any method call (so... a Dummy object, not a mock)
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.Mockito.mock;
public class Dummies {
private static class NoMethodShouldBeCalledAnswer implements Answer<Object> {
private String className;
@acdcjunior
acdcjunior / parsing brackets.md
Created February 21, 2016 06:43
Parsing brackets using JavaScript (with PEG.js, not regex)

GO TO

  http://pegjs.org/online

Paste in the grammar:

  Expression
        = head:Factor tail:Factor* {
              return head + tail.join("");

}

@acdcjunior
acdcjunior / Banco.js
Last active July 5, 2017 22:59
Banco.js
var Banco = (function () {
function Banco(nomeBanco) {
if (nomeBanco === void 0) { nomeBanco = 'testes'; }
this.checkEhString(nomeBanco);
this.db = new PouchDB(nomeBanco);
}
Banco.prototype.checkEhString = function (id) {
if (typeof id !== 'string') {
throw new Error('Argumento deve ser uma string e nao um objeto! Recebido: '
+ JSON.stringify(id));
0x1750dd0f8cd22ee9d849ab11ebc62adb37ffc10a