Skip to content

Instantly share code, notes, and snippets.

View jonathanpbailey2's full-sized avatar

Jonathan Bailey jonathanpbailey2

View GitHub Profile
@jonathanpbailey2
jonathanpbailey2 / osx_docker_port_forwarding
Created March 11, 2015 23:48
OSX Boot2Docker/VirtualBox Port Forwarding
VBoxManage controlvm boot2docker-vm natpf1 "name,tcp,127.0.0.1,8080,,8080"
@jonathanpbailey2
jonathanpbailey2 / mysql_qry_to_csv
Created February 3, 2015 23:32
Execute a MySQL query and save as CSV
mysql -u [user name] -p [db name] -B -e "[select query]"| sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > output.csv
@jonathanpbailey2
jonathanpbailey2 / vim_num_list
Created May 5, 2014 00:16
Insert numbered list at beginning of each line starting with line 2
:2,$ s/^/\=printf('%d,', (line('.') - 1))
@jonathanpbailey2
jonathanpbailey2 / disable_root_ssh
Created March 4, 2014 15:44
Disable root login via SSH. Why? Because it's not secure.
First change the following line in /etc/sshd/sshd_config
from:
PermitRootLogin yes
to:
PermitRootLogin no
Then restart the service:
either
@jonathanpbailey2
jonathanpbailey2 / jpa2_find_max_of_many_attribute
Created February 11, 2014 21:54
JPA2 CriteriaBuilder - Select a MAX() value from a set of attributes that are in a @xToMany relationship
CriteriaQuery<Integer> yourQuery = criteriaBuilder.createQuery(Integer.class);
Root<YourRootClass> rootClass = yourQuery.from(YourRootClass.class);
Join<YourRootClass, YourManyAttributeClass> theAttribute = rootClass.join("theAttributes");
Expression<Integer> attributeFieldToCheck = theAttribute.get("attributeFieldToCheck");
yourQuery.select(criteriaBuilder.max(attributeFieldToCheck));
Integer maxValue = 0;
try {
maxValue = getEntityManager().createQuery(yourQuery).getSingleResult();
@jonathanpbailey2
jonathanpbailey2 / get currency symbol in magento
Created January 26, 2014 18:50
Gets currency symbol for current locale in Magento.
$currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
@jonathanpbailey2
jonathanpbailey2 / bash for loop int range
Created January 20, 2014 21:56
Bash for loop with integer range
for i in {1..5000}; do echo 'Doing something 5000 times'; done
@jonathanpbailey2
jonathanpbailey2 / perl search and replace
Created January 16, 2014 15:59
Search and replace text in file(s) from BASH prompt using perl
perl -pi -e "s:toSearch:toReplaceWith:g" path/to/file(s)