File does not exist: /etc/apache2/htdocs (in your apache error.log file)

The problem

/var/log/apache2/error.log has these annoying message every 5 minutes: [Wed Mar 30 18:12:34 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:17:35 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:22:36 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:27:36 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:32:37 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:37:37 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:42:38 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs [Wed Mar 30 18:47:39 2016] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs

The solution

Create the file /etc/apache2/conf.d/default-documentroot and have it contain this single line: DocumentRoot /var/www Then restart the apache2 service: service apache2 restart

Gulp

New notes: (4/2018)

The older post content dealt with react as well as ES2015. Since then, lot has changed: I’m not interested in react, and babel prefers working with ‘babel-preset-env’. So:

npm install babelify babel-core babel-preset-env --save-dev

When you get some SyntaxError: Unexpected token: name (xxxxxx) from Uglify (or Browserify?) it is probably because uglify couldn’t parse some JS syntax, like ES2015 syntax. One solution: Babelify, as demonstrated below.

Your gulp task can take a browserify object and transform it using babelify as in the first piped command here: (the original documentation: https://github.com/babel/babelify)
b
  .transform("babelify", {presets: ["env"]}) // Optional: Uncomment to support ES2015
  .bundle()
  .on('error', gutil.log.bind(gutil, 'Browserify Error')) // log errors if they happen
  .pipe(source(bundle_name)) // e.g. 'bundle.js'
  .pipe(buffer()) // optional, remove if you don't need to buffer file contents
  //.pipe(sourcemaps.init({loadMaps: true})) // loads map from browserify file // optional, remove if you don't want sourcemaps
  // Add transformation tasks to the pipeline here.
  .pipe(uglify())
  .on('error', gutil.log)
  .pipe(sourcemaps.write('./')) // writes .map file
  .pipe(gulp.dest('./public/dist'));

Older post content from here

First note: We’ll eventually be using some of these packages: (also note the --save vs. --save-dev)
npm install --save-dev gulp gulp-nodemon gulp-htmlmin gulp-cssnano gulp-uglify gulp-buster browserify vinyl-source-stream gulp-util babelify babel-preset-es2015 babel-preset-react
npm install --save react react-dom
Ok, hi. Let’s start with gulp‘s .task() simple syntax:
// (in gulpfile.js)
gulp.task('temp', [], function(){
  console.log('hello world');
}
Just copy the above into the file gulpfile.js at your root directory — this is the only file gulp needs in order to run. Then run %> gulp temp and get:
hello world
And here’s how we can simply bundle together a few files, using browserify:
// (in gulpfile.js)
gulp.task('temp', [], function() {
  browserify({
    entries: 'file1.js' // or array, e.g. ['file1.js','file2.js']
  })
  .add('another2.js') // Can also add like this
  .add('another3.js') // And more...
  .add(['another4.js', 'another5.js']) // Or use an array...

  .bundle() // Finally, let's bundle!

  .pipe(source('bundle.js')) // And store result in bundle.js
  .pipe(gulp.dest('./')); // In this directory
Ok, so we have the following simple usage:
// (in gulpfile.js)
gulp.task('temp', [], function() {
  browserify({
    entries: 'file1.js'
  })
  .bundle() // Bundle!
  .pipe(source('bundle.js')) // Store result in bundle.js
  .pipe(gulp.dest('./')); // In this directory
Suppose file1.js contains:
// file1.js
var file1var = 123;
console.log('in file1.js');
Then running %> gulp temp will overwrite bundle.js to contain:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// file1.js
var file1var = 123;
console.log('in file1.js');

},{}]},{},[1]);
There you have it. The basic usage we’ve been looking for: We can bundle together multiple JS files into one, so that we could include it in from our index.html using some script tag, for example. In our modest case, though, with no index.html and just dummy code, we could run %> node bundle.js to get this output:
in file1.js

It’s time we appreciate what we already have in our hands: What bundle really does is “Bundle the files and their dependencies into a single javascript file.” Let’s see that in action, shall we? Create a file2.js:
var file2var = 456;
console.log('in file2.js');

module.exports = {
  f : function() {
    console.log('My cool function from file2.js');
  },
  c : 789
}
And add an import command to file1.js, so its updated content is:
import File2 from './file2';

// file1.js
var file1var = 123;
console.log('in file1.js');
Running %> gulp temp will FAIL, with some error like the one below, complaining about our ES2015 syntax… (namely our newly added import command in file1.js)
events.js:141
      throw er; // Unhandled 'error' event
      ^
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
So to allow ourselves to write in ES2015 and transpile it to ordinary JS, we use babelify! Update our gulp file as follows:
// (in gulpfile.js)
gulp.task('temp', [], function() {
  browserify({
    entries: 'file1.js'
  })
  .transform("babelify", {presets: ["es2015"]}) // <= ADD THIS ROW
  .bundle() // Bundle!
  .pipe(source('bundle.js')) // Store result in bundle.js
  .pipe(gulp.dest('./')); // In this directory
And voila, running %> gulp temp overwrites bundle.js into the following:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';

var _file = require('./file2');

var _file2 = _interopRequireDefault(_file);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// file1.js
var file1var = 123;
console.log('in file1.js');

},{"./file2":2}],2:[function(require,module,exports){
'use strict';

var file2var = 456;
console.log('in file2.js');

module.exports = {
  f: function f() {
    console.log('My cool function from file2.js');
  },
  c: 789
};

},{}]},{},[1]);
Cool! So even though we merely asked for file1.js to be bundled, browserify realized that it depends on file2.js and included it in the bundle! Awesome! The import command in file1.js first "sources" the contents of file2.js. To illustrate, try running %> node bundle.js, you'll get:
in file2.js
in file1.js

Finally, a more closer-to-reality usage is to have file1.js do something with the class / object that we imported from file2.js. For example, suppose file1.js is:
import File2 from './file2';

// file1.js
var file1var = 123;
console.log('in file1.js');

console.log(File2);
Run %> gulp temp and then %> node bundle.js and we get:
in file2.js
in file1.js
{ f: [Function: f], c: 789 }

Read more here on the import command and ways to selectively import only some of the module's members (and even give them shorter aliases if necessary). Read here on browserify. In particular, about require and external!

Input type=number

<input type="number" step="any"/> Will allow any decimal point. If the current value of the input is “123.456”, for example, then clicking the UP arrow will increase it to “124.456”. Without the ‘step=”any”‘, it would’ve increased to “124”. Note: The ‘step’ attribute, together with ‘min’ and ‘max’, control which values are considered valid.

jQuery Cheatsheet

Traversal

$('p').find('span') Finds all span elements that are descendants of some ‘p’ elements (not necessarily immediate children). Compare to .children(), that travels only a single level down the DOM tree.
$('p').find('span')
or: $('span', $('p'))
Finds all span elements that are descendants of some ‘p’ elements (not necessarily immediate children). Compare to .children(), that travels only a single level down the DOM tree.

Manipulation

$(this).data('k',123) Use $(this).data('k') to get the associated value (123 in this case), $(this).data() to get all the key-value map, and $(this).removeData('k') to remove a data entry.
$('<div/>',{'class':'c1 c2'}) As of jQuery 1.4, this creates an element on the fly with specified attributes, e.g. <div class="c1 c2"></div> in this case. Note: Usually you’d like to append() or appendTo() this new element. But if you want its string representation, use the element.outerHTML attribute, i.e. $(...)[0].outerHTML.

Which PayPal product should I choose

Many products, many APIs
With their inconsistent information (and user experience) all over their dozens of different domains, PayPal miserably fails to deliver a clear message to developers. Here is a nice attempt (by PayPal) to consolidate some typical use cases so you can decide better which product is suitable for you, but you might get lost without some basic understanding of terms like “Express Checkout”, “Adaptive Payments”, “Classic APIs” etc. And so we try to shed some light on the general usage of PayPal’s products and APIs. Leave a comment and we’ll consider elaborating on other stuff as well. This document is still in the process of writing. Feel free to comment with feedback and suggestions.
PayPal NVP (Name-Value Pair) API
PayPal exist for many years, so they host a few families of APIs you can use. The newest are their REST APIs. In this section however we focus on the NVP API, which is considered as one of their “Classic APIs”. The “Name-Value” simply means that we’re passing information using the format “NAME=value”, for example FIRSTNAME=Robert&MIDDLENAME=Herbert&LASTNAME=Moore. Our page will send such a formatted request to the PayPal API Server, which will return a response: There’s a specific way to build the request. For example, you need to specify the METHOD (the required API operation to perform), and you need to provide some API Credentials: Either a signature or a certificate (but not both). For example, the “signature” option is merely some “USER=...&PWD=...&SIGNATURE=...” (together with the METHOD=... as well as other request-specific details. The response is also formatted in a specified way, and both response and request should be UTF-8-encoded. But it may help to first understand the types of requests (“API operation”s) you can make, so read on! (and later feel free to dwell into the boring details in the original documentation) Note: Some of the features, like Express Checkout, require your process to perform multiple operations in order to complete. For example, first call SetExpressCheckout and then DoExpressCheckoutPayment, as illustrated here:
Classic APIs
The API operations are divided in the documentation into 6 categories:
  • Adaptive Accounts: Create PayPal accounts and handle account management. Example requests: CreateAccount, AddPaymentCard, …
  • Adaptive Payments: Manage payments, payment preapprovals, and refunds. Example requests: Execute Payment, Pay, Refund, SetPaymentOptions, …
  • Button Manager: Manage your buttons! BMCreateButton, BMGetButtonDetails, … See also the image reference here.
  • Invoicing: CreateInvoice, SendInvoice, …
  • Merchant APIs: Some useful operations here! E.g. DoDirectPayment, DoExpressCheckoutPayment, CreateRecurringPaymentsProfile, GetExpressCheckoutDetails, GetRecurringPaymentsProfileDetails, SetExpressCheckout, UpdateRecurringPaymentsProfile, …
  • Permissions: GetPermissions, RequestPermissions, … Handle permissions associated with an access token, e.g. to execute operations on behalf of the buyer.
Express Checkout
The typical use case: When you want to allow one-time payment (as opposed to recurring payments), for example to support shopping carts on your site. The buyer clicks a button at your site, redirected to PayPal to fill in some payment details and confirm, and then redirected back to your site. You must have a PayPal merchant account to allow this. Below is a summary of the getting started guide.
  • The typical checkout flow, without Express Checkout, is the following:
    • The payor (buyer) clicks the checkout button in his shopping cart page,
    • Provide shipping info,
    • Select payment method,
    • Review summary for approval,
    • Sees a confirmation of the transaction.
  • The “Express Checkout” way skips the “shipping info” and “payment method” steps. The image below neatly summarizes the process together with the 3 API calls your applications needs to make:
The relevant API for working with Express Checkout is here. A good and detailed documentation about actually implementing it is here.
Payflow Gateway
For the more serious applications that want full control on the process: To host the checkout pages, manage security for sales and authorizations. You need an “Internet Merchant Account” for that (which is a different thing from being simply a “merchant”, i.e. there’s a special application form you have to fill and it gets processed within a few days). Quoting the documentation:
Payflow is secure, open payment gateway. It is available in two versions: Payflow Link, which requires the use of hosted payment pages, and Payflow Pro, which gives merchants total control over the payment process. Payflow allows merchants to choose any Internet Merchant Account to accept debit or credit card payments and connect to any major processor. It also lets merchants accept PayPal and Bill Me Later payments.
PayPal Payments Pro (Direct Integration), Website Payments Pro
Enables merchants and developers to accept credit cards, debit cards, and PayPal payments directly on their website. PayPal Payments Pro also includes Express Checkout and Virtual Terminal. Add-on services like Recurring Billing are also available.
Recurring Payments
https://developer.paypal.com/docs/classic/paypal-payments-pro/integration-guide/WPRecurringPayments/ recurring payment profile: Every time someone is charged in a recurring manner (subscription), in PayPal terms this means she has a recurring payment profile. This “profile” instance includes all the payments details and is maintained at PayPal’s side.

Social Apps, OAuth

Google

To revoke access of a Google App:
https://accounts.google.com/IssuedAuthSubTokens,
or https://plus.google.com/apps if you have a Google+ profile.

For OAuth purposes:
– To create an App: https://cloud.google.com/console/.
– Use Client ID (e.g. 123456789012.apps.googleusercontent.com) and Client secret (e.g. FAft3aUW3sdtM1E28XXMimQw).
– Make sure you configure both the “Authorized Javascript origins” as well as the “Authorized redirect URI” fields.

Facebook

To revoke access of a Facebook App:
https://www.facebook.com/settings?tab=applications (Settings -> Apps).

For OAuth purposes:
– To create an App: developers.facebook.com.
– Use App ID and App Secret.
– Make sure you configure the “App Domains”, and add a “Platform”, namely “Website”, where you also configure the “Site URL” cialis 20mg tadalafil.

LinkedIn

For OAuth purposes:
– To create an App: https://www.linkedin.com/secure/developer.

Laravel Cheatsheet

Some useful Laravel 4 commands below.

Config

In app/config/ there are various files (objects) like ‘app’, ‘auth’, ‘database’, and more. Configure them as you like. You can use Config::get($key) to access some configuration in real-time, e.g.Config::get('app.debug').

Redirect

Redirect::to('') or Redirect::to('/') Redirects to /public/
Redirect::route('someName') Redirects using a Named Route.

Named Routes

Route::get('user/profile', array('as' => 'profile', function() { ... })) or Route::get('user/profile', array('as' => 'profile', 'uses' => 'UserController@showProfile')); Associates the “user/profile” route with some function (or Controller method), and creates a Named Route to “user/profile” (so now when you’ll call Redirect::route('profile'); you’ll redirect to “user/profile”.

Rename a folder when Windows claims it’s shared or open in another program

You’re trying to rename (or delete) a folder on your Windows 7 machine, and you get an annoying message saying that some of its subfolders are shared, or the message: “this action can’t be completed because the folder or a file in it is open in another program”. Possible quick solutions for the sharing error message:
  • Make sure it’s indeed not shared! (go to Properties->Sharing and make sure it says “Not Shared”).
  • Not sure which of the subfolders is being shared? Run net share to view all current shares in your machine (and thank me later). More documentation is here.
  • It’s sometimes the thumbs.db’s fault. It sometimes helps to change the “view” to disable any previews (e.g. use the “Details” or “List” views).
Possible quick solutions for the “open in another program” error message:
  • Delete all contents from “C:\Users\USERNAME\AppData\Local\Temp” (or simply type “%temp%” in your Windows Explorer or “Start” input box and it will get you there). If this doesn’t help, empty the Recycle Bin as well.
  • Restart the explorer.exe service (e.g. go to Windows Task Manager (CTRL+SHIFT+ESC), find explorer.exe and “End Process”, then under “File” click “New Task (Run…)” and type in “explorer.exe”)
  • Delete all thumbs.db files from that folder (search for thumbs.db and delete all results; don’t worry, Windows will generate them the next time you visit the appropriate files/directories). Also from Recycle Bin.
  • Update to the most recent .NET Framework.
  • Try to rename oldDirName newDirName from the Command Console (preferably with Administrator privileges, but doesn’t really matter in this case). If the command fails (“access denied”), run it in Safe Mode or immediately after the computer boots! (if the latter suggestion worked, this means that the culprit was some nasty service you have there running, better get acquainted with your processes, check out the cool Process Explorer by Windows Sysinternals.
Other possible solutions:

Related issue — remove an annoying “lock sign” off a file or a folder:

  • Compare the Properties->Security of that folder with another well-behaved folder. It’s usually the “Authenticated Users” group that would suddenly disappear, so add it (Edit->Add, then type in “Authenticated Users”) again and give it the same permissions as your other, well-behaved folder.
If you still have a problem, write a comment below and we’ll try to help. Please, no links to sites or any other spam.

How to limit the number of revisions in WordPress

WordPress has an interesting Revisions System. Each saved draft or published update is stored as a separate row in the DB, and you can compare any two specific revisions. In addition, there’s also a special “autosave revision” that is kept there from time to time while you edit your thoughts.Movie Rings (2017)

But if you like tidiness and a bounded number of rows in your DB tables, you may limit or disable the number of revisions. The easiest way is to edit wp-config.php, by adding:
define( 'WP_POST_REVISIONS', 3 );
Instead of the 3 above that will limit the number of revisions to 3 + the autosave one, you may choose any other integer > 0. To disable all revisions (except the autosave one) use 0 or false instead. To remove the limit either remove this line or use -1 or true. This is all explained in WordPress Codex as well, but whatever your final choice is, make sure you add this before the line:
/* That's all, stop editing! Happy blogging. */

Hope this helps.

Laravel Blank Page / White Screen

Did you also get an annoying blank page / white screen after your first installation of Laravel? Here are a few troubleshooting directions that may help:

  • Permissions: folders within app/storage require write access by the web server! Make sure you chmod everything appropriately!
    • Note for beginners: If you’re using Apache, the user used by the web server may be “www-data” or “root” by default. You can find the User directive usually in the /etc/apache/apache2.conf file, usually with something like User ${APACHE_RUN_USER} (the environment variable APACHE_RUN_USER is set in /etc/apache2/envvars.
  • Note that Apache 2.2 and 2.4 differ in some Rewrite-related commands. Might be relevant for you, if you’re struggling with some rewrites.
  • Ubuntu users, make sure you sudo apt-get install php5-mcrypt (and then sudo service apache2 restart)
  • In the routes.php file, try a really simple route before going into View rendering etc., for example: Route::get('/', function() { echo 'HERE! (delete me!)'; return 'Returning a simple string without any View rendering.'; }

Still stuck? Leave a comment and we’ll do our best to debug your problem. But it seems like the reasons above solve most of the cases.