Skip to content

Instantly share code, notes, and snippets.

@dtolb
dtolb / withPromise.js
Created April 8, 2016 16:02
withPromise
var myModule = require('myModule');
myModule.doSomethingCool(100)
.then(function (result) {
console.log(result);
})
.error(function (err) {
console.error(err);
});
@dtolb
dtolb / withCallback.js
Created April 8, 2016 16:02
withCallback
var myModule = require('myModule');
myModule.doSomethingCool(100, function (err, result) {
if (err) {
console.error(err);
return;
}
console.log(result);
});
@dtolb
dtolb / asCallback.js
Created April 8, 2016 16:01
asCallback
var someOtherModule = require('./someOtherModule');
var myModule = function() {
this.doSomethingCool(input, callback) {
// do something cool here
return someOtherModule.thatReturnsPromises(input)
.then(function (result) {
// do something else cool here
return result++;
})
@dtolb
dtolb / simplepromise.js
Created April 8, 2016 16:00
simplePromise
doTheFirstThing()
.then(doTheSecondThing)
.then(doTheThirdThing)
.then(doTheFourthThing);
@dtolb
dtolb / callback.js
Created April 8, 2016 15:59
callback
doTheFirstThing(function (err, firstResult) {
doTheSecondThing(firstResult, function (err, secondResult) {
doTheThirdThing(secondResult, function (err, thirdResult) {
doTheFourthThing(thirdResult);
});
});
});
@dtolb
dtolb / SpringApp.java
Created April 7, 2016 14:52
SpringApp.java
@SpringBootApplication
public class Application
{
private static final Logger log = LoggerFactory.getLogger(Application.class);
public static void main(String[] args)
{
SpringApplication.run(Application.class);
}
@dtolb
dtolb / products.sql
Created April 7, 2016 14:52
products.sql
select ...
from products product0_
where product0_.buyPrice>?
order by product0_.buyPrice desc
@dtolb
dtolb / ProductRepository.java
Created April 7, 2016 14:51
ProductRepository.java
public interface ProductRepository extends CrudRepository<Product, String>
{
List<Product> findByBuyPriceGreaterThanOrderByBuyPriceDesc(BigDecimal buyPrice);
}
@dtolb
dtolb / offices.sql
Created April 7, 2016 14:51
offices.sql
select ...
from employees employee0_
left outer join offices office1_ on employee0_.officeCode=office1_.officeCode
where office1_.country<>?
@dtolb
dtolb / employees.sql
Created April 7, 2016 14:50
employees.sql
select ...
from employees employee0_
where employee0_.firstName=? and employee0_.lastName=?