Odd image rotation when uploading photos taken from Samsung S4

Issue occurs when I upload an image to my webapp from the Samsung S4. The actual image displays just fine when requested directly through Chrome (ie. http://xxxxx/image.jpg). However, when rendered using rails image tag, the image appears 90 degrees rotated. The image appears rotated in Chrome but renders fine in mobile safari.

Turns out.. images uploaded through the Samsung Galaxy S4 includes an extra bit of metadata to tell the renderer how to orient the image correctly. It would appear that chrome (or perhaps it's rails, not sure) isn't taking this into account.

The proper solution is to allow your rendering code to detect the image orientation. Perhaps there's a way to solve this through CSS. Since I'm bound by time, I've came up with the most fastest (albeit hacky) solution possible... manual commands via imagemagick!


Turns out it's extremely easy to install imagemagick on linux:

sudo apt-get install imagemagick

Rotating the image:

convert source_photo.jpg -rotate 90 dest_photo.jpg

Removing the image metadata:

mogrify -strip image.jpg


Please share if you have a more automated solution!!


Various jQuery filters

basic filters
:first
:last
:even
:odd
:eq(n)
:gt(n)
:lt(n)
:header // selects H1, H2...
:animated
:not(selector)

attribute filters
[attribute]
[attribute=value]
[attribute!=value[
[attribute^=value[ // starts with
[attribute$=value[ // ends with
[attribute*=value[ // contains
[attrFilter1][attrFilterN] // match all specified filters

content filters
:contains(text) // contains text string
:empty // only include empty elements
:has(selector) // element containing at least one element with specified selector
:parent // all elements that are parents

visibility filters
:visible
:hidden

child filters
:nth-child(index)
:nth-child(even)
:nth-child(odd)
:nth-child(equation)
:first-child
:last-child
:only-child

form filters
:input
:text
:password
:radio
:checkbox
:submit
:reset
:image
:button
:file

form state filters
:enabled
:disabled
:checked
:selected


Deploying .NET through Plesk

Need:
To deploy a .NET 4.0 web application


Problem:
Plesk is used to manage sites and application pools :(
Plesk is old and only supports .NET 2.0 :( :(


Solution:
create new subdomain in plesk. By default the site will use ASP.NET 2.0
cd c:\...\framework\v4.0.xxxxx
aspnet_regiis.exe -lk
# now go find the identifier of the site/subdomain in IIS, should be a number
# now update .NET version of that site/subdomain using identifier
aspnet_regiis -sn W3SVC//ROOT/
# verify that it worked
aspnet_regiis.exe -lk


Site now served using .NET 4.0 application pool even though Plesk doesn't support it.

Problems in Rails

Problem: Issue with rails missing the rake gem
Solution: Install rake to the rvm global environment

rvm ruby-2.0.0-p###
gem install rake -v 10.1.0


Problem: It looks like Bundler could not find a gem. This is probably because your application is being run under a different environment than it's supposed to.
Solution: Manage gems with rvm. In my case, 'passenger' was using the global gemset even though I specified the project to use env1... solution is of course to install all missing gems for the global gemset.

# list the gemsets
rvm gemset list
# to use env1 gemset
rvm 2.0.0-p###@env1
# to use global gemset
rvm 2.0.0-p###@global
# install missing gems
gem install
bundle install


Problem: Various commands for cloning/creating/deleting gemsets
Solution: Use rvm

# clone
rvm gemset copy 2.0.0-pXXX@env1 2.0.0-pXXX@env2
# create
rvm gemset create env2
# delete
rvm gemset delete env2


Problem: When POW complains that rake does not exist
Solution: Add a .powrc file with the following content:

if [ -f "$rvm_path/scripts/rvm" ]; then
  source "$rvm_path/scripts/rvm"

fi
rvm ruby-2.0.0-pXXX@env1


Problem: Gem::LoadError: You have already activated json 1.8.1, but your Gemfile requires json 1.8.0 ...
Solution-1: Globally, call bundle uninstall json -v 1.8.1
Solution-2: Locally, call bundle update json






Getting PHP and Apache to work again after upgrading to Yosemite

One of the worst part about upgrading OSX has to be reconfiguring Apache to work. It was the same when I upgraded to Maverick, and again now in my upgrade to Yosemite.

Apache:

The httpd.conf is still at the same place: /etc/apache2/httpd.conf, but it was overwritten. I think the previous is automatically backed up as httpd.conf~previous.

You can use sudo apachectl configtest to check configuration errors. Diff-ing the previous version against the current version yielded the following (annoying) gotchas:

  1. Many modules were turned off by default (ie. php5_module). Some were added (ie. session_module), renamed (ie. disk_cache_module), or removed (ie. ident_module)
  2. User & Group were reset to _www
  3. Order deny,allow / Deny from all is now Require all denied
  4. Order deny,allow / Allow from all is now Require all granted
  5. Supplemental configs were removed (ie. httpd-vhosts.conf, httpd-ssl.conf, etc)
  6. For SSLSessionCache, you need to enable several modules in the httpd.conf file (ie. socache_shmcb_module, socache_dbm_module, socache_memcache_module)
The biggest, and most annoying gotcha of all were items #3 and #4. Make sure you make these changes in all supplemental configs like httpd-vhosts.conf.

PHP:

php.ini was removed. I think the previous is automatically backed up as php.ini-x.x-previous. For some reason, my php zts extension was updated as well, so I had to make a minor update to the php.ini ie. /usr/lib/php/extensions/no-debug-non-zts-xxxxxxxx/xdebug.so

P.s. I don't remember if I had to reinstall pear.

MySQL:

If MySQL isn't started, run this command to start it again:
sudo /usr/local/mysql/support-files/mysql.server start

Setting up a local proxy on your phone

The software I chose to use is called Squidman Proxy. A more robust and intuitive (albeit costly) option is Charles Proxy.

http://squidman.net/squidman/
http://www.charlesproxy.com/

This tutorial is for setting up Squidman for iOS or Android.

Precursor:
Make sure that the computer is accessible by your device by IP.
It's easiest to set up your environment if both are connected to the same router.

Steps:
On your iOS device, select WIFI and click on the little (i) icon
Select Manual for HTTP PROXY
Set Server IP to the IP of your computer
Set Port to 8112
Leave authentication empty
On your computer, open Squidman
Set your HTTP Port to 8112.
Go to the Template tab, and paste the following
Replace the highlighted IP with your device's IP
Click on Start Squid

cache_peer %PARENTPROXY% parent %PARENTPORT% 7 no-query no-digest no-netdb-exchange default
cache_dir ufs %CACHEDIR% %CACHESIZE% 16 256
maximum_object_size %MAXOBJECTSIZE%
coredump_dir %CACHEDIR%
visible_hostname %VISIBLEHOSTNAME%
cache_access_log stdio:/Users/dyu/Desktop/access.log
cache_store_log stdio:/Users/dyu/Desktop/store.log
cache_log /Users/dyu/Desktop/cache.log
pid_filename %PIDFILE%
http_port %PORT%
acl SSL_ports port 443
acl Safe_ports port 80  # http
acl Safe_ports port 21  # ftp
acl Safe_ports port 443  # https
acl Safe_ports port 70  # gopher
acl Safe_ports port 210  # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280  # http-mgmt
acl Safe_ports port 488  # gss-http
acl Safe_ports port 591  # filemaker
acl Safe_ports port 777  # multiling http
acl CONNECT method CONNECT
%ALLOWEDHOSTS%
%DIRECTHOSTS%
http_access allow localhost manager 
http_access deny manager
acl allcomputers src 192.168.0.0/255.255.252.0
http_access allow allcomputers
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny to_localhost
http_access allow localhost
%HTTPACCESSALLOWED%
http_access deny all
%ALWAYSDIRECT%
always_direct deny all
hierarchy_stoplist cgi-bin ?
refresh_pattern ^ftp:  1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern .  0 20% 4320

How not to write Javascript

Great tips & tricks from an javascript expert:
http://www.sitepoint.com/google-closure-how-not-to-write-javascript/

Highlights:


When checking if a variable is undefined:

var undefined;
return val !== undefined



When using strings in a switch: 

// use hash instead
obj[key] = 1;
if obj.hasOwnProperty(key);



When looping:
for (var i=0; j=arr.length; i



When converting functions to string for function name:
// str = String(foo);
str = (foo + "");



When checking for string type:
// typeof new String("a string") == 'object'
typeof (new String("a string") + "") == 'string'



When using float points:
// 1.0 - 0.25
1 - 0.25



When initializing arrays it is unnecessary to pre-allocate 'space':
// arr = new Array(25);
arr = [];



In JS, variable scope is declared by functions, and not blocks. That is:
if (a) { var x = 25; } console.log(x); // prints 25 just fine



The difference between:
var foo = function() {} and function bar() {} is that the latter is a function with the name 'bar'. The former is an anonymous function without a 'name'



Arrays are very powerful:
Acting as a queue: push, shift (unshift)
Acting as a stack: push, pop
Acting as array: arr[index], delete arr[index] (sets index content to undefined)
Splicing array: adding & removing elements with arr.splice(index,count,objs...)



Using regex:
var regex = '/regex_exp/i';
regex.test(haystack);



Using enumerative for-loops the right way:
for (var p in pages) { if (pages.hasOwnProperty(p)) { /* do something awesome */ } };
Use the hasOwnProperty method to prevent against enumerating over inherited properties



Don't use document.write(str);
Don't use browser sniffing code, ie. navigator.appName == 'Microsoft IE'
Don't use eval(str)
Don't use pseudo-protocols, ie. link




PHP Codeception

Great functional/BDD testing framework. BEAUTIFUL syntax.

wget http://codeception.com/codecept.phar
php codecept.phar bootstrap
php codecept.phar generate:suite services
php codecept.phar generate:cept services LoginService

Edit services.suite.yml


class_name: ServicesTester
modules:
    enabled:
        - PhpBrowser
        - AcceptanceHelper
        - REST
    config:
        PhpBrowser:
            url: 'http://localhost/'

Alter APACHE PATH environment variables for PHP

In phpinfo(); under Apache Environment section, you will see PATH

On the mac this was stuck at /usr/bin:/bin:/usr/sbin:/sbin

One way to remedy this is to edit the launchDaemon plist file...
vi /System/Library/LaunchDaemons/org.apache.httpd.plist


Add the following key
EnvironmentVariables
PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

Moc'ing XXXX.h... File not found / no such file

There's a couple potential causes for having issue with Moc'ing (QT) files in Visual Studio 201X.

For the most part, the fact that you get this message means that QT plugin is working, so I won't go into trouble-shooting that.


In my case, it had to do with the QTDIR environment variable being 'cached' in the vcproj.user file.

In otherwords, I set my system env QTDIR=c:\qt, and later changed it to c:\qt5

VS continues to use c:\qt due to the vcproj.user file


Stupid VS >:I

Qt 5.3 for VS2010

The QT installer is built for VS2012 by default, and I need binaries and libs for VS2010. Here's how to get the ball rolling.


Luckily, they already compiled it: http://download.qt-project.org/official_releases/qt/5.3/5.3.2/qt-opensource-windows-x86-msvc2010_opengl-5.3.2.exe

Error installing HAXM on Lenovo W510 running Windows Server 2008

Error message #1:

This computer does not support Execute Disable Bit XD.

Error message #2:

This computer does not support Intel Virtualization Technology (VT-x).

Turns out this can all be solved in the BIOS setting.

For the W510
On the boot screen, hit F1
Config > CPU > Intel Hyper-Threading ENABLED
Config > CPU > Intel Virtualization Technology ENABLED
Config > CPU > Intel VT-d Feature ENABLED
Security > Memory Protection > Execution Prevention ENABLED
Security > Security Chip ACTIVE
Security > Intel TXT Feature DISABLED
Hit F10 to save and restart


Coincidentally, the above configuration can also be used to install HYPER-V for WINDOWS SERVER 2008 R2. Speaking of, you must uninstall or disable HYPER-V in order to install HAXM. Failure to do so yields the 2nd error message above.

Setting up SQL Server 2012

This tutorial should work for setting up a brand new SQL Server instance. In this case, I am using SQL Server 2012.
  • If you can't find SQL Server Management Studio, you may need to install it first.
    1. Download SQLManagementStudio_x64_EMU, run setup
    2. During the Feature Selection step, select Management Tools - Basic (or Complete)
    3. After the installation is complete the executable can be located at:
      • C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\ssms.exe
    4. NOTE: Make sure the database supports both Windows authentication and SQL Server Authentication
  • Creating credentials for remote SQL server access
    1. NOTE: If you have the sa user password, you can just use that account to connect remotely
    2. On the SQL Server, sign in as Administrator or sa (If you forgot your sa password, it can be reset)
    3. Once connected to the local DB Engine, go to Object Explorer > SERVERNAME > Security > Logins
    4. Right click on Logins > New Login ...
    5. Under General > enter Login name
    6. Under General > select SQL Server authentication, uncheck Enforce password policy
    7. Under Server Roles > check public, sysadmin
    8. Click OK to save
At this point, you should have properly set up the credentials for remote login. This next section discusses how to set up the server such that it can be accessed remotely. Keep in mind I don't go over my Windows Firewall setup, that'd be on you.
  • On the SQL server, open up Computer Management
  • Expand Services and Applications
  • Expand SQL Server Configuration Manager
  • Select SQL Server Network Configuration
    1. Select Protocols for SERVERNAME
    2. Right click TCP/IP > Enable
    3. Right click > Properties > IP Addresses tab
    4. Note the IP Address (ie. 192.168.1.35)
    5. Enter 1433 for TCP Port (Your firewall needs to open 1433)
    6. Click OK to save
  • Select SQL Server Services, you should see...
    1. SQL Server (SERVERNAME) Running
    2. SQL Server Agent (SERVERNAME) Stopped
    3. SQL Server Browser Running
  • Restart #1 and #3 services listed directly above
At this point you should be good to go. Just 1 last step inputting the correct hostname, username, etc.
  • Server type: Database Engine
  • Server name: 192.168.1.35\SERVERNAME
  • Authentication: SQL Server Authentication
  • Login: Username set up above, or sa
  • Password: Self-explanatory
Done.





Qt Unresolved external symbol QMetaObject error

This one was incredibly frustrating as a Qt noob...

Error   4   error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Counter::metaObject(void)const " (?metaObject@Counter@@UBEPBUQMetaObject@@XZ) 
Error   5   error LNK2001: unresolved external symbol "public: virtual void * __thiscall Counter::qt_metacast(char const *)" (?qt_metacast@Counter@@UAEPAXPBD@Z)
Error   6   error LNK2001: unresolved external symbol "public: virtual int __thiscall Counter::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Counter@@UAEHW4Call@QMetaObject@@HPAPAX@Z)  
Error   7   error LNK2019: unresolved external symbol "protected: void __thiscall Counter::valueChanged(int)" (?valueChanged@Counter@@IAEXH@Z) referenced in function "public: void __thiscall Counter::setValue(int)" (?setValue@Counter@@QAEXH@Z
This happens when you use the Q_OBJECT macro in your class extending QObject. Turns out in Qt you need to call run qmake first in order to invoke the moc compiler. So, the proper solution: 1. Run qmake 2. Build 3. Run

Install Scrapy via cygwin

Take the following with a grain of salt, because I'm not 100% sure all the dependencies, but the following should give you enough info to figure out anything which is missing.



1. Install cygwin64
2. Install cygwin packages: python, python3, libxml2-devel, libxslt-devel, libpcre-devel, libffi-devel, gcc-core
3. Install PIP
- wget https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
4. Install scrapy
- CFLAGS="-I/cygdrive/c/Cygwin64/lib/libffi-3.0.13/include -I/cygdrive/c/Cygwin64/usr/include/libxml2 -I/cygdrive/c/Cygwin64/usr/include/libxslt" pip2.7 install scrapy



In the process I saw lots of:

- fatal error: libffi/ffi.h: No such file or directory
- fatal error: libxml/xmlversion.h: No such file or directory
- fatal error: libxslt/xsltconfig.h: No such file or directory
- error: command 'gcc' failed with exit status 1


Think these were all resolved by adding the CFLAGS includes.

Unknown table engine 'InnoDB'

Sometimes on initial mysql setup, you will find that you can log into the db, use db. But when you select * from table, you get the following error message:
Table 'db.tablename' doesn't exist

This is most likely because the data you are importing was intended for a non-transactional configured database.

To reconfigure the database as a non-transactional one: execute C:/.../MySQL Server X.Y/bin/MySQLInstanceConfig.exe

After this is done, you still need to alter the my.ini configuration file to tell mysql to use the innodb engine. If not you will likely see this error message:
Unknown table engine 'InnoDB'

To which the solution is to make sure you have the following line in your my.ini file:
default-storage-engine=INNODB

PHP with CGI crash with extensions

When enabling PHP extensions, IIS is crashing even for a simple phpinfo() call, that is, as I uncomment extension=php_mssql.dll I immediately get:

HTTP Error 500.0 - Internal Server Error

The FastCGI process exited unexpectedly


Turns out, the issue is that the default php.ini has extension_dir = "./", the fix is to change this to:

extension_dir = "./ext"

Dont forget to restart IIS (Stop & start the server not just the Site).

Setting up host urls in IIS

The following was done in IIS7.

When you add a new website:
Site name: WhateverYouWant
Application pool: Pick the appropriate .NET pool
Physical path: Path to root (can be anywhere on you HDD)
Type: http
IP address: 127.0.0.1
Port: 80
Host name: whatever-you-want.com

Edit C:\windows\system32\drivers\etc\hosts

Add the following line:
127.0.0.1    whatever-you-want.com

Flush DNS in command prompt:
ipconfig /flushdns

Load the page in browser:
http://whatever-you-want.com