How to close idle connections in PostgreSQL automatically?

For those who are interested, here is the solution I came up with, inspired from Craig Ringer’s comment: (…) use a cron job to look at when the connection was last active (see pg_stat_activity) and use pg_terminate_backend to kill old ones.(…) The chosen solution comes down like this: First, we upgrade to Postgresql 9.2. Then, … Read more

Express.js Response Timeout

There is already a Connect Middleware for Timeout support: var timeout = express.timeout // express v3 and below var timeout = require(‘connect-timeout’); //express v4 app.use(timeout(120000)); app.use(haltOnTimedout); function haltOnTimedout(req, res, next){ if (!req.timedout) next(); } If you plan on using the Timeout middleware as a top-level middleware like above, the haltOnTimedOut middleware needs to be the … Read more

Is there a Task based replacement for System.Threading.Timer?

It depends on 4.5, but this works. public class PeriodicTask { public static async Task Run(Action action, TimeSpan period, CancellationToken cancellationToken) { while(!cancellationToken.IsCancellationRequested) { await Task.Delay(period, cancellationToken); if (!cancellationToken.IsCancellationRequested) action(); } } public static Task Run(Action action, TimeSpan period) { return Run(action, period, CancellationToken.None); } } Obviously you could add a generic version that takes … Read more

find the time left in a setTimeout()?

Just for the record, there is a way to get the time left in node.js: var timeout = setTimeout(function() {}, 3600 * 1000); setInterval(function() { console.log(‘Time left: ‘+getTimeLeft(timeout)+’s’); }, 2000); function getTimeLeft(timeout) { return Math.ceil((timeout._idleStart + timeout._idleTimeout – Date.now()) / 1000); } Prints: $ node test.js Time left: 3599s Time left: 3597s Time left: 3595s … Read more

Timeout jQuery effects

Update: As of jQuery 1.4 you can use the .delay( n ) method. http://api.jquery.com/delay/ $(‘.notice’).fadeIn().delay(2000).fadeOut(‘slow’); Note: $.show() and $.hide() by default are not queued, so if you want to use $.delay() with them, you need to configure them that way: $(‘.notice’) .show({duration: 0, queue: true}) .delay(2000) .hide({duration: 0, queue: true}); You could possibly use the … Read more

Why composer install timeouts after 300 seconds?

Check with composer update/install -o -vvv whether the package is being loaded from composers’ cache. If yes, try clearing composer’s cache or try adding –cache-dir=/dev/null. To force downloading an archive instead of cloning sources, use the –prefer-dist option in combination with –no-dev. Otherwise you could try raising composer’s process timeout value: export COMPOSER_PROCESS_TIMEOUT=600 # default … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)