Snippets
To redirect all requests to HTTPS, place the following code into the vhost configuration file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
php_value session.cookie_secure 1
</IfModule>This jQuery code will select <img> tags that are the only child inside a <p>.
var images = jQuery('p img:only-child');However, the code is no good if we want <img> without anything around, not even texts such as,
<p><img src="foo" />Some text goes here</p>Using DOM properties, previousSibling and nextSibling, does the job.
var images = $('p img:only-child').filter(function() {
return !this.previousSibling && !this.nextSibling;
});This will detect texts as siblings as well, while jQuery methods don't.
Copy and paste the following command to address line and press "Return"data:text/html, <html contenteditable>
Find all .DS_Store files under the directory /Users/jsmith/www
sudo find /Users/jsmith/www -name .DS_Store -depthAnd remove them as well.
sudo find /Users/jsmith/www -name .DS_Store -depth -exec rm {} \;Add the command to crontab so it does it at 10:15am and 3:15pm every day.
# Enter the command and your password when prompted.
sudo crontab -e
# The command should have opened an editor of your choice.
# If an editor is not assigned, you can temporarily assign nano editor.
export EDITOR=nano
# In the editor, enter this line, save it and exit.
15 10,15 * * * root find /Users/jsmith/www -name .DS_Store -depth -exec rm {} \;
I could have removed all .DS_Store files in the system, but doing it with a directory that contains web sites, which can be copied over the network, was good enough for me. Version control softwares usually make exceptions for .DS_Store file by default, so no worry on unwillingly putting them in the code repositories, but it would not hurt to clean them up locally too.
If your local drupal site stopped sending out emails after upgrading to OS X Mountain Lion, run these commands:
sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions (ignore error message after you run it)
sudo /usr/sbin/postfix startSource: http://apple.stackexchange.com/questions/54051/sendmail-error-on-os-x-mo...
When inserting special characters in CSS generated content using :before or :after, use hexadecimal notation.
// Like this
a:after {
content: "\25C2";
}
// Instead of this
a:after {
content: "◂";
}Ref) http://alanhogan.com/tips/css/special-characters-in-generated-content
If you manage to install binaries and run it, that's much simpler. If you need to compile yourself, then these tips can save you some time.
These are prerequisites to installing node.js. You can skip the ones that are already installed.
1) Install g++
$ yum install sudo gcc-c++2) Install bzip2-devel (besides bzip2)
$ yum install bzip2-devel3) Upgrade python to 2.7.3 (from 2.4)
- Node.js requires python 2.6 or 2.7
- If you have 3.0, see https://github.com/joyent/node/wiki/Installation
$ curl -O http://python.org/ftp/python/2.7.3/Python-2.7.3.tgz
$ tar xfz Python-2.7.3.tgz
$ cd Python-2.7.3
$ ./configure
$ make
# You'd need to be either root or a sudoer
$ sudo make installAfter these, I was able to compile node.js without an error. Latest version of node.js may be different from the example.
$ curl -O http://nodejs.org/dist/v0.8.14/node-v0.8.14-linux-x64.tar.gz
$ tar -zxf node-v0.8.14.tar.gz
$ cd node-v0.8.14
$ ./configure
$ make
# You'd need to be either root or a sudoer
$ sudo make installMy php page had a line like,
<?php
shell_exec('wget http://www.example.com/path/to/something');
?>The actual parameters of wget command were more complicated. There were two things I had to resolve. wget command does not come with OS X by default, so you needed to install it first. One of easy ways to install wget is through homebrew, which I already had. I simply ran,
$ brew install wgetRon explained how to install homebrew.
But then I figured that apache running the php page could not find wget command, which is located in /usr/local/bin/wget. I use MAMP and I had to tell MAMP where to look for wget. I opened up text file, /Applications/MAMP/Library/bin/envvars and added the following line in it,
export PATH=$PATH:/usr/local/binStop and start Apache Server of MAMP and the problem was solved.
Run scp to machine R, which is only accessible through gateway machine G.
Step 1: Establish SSH tunnel. Pick a temporary port between 1024 and 32768 (1234 in this example). Port 22 will be used by scp.
$ ssh -L 1234:<address of R known to G>:22 <user at G>@<address of G>
# Adding "cat -" will keep it running while above will get you connected to G
$ ssh -L 1234:<address of R known to G>:22 <user at G>@<address of G> cat -
Either way you run it, open another terminal for next step.
Step 2: Run scp against port 1234 pretending 127.0.0.1 (localhost) is the remote machine R, and the command will be sent to R.
$ scp -P 1234 <user at R>@127.0.0.1:/path/to/file file-name-to-be-copiedReferences:
http://whoochee.blogspot.com/2012/07/scp-via-ssh-tunnel.html
http://www.rzg.mpg.de/networkservices/ssh-tunnelling-port-forwarding
http://www.diffchecker.com
Diff Checker is a free online diff tool that gives you the text differences between two blocks of text.
http://drupal.org/project/odir
This module adds a new organizational layer to drupal, making it easy for managing large numbers of files and nodes. It allows the creation of onthefly directory structures and upload of mutliple files at once. Jpeg files are displayed as slideshows, other files can be downloaded from a block.
This command will bring all changes in trunk since the branch was created (called sync or catch-up).
Caret (^), available since version 1.6, denotes the root of repository so you do not have to specify full URL.
$ cd /to-the-path-of/working-copy-of-the-branch
$ svn merge ^/trunk
# If your project is a subfolder of root (svn represents repository as if they are directory structure).
$ svn merge ^/my-project/trunk
The merged change is still local, so you need to commit the change.
$ find . | xargs wc -lTo limit to certain file types such as inc, php, and module
$ find . -type f | egrep "\.(inc|php|module)$" | xargs wc -lA small, customizable plugin for scrolling elements, or the window itself.
http://demos.flesler.com/jquery/scrollTo/
onScreen is a jQuery plugin to detect whether an element is currently visible on-screen. It adds the :onScreen selector which you can use like so: $("span:onScreen").
http://benpickles.github.com/onScreen/
These svn commands are not particularly version 1.7, but works well with upgrading Drupal modules.
After replacing module folders and when ready to commit the code change to svn repository:
# Remove dropped files
$ svn st | grep '^!' | awk '{print $2}' | xargs svn rm# Add new files
$ svn st | grep '^?' | awk '{print $2}' | xargs svn add# To add, this works too (Make sure you are at directory level that has no ignored files; otherwise --force will add ignored files as well)
$ svn add --force .# Commit
$ svn ci -m "Upgraded a module."If you are using svn 1.6, overwrite folders instead of replacing to keep hidden .svn folders. Then the command above should work too. There will be no files getting dropped when overwriting.
If you want to edit a hidden file (such as .htaccess) without dropping into Terminal, on [Open Files] dialog of a text editor, enter Shift-Command-. (dot).
Wish Finder has the feature too? A little work with Automator can achieve close enough effect.
More info on how to do this.
Install NTFS-3G and MacFuse.
OS X already reads and writes to FAT32 formatted drive, and can read from NTFS formatted drive. Snow Leopard has built-in write support to NTFS, but it is inactive due to known instability. If you don't need file access permissions and know that every file will be less than 4GB size, you could consider using FAT32 format.
More info
# Find all .svn directories under current directory (see dot).
$ find . -type d -name .svn
# Delete all .svn directories found; note tick(`).
$ rm -rf `find . -type d -name .svn`
The Override Node Options module allows permissions to be set to each field within the Authoring information and Publishing options field sets on the node form. It also allows selected field sets to be set as collapsed and / or collapsible.
http://drupal.org/project/override_node_options
If you don't want to save strings in clear text, there are new php functions (php >= 5.3.0) that can be of help; openssl_encrypt() and openssl_decrypt().
<?php
$string = "This is a readable string."
$password = "p@ssword";
$method = "aes-256-cbc";
$encrypted = openssl_encrypt($string, $method, $password);
echo "$string => $encrypted";
// Outputs: This is a readable string. => OeOiTWcgIPC1xIZaDJ3XTEaY/D4m1sQmxgPbzjxxlRA=
$decrypted = openssl_decrypt($encrypted, $method, $password);
echo "$encrypted => $decrypted";
// Outputs: OeOiTWcgIPC1xIZaDJ3XTEaY/D4m1sQmxgPbzjxxlRA= => This is a readable string.
?>According to http://stackoverflow.com/questions/1391132/two-way-encryption-in-php, these are possible values for encryption methods.
aes-128-cbc, aes-128-cfb, aes-128-cfb1, aes-128-cfb8, aes-128-ecb, aes-128-ofb, aes-192-cbc, aes-192-cfb, aes-192-cfb1, aes-192-cfb8, aes-192-ecb, aes-192-ofb, aes-256-cbc, aes-256-cfb, aes-256-cfb1, aes-256-cfb8, aes-256-ecb, aes-256-ofb, bf-cbc, bf-cfb, bf-ecb, bf-ofb, camellia-128-cbc, camellia-128-cfb, camellia-128-cfb1, camellia-128-cfb8, camellia-128-ecb, camellia-128-ofb, camellia-192-cbc, camellia-192-cfb, camellia-192-cfb1, camellia-192-cfb8, camellia-192-ecb, camellia-192-ofb, camellia-256-cbc, camellia-256-cfb, camellia-256-cfb1, camellia-256-cfb8, camellia-256-ecb, camellia-256-ofb, cast5-cbc, cast5-cfb, cast5-ecb, cast5-ofb, des-cbc, des-cfb, des-cfb1, des-cfb8, des-ecb, des-ede, des-ede-cbc, des-ede-cfb, des-ede-ofb, des-ede3, des-ede3-cbc, des-ede3-cfb, des-ede3-cfb1, des-ede3-cfb8, des-ede3-ofb, des-ofb, desx-cbc, rc2-40-cbc, rc2-64-cbc, rc2-cbc, rc2-cfb, rc2-ecb, rc2-ofb, rc4, rc4-40, seed-cbc, seed-cfb, seed-ecb, seed-ofb
If you don't know what to choose, try "aes-256-cbc". AES is said to be used by U.S. government.
For alternatives that can be used in older PHP versions, check out, http://us2.php.net/manual/en/refs.crypto.php.
Don't use two-way encryptions on passwords. They should be encrypted with one-way hash functions.
See the beginning of a file.
$ head foo.logSee first 25 lines.
$ head -n 25 foo.logSee the end of the file.
$ tail foo.log"Follow" a log file that is being updated.
$ tail -f foo.logExtract files from a tar file (see x in the arguments).
$ tar -xvf foo.tarExtract gz compressed tarball.
$ tar -xvzf foo.tar.gz
$ tar -xvzf foo.tgztar seems to work without z as well.
$ tar -xvf foo.tar.gzExtract one file.
$ tar -xvzf foo.tgz onefile.phpCreat a tar file and zip it (see c in the arguments).
(tar allows arguments with no dash for historical reason)
$ tar cvzf foo.tgz *.php *.txt
$ tar cvzf foo.tgz mydirectory