Overwriting a branch in Git with remote results (and bypassing merge conflicts)

If you’ve ever tried to do a git pull to get a branch up to date and have run into conflicts that you just want to bypass and go with the contents of the remote branch, do the following:

# Fetch from the default remote of origin.
git fetch origin
# Check out the branch you want to override the conflicts upon.
git checkout master
# Reset your current branch of master to origin's master.
git reset --hard origin/master

Reference: Stack Overflow: Git pull from remote.. Can I force it to overwrite rather than report conflicts?

Get a list of files added, removed and modified in Git between two branches

It’s sometimes useful to know exactly what files you’ve made changes to in your feature branch as you’re getting ready to merge back into your trunk code. Git’s diff option allows for this to be done quick easily:

git diff --name-status master..newfeature

The output looks like the following:

M       .gitmodules
A       plugins/backplane.php
A       plugins/multiple-post-thumbnails
M       themes/sportsnet/css/scss/_inc-controls.scss
M       themes/sportsnet/functions.php
M       themes/sportsnet/header.php
M       themes/sportsnet/single-sn-article.php
M       themes/sportsnet/single-sn-blog-entry.php
M       themes/sportsnet/single-sn-signing.php
M       themes/sportsnet/single-sn-trade.php
A       themes/sportsnet/zones/articles-comment-form.php
A       themes/sportsnet/zones/global/user-account-links.php
(END)

Reference: Stack Overflow – Showing which files have changed between git branches

Where all of my placeholder images come from

Years back, I happened upon fractalsponge.net, a one-man effort in creating extremely high resolution Star Wars renders of the various spacecraft in that fictional universe.

Downloading more than 5,000 rows from Google Analytics at a time

I’ve been increasing the amount of click tracking I do via Google Analytics, but getting the data back out of that system can be a bit of a time when you’re talking large amounts of data.

Enter Download Analytics, which will ask for input of a URL to the report page you’re viewing, and will automatically prompt to e-mail you (when ready) a link that will allow you to download the entire list of rows in your report. Simple, fast, effective.

Checking Akamai cache expiry times on your website’s pages

This involves sending some custom headers along with your HTTP GET request, so utilize either the wget command line tool:

wget -S -O /dev/null --header="Pragma: akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no" http://www.sportsnet.ca/

Or the curl command line tool:

curl -H "Pragma: akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no" -IXGET http://www.sportsnet.ca/

The X-Cache-Key setting will contain the amount of time the URL is cached for; in this example, the time is 1 minute (“1m”):

X-Cache-Key: /L/370/77322/1m/www.sportsnet.ca/

Running Windows? No problem – grab a compiled version of wget for Windows.

Source: Stack Overflow – What’s the best way to troubleshoot Akamai headers these days?

Costco: An internal promotion trumps an MBA any day of the week

I noticed this as well, but it took a blog post in The Washington Monthly to crystallize it in my mind.

The Washington Monthly – Political Animal – The secret of Costco’s success revealed! (hint: no MBAs need apply)

… Costco does not hire business school graduates—thanks to another idiosyncrasy meant to preserve its distinct company culture. It cultivates employees who work the floor in its warehouses and sponsors them through graduate school. Seventy percent of its warehouse managers started at the company by pushing carts and ringing cash registers.

Those sentences speak volumes. They tell you that Costco is a company that values its own hard-won experience over trendy B-school subjects like management theory and Econ 101 abstractions. They’ve found a formula that works and they’re not going to mess with it. I’ve long found the typical B-school curriculum to be problematic. On the one hand, you have management “theory,” which frequently is not well-supported by rigorous research, and might be characterized as more theological than anything else — Tom Frank has often been insightful about the ideological function served by this kind of business literature.

Then, on the other hand, you have B-school economics. One of the great sins about economics as a university subject is that, particularly at the introductory and intermediate levels where people are most likely to study it, the econ that gets taught tends to be almost entirely theoretical, not empirical. Few economists understand how businesses work, because few of them have actually bothered to ask businesspeople how they make business decisions. Instead, they make assumptions. But even assumptions that seem highly plausible in theory can turn out to be wildly off-base in fact.

Getting back to Costco: the abstract theorizing that MBA students learn in microeconomics courses often has little relevance to practical business situations. The simplified textbook models teach the lesson that policies like unions and the minimum wage are inefficient and wrong — that message comes through loud and clear. Economics as it’s taught in most American colleges today more or less encourages poor labor practices.

Costco: Secrets of the cheapest, happiest company in the world

I occasionally read an article about deplorable call centre conditions, or most recently about how difficult work in Amazon’s fulfilment warehouse is. And I always think: Why not take a small hit to the company’s margins and ease things back towards being a workplace your employees don’t dread going to? (Offhand, I’m fortunate to be able to say that in my own field of software development, working conditions are usually somewhere between good to ridiculously luxurious.)

In an era of global competition it’s hard to justify not maximizing shareholder revenue, but with the below there is a spark of hope: Evidence that companies that treat their employees better also perform better.

Costco CEO Craig Jelinek Leads the Cheapest, Happiest Company in the World

Despite the sagging economy and challenges to the industry, Costco pays its hourly workers an average of $20.89 an hour, not including overtime (vs. the minimum wage of $7.25 an hour). By comparison, Walmart said its average wage for full-time employees in the U.S. is $12.67 an hour, according to a letter it sent in April to activist Ralph Nader. Eighty-eight percent of Costco employees have company-sponsored health insurance; Walmart says that “more than half” of its do. Costco workers with coverage pay premiums that amount to less than 10 percent of the overall cost of their plans. It treats its employees well in the belief that a happier work environment will result in a more profitable company. “I just think people need to make a living wage with health benefits,” says Jelinek. “It also puts more money back into the economy and creates a healthier country. It’s really that simple.”

Jelinek earned $650,000 in 2012, plus a $200,000 bonus and stock options worth about $4 million, based on the company’s performance. That’s more than Sinegal, who made $325,000 a year. By contrast, Walmart CEO Mike Duke’s 2012 base salary was $1.3 million; he was also awarded a $4.4 million cash bonus and $13.6 million in stock grants.

Costco has no public-relations staff. Jelinek conducts an interview with a journalist alone, an anomaly at major corporations, and afterward Costco Chief Financial Officer Richard Galanti calls to inquire whether the boss inadvertently said anything negative. Sinegal returns a reporter’s phone call on a Saturday morning, leaving his cell number.

Costco’s constitutional thrift makes its generous pay and health packages all the more remarkable. About 4 percent of its workers, including those who give away samples and sell mobile phones, are part-time and employed by contractors, though Costco says it seeks to ensure they have above-industry-average pay. And while Walmart, Amazon, and others actively avoid unionization, Costco, while not exactly embracing it, is comfortable that the International Brotherhood of Teamsters represents about 15 percent of its U.S. employees. “They are philosophically much better than anyone else I have worked with,” says Rome Aloise, a Teamsters vice president.

Most retailers “see their employees as a cost to be minimized and typically end up underinvesting in them,” says Zeynep Ton, an adjunct associate professor of operations management at the MIT Sloan School of Management. She thinks that ends up creating operational problems that shoppers are all too familiar with: surly employees in stores engulfed in chaos, an environment that makes ordering online look a lot better. One solution to surly cashiers is to get rid of them completely. Walmart said that this year it would add 10,000 self-service checkout systems (though it did not say whether these systems would displace workers). Costco has also experimented with self-service checkouts, but Jelinek says he’s now removing them because employees do the work more efficiently. “They are great for low-volume warehouses, but we don’t want to be in the low-volume warehouse business,” he says.

Many conscientious companies such as Costco are performing well financially. Over the last few years, Nordstrom (JWN), the Container Store, Sephora, REI, and Whole Foods Market (WFM), all of which are known for treating employees well, have outpaced rivals. “This is the lesson Costco teaches,” says Doug Stephens, founder of the consulting firm Retail Prophet and author of the forthcoming The Retail Revival. “You don’t have to be Nordstrom selling $1,200 suits in order to pay people a living wage. That is what Walmart has lost sight of. A lot of people working at Walmart go home and live below the poverty line. You expect that person to come in and develop a rapport with customers who may be spending more than that person is making in a week? You expect them to be civil and happy about that?”

Fast 404s for missing images in WordPress

If you’re looking to replace WordPress’s long load time for a 404 error page for at least the missing images on your website, consider adding the following to the .htaccess file that sits in the root of your WordPress installation airblown inflatables canada:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$
RewriteRule .* /wp-content/themes/your-theme/images/placeholder.png [L]

In practice, this looks something like:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$ 
RewriteRule .* /wp-content/themes/your-theme/images/placeholder.png [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Working with Nginx? No problem, here’s the equivalent commands that go into your site configuration file:

location ~* (jpg|jpeg|gif|png) {
	expires 30d;
	access_log off;

	error_page 404 /wp-content/themes/your-theme/images/placeholder.png;
}

Selectively taking commits out of a GitHub pull request

Once in a while it’s necessary to get picky and only accept one or more commits from a bundle sent over in a GitHub pull request – or maybe someone’s been working on a fork of a repository of yours and you want to pull a change or two in. The git command cherry-pick is there for this purpose.

To start, you’ll need to run git fetch on the forked repository:

git fetch [email protected]:hakimel/Fokus.git

Next, take the hash of the commit you want to retrieve files for and run the cherry-pick command on it:

git cherry-pick 00988a520bda3e365c74033a44a96941d77be86f

That should do it! Check your git log to see the commit pulled into your repository.

Source: StackOverflow – Pull in changes from a Github fork

Using XDebug with Aptana Studio 3, nginx and PHP-FPM

Instructions on how to step through your PHP code with XDebug seem to be an unholy mess online. After an hour of tinkering in Ubuntu 12.04 to get it working, I’ve come up with the ten steps listed below to get the combination of Ubuntu, Nginx, PHP-FPM, XDebug and Aptana Studio 3 working together. Here’s hoping this helps someone else out there.

1. Install php5-xdebug:

sudo apt-get install php5-xdebug

2. Edit the xdebug configuration file /etc/php5/fpm/conf.d/xdebug.ini , most notably changing the default port to 9001 as PHP-FPM itself runs a daemon on port 9000. We also change the log file location to /var/log/xdebug (remember to create this folder):

xdebug.profiler_output_dir=/var/log/xdebug
xdebug.profiler_enable_trigger=1
xdebug.profiler_enable=0

xdebug.remote_enable=true
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9001
xdebug.remote_handler=dbgp
xdebug.remote_autostart=0

3. Restart PHP-FPM:

sudo /etc/init.d/php5-fpm reload

4. In Aptana Studio 3, we’ll start by ensuring that Aptana recognizes XDebug as being installed as a debugger on the system. Go to Window > Preferences > Aptana Studio > Editors > PHP > Debug. Ensure that under Installed Debuggers, XDebug is listed on port 9001.

5. While still in the Preferences window, go to General > Web Browser and change the option to Use external web browser. Leave Default system web browser marked.

6. Close the Preferences window and go to Run > Debug Configurations… Right-click PHP Web Page and select New.

7. Name your configuration whatever you’d like (localhost if you’re lacking ideas). Ensure that Server Debugger is set to XDebug. Create a new PHP Server by clicking the + button, and ensure that you set the Base URL and Document Root properly for the website you are trying to debug.

8. Almost done! We now need to Xdebug Helper in the Google Chrome browser. After it’s installed, enable it on your locally viewed web page by clicking the bug icon until it changes colour to green (if you hover over it, it will inform you that it has debugging enabled).

9. Let’s switch back to Aptana Studio 3. Under Window > Perspective, switch to Debug. We left the “Break on first line…” option under Window > Preferences > Aptana Studio > Editors > PHP > Debug, but you can just as easily double-click in the margin beside any line in your PHP script to add a breakpoint at that location. Navigate to a page that will execute that PHP script and watch as execution halts and your debugger steps in, giving you the ability to inspect variables or control execution at will.

10. Inspect the value of any variable quickly by adding the Expressions window while in Debug mode at Window > Show View > Expressions. Pop in a variable such as $page and press Enter to see the value immediately.

Need to switch back to regular coding view? Under Window > Perspective, switch to Web. Bear in mind that even outside of the Debug perspective your debugger will be active – click the bug icon in Chrome until it is grey to disable activating XDebug.