Skip to content

Instantly share code, notes, and snippets.

var Q = require('q');
promise1(2).then(function (d) {
return promise2(d)
}).then(console.log,console.log)
function promise1 (d){
var def = Q.defer();
if(d===1){
def.resolve('resuelto promise1')
function send(d){
var p = "\x02"+d+"\x0D";//adds STX y ETX
var timeout;
var deferred = Q.defer();
serialPort.on('data', function (data) {
//console.log('RECEIVED: ' + data );
data=''+data;
deferred.resolve(data.trim())
Here is the puzzle. It is expressed in coffeescript, but you can answer in javascript or coffeescript.
Imagine you have a function that accesses a resource asynchronously. However, the resource is not able to handle too many concurrent requests. In order to control the number of concurrent requests, you will need to design a function throttle.
- A function throttle takes an asynchronous function and a concurrency limit as its arguments and returns a throttled version:
throttledFunction = throttler(asyncFunction, concurrencyLevel)
- The asynchronous function will always have as its last argument a callback function, which is called with the result as its only argument.
- A resource is "in use" between the time the asynchronous function starts and the time it calls its callback with the result.
- If the throttler sees too many calls to the asynchronous function simultaneously, then it queues the extra calls and waits until a callback is c alled before starting a new execution.
Please write a "throttler" functio
I did
bower install ember-data-sails-adapter --save
if I put
<script type="text/javascript" src="/bower_components/ember-data-sails-adapter/ember-data-sails-adapter.js"></script>
in the index file of the app when I lift the ember server usign ember-cli it throws this error:
Remote Address:127.0.0.1:4200
Request URL:http://localhost:4200/bower_components/ember-data-sails-adapter/ember-data-sails-adapter.js
Request Method:GET
{
"data": {
"fullName": "jose andradez",
"hourlyWage": "44",
"phoneNumber": "4245"
},
"fullName": "",
"hourlyWage": 0,
"phoneNumber": "",
"createdAt": "2014-09-09T16:09:28.391Z",
@HERRKIN
HERRKIN / gist:cb4552ce04c47f229381
Last active August 29, 2015 14:07
ember select doesnt show properly the selected one
pet template/////////////////////
<h1>
{{nombre}} {{color}}
</h1>
<p>pertenece a:
{{dueno.nombre}} {{dueno.apellido}}</p>
{{#if editando}}
<form role="form">
in bluebird whats the difference bewteen these two?
somepromise(arg)
.then(someotherpromise(secondarg))
.then(athirdoption())
.then(undefined,console.log)
whats the difference between doing that and doing:
var Promise=require('bluebird');
var net= require('net');
//var openedPort=false;
//Cas.config;
//Cas.client;
var Cas = function(args) {
this.config=args
console.log(this.config)
// console.log(config)
@HERRKIN
HERRKIN / gist:d82572169c8914bbfa7e
Created February 9, 2015 20:39
problem with view select
//item controller for article
import Ember from 'ember';
export default Ember.Controller.extend({
states: ['borrowed', 'returned'],
autoSave: function() {
if (!this.get('model.isNew')) {
#!/bin/sh
DATE=`/bin/date +%d-%m-%Y-%H:%M:%S`
export PGUSER=user
export PGPASSWORD=password
pg_dump -Fc -b database > /home/saecosoft/Dropbox/pgbackup/respaldo-$DATE.backup