---
layout: post
title: "How to write proper PHP"
permalink: 2013/12/17/how-to-write-proper-php
postday: 2013/12/17
posttime: 05_57
tags: untagged
---
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function buildTranslations(message, originLanguage, destLanguages){ | |
return Promise.try(function(){ | |
translations = {}; | |
destLanguages.map(function(currentLang){ | |
translations[currentLang.code] = {} | |
db.model('Translation').translate(message,originLanguage.code,currentLang.code).then(function(translation){ | |
console.log('build Trans function'+translation); | |
translations[currentLang.code] = translation; | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bingTranslate(message,originLang,destLang,accessToken){ | |
Promise.try(function(){ | |
accessToken.then(function(bingToken){ | |
options = { | |
headers:{ | |
'Authorization': "Bearer "+accessToken | |
} | |
}; | |
queryString="text="+encodeURIComponent(message)+"&from="+originLang+"&to="+destLang+"&contentType=text%2Fplain"; | |
return bhttp.get("http://api.microsofttranslator.com/V2/Http.svc/Translate?"+queryString,options).then(function(data){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// models/user.js | |
module.exports = function(bookshelf) { | |
return bookshelf.define(/* blah blah blah */); | |
} | |
// app.js | |
var bookshelf = /* connection stuff goes here */ | |
var User = require("models/user")(bookshelf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* npm install --save-dev gulp gulp-util gulp-concat gulp-rename gulp-coffee gulp-cached gulp-remember gulp-plumber */ | |
var gulp = require('gulp'); | |
/* CoffeeScript compile deps */ | |
var path = require('path'); | |
var gutil = require('gulp-util'); | |
var concat = require('gulp-concat'); | |
var rename = require('gulp-rename'); | |
var coffee = require('gulp-coffee'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frontpageScore = (upvotes, minutes) -> | |
maxMinutes = (48 * 60); | |
maxMultiplier = Math.pow(1.001, maxMinutes); | |
if minutes > maxMinutes | |
minutes = maxMinutes | |
factor = 1 - (Math.pow(1.001, minutes) / maxMultiplier) | |
return factor * upvotes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var path = require('path'); | |
var gutil = require('gulp-util'); | |
var concat = require('gulp-concat'); | |
var rename = require('gulp-rename'); | |
var coffee = require('gulp-coffee'); | |
var cache = require('gulp-cached'); | |
var remember = require('gulp-remember'); | |
var plumber = require('gulp-plumber'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S = require "string" | |
Promise = require "bluebird" | |
request = require "request" | |
libxml = require "libxmljs" | |
longest = require "longest" | |
cld = Promise.promisifyAll(require "cld") | |
urlLib = require "url" | |
module.exports = | |
createTeaser: (input, length) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise = require "bluebird" | |
express = require "express" | |
router = express.Router() | |
gm = require "gm" | |
util = require "../util" | |
fs = require "fs" | |
path = require "path" | |
moment = require "moment" | |
request = require "request" | |
urlLib = require "url" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(bookshelf) { | |
return bookshelf.Model.prototype.saveChanges = function(options) { | |
if (options == null) { | |
options = {}; | |
} | |
options.patch = true; | |
return this.save(this.changed, options); | |
}; | |
}; |
OlderNewer