Software > Cheat Sheets > Other
- Getting WordPress to work with SE Linux
- Getting Excel to change delimiter (Windows)
- Removing frame around inserted image in AutoCAD
- Setup Fedora as a webserver
- Getting mod_rewrite to work
- Changing what turns on at boot in Fedora
- Accessing external MySQL database form a mobile
- Installing sox without root
- Cleaning up WordPress databases
- Getting around AutoCAD opening menu on dash
- Adding a custom WordPress post type
- Modifying struts configuration
- Modifying "More Fields" WordPress plugin to work with new TinyMCE
- Adding AdMob to a Cordova/PhoneGap project
- Making Cordova external links open in Safari browser
- Freeing disk space on a Fedora instance
- Deleting recent files on Windows usind command prompt
Getting WordPress to work with SE Linux As of Fedora 21
chown -R apache:apache /var/www/html/ chcon -Rt httpd_sys_content_t /var/www/html
setenforce 1 chcon -R -t public_content_rw_t <web root> setsebool -P allow_httpd_anon_write on setsebool -P httpd_can_network_connect on /* Also */ chown -R apache:webgroup <web root>
Getting Excel to change delimiter (Windows) Excel uses the regional language options set by the OS. To change this:
- Go to Control Panel > Regional and Language Options > Customize
- Change List separator to whatever character(s) you want.
Windows 7
- Go to Control Panel > Clock, Language and Region > Region & Language
- On "Formats" tab, click Additional Settings button on bottom.
- Change List separator to whatever character(s) you want.
Removing frame around inserted image in AutoCAD
IMAGEFRAME 0
Setup Fedora as a webserver
yum -y install httpd php mysql mysql-server php-mysql #Open /etc/httpd/conf/httpd.conf #Add the following lines: AddType application/x-httpd-php .html .htm AddType application/x-httpd-php .php #Append index.php to this line DirectoryIndex index.html index.html.var index.php
Getting mod_rewrite to work
#modify /etc/httpd/conf/httpd.conf #In the directory you want effected LoadModule rewrite_module modules/mod_rewrite.so Options Indexes FollowSymLinks AllowOverride FileInfo
Changing what turns on at boot in Fedora
#turn on httpd and mysqld on boot chkconfig httpd on chkconfig mysqld on #turn on/off a daemon in session service httpd start service httpd stop
Accessing external MySQL database form a mobile On Mobile (via PhoneGap/Cordova)
function selectDB(dbNum) { document.getElementById("dbResult").innerHTML = "Loading..."; document.getElementById("dbTitle").innerHTML = "Database " + dbNum; $.ajax({ url: 'http://www.pereanu.com/health/backend.php?num=' + dbNum, dataType: 'jsonp', jsonp: 'jsoncallback', timeout: 10000, success: function(data, status){ $.each(data, function(i,item){ document.getElementById("dbResult").innerHTML = item.name; }); }, error: function(){ document.getElementById("dbResult").innerHTML = 'Connection took too long. Try again.'; } }); }
<div data-role="page" id="page_menu"> <div data-role="content"> <center> <br /><br /> <a href="#page_showDB" data-transition="slide" onClick='selectDB("1")' >Database # 1</a> <br /><br /> <a href="#page_showDB" data-transition="slide" onClick='selectDB("2")' >Database # 2</a> </center> </div> </div> <div data-role="page" id="page_showDB"> <div data-role="content"> <center> <div id="dbTitle"></div> <table border="1"> <tr><td align="center"><strong>Patient Name</strong></td></tr> <tr><td align="center"><div id="dbResult">Loading...</div></td></tr> </table> <br /><br /> <a href="#page_menu" data-transition="slide" data-direction="reverse">Select a different DB</a> </center> </div> </div>On server
$server = "host_IP"; $username = "username"; $password = "password"; $database = "db_name"; $table = "table_name"; $con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error()); mysql_select_db($database, $con); $sql = "SELECT name FROM " . $table; $result = mysql_query($sql) or die ("Query error: " . mysql_error()); $records = array(); while($row = mysql_fetch_assoc($result)) { $records[] = $row; } mysql_close($con); echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
Installing sox without root
Download sox tar zxvf sox-14.4.0.tar.gz cd sox-14.4.0 ./configure --prefix=/home/sox make -s && make install
Cleaning up WordPress databases WordPress stores post/pages drafts indefinitely which can take up a lot of space. This SQL statement will delete
DELETE FROM wp_posts WHERE post_status="trash"; DELETE FROM wp_posts WHERE post_status="auto-draft"; DELETE FROM wp_posts WHERE post_status="draft"; DELETE FROM wp_posts WHERE post_status="inherit" AND post_type!="attachment";
Getting around AutoCAD opening menu on dash When typing a dash “-” on most newer versions of AutoCAD, a drop-down menu will open (this appears to be similar to pressing ALT and then down). This gets in the way when you type negative values in any command (for example, “@12′&-90"). One way around this is to turn off the drop-down menubar completely. To do this:
MENUBAR 0The menubar can be turned on at any time by simply:
MENUBAR 1
Adding a custom WordPress post type Creating a custom post type in WordPress requires changing your function.php file. This can be found in the /wp-contents/themes/<theme name>/ path. To do this, add the following to the bottom of the file:
add_action( 'init', 'create_hacks' ); function create_hacks() { $labels = array( 'name' => _x('Hacks', 'post type general name'), 'singular_name' => _x('Hack', 'post type singular name'), 'add_new' => _x('Add New', 'Hack'), 'add_new_item' => __('Add New Hack'), 'edit_item' => __('Edit Hack'), 'new_item' => __('New Hack'), 'view_item' => __('View Hack'), 'search_items' => __('Search Hacks'), 'not_found' => __('No Hacks found'), 'not_found_in_trash' => __('No Hacks found in Trash'), 'parent_item_colon' => '' ); $supports = array('title', 'editor', 'custom-fields', 'revisions', 'excerpt', 'thumbnail', 'comments'); register_post_type( 'hack', array( 'labels' => $labels, 'public' => true, 'supports' => $supports ) ); }
Modifying struts configuration Adding a page requires setting up a path, an action and then restarting the server with the new configuration. Modifying the struts-config.xml file, located in WEB-INF:
<action path="/WC_Autism" type="org.mindspec.autdb.web.actions.DbSearchAction" name="dbQuery" scope="request"> <forward name="success" path="wcautism"/> </action>Modifying the tiles-def.xml file, located in WEB-INF:
<definition name="wcautism" extends=".layout_main"> <put name="title" value="AutDB - Autism"/> <put name="body" value="/WEB-INF/pages/WC_Autism.jsp"/> </definition>Restart tomcat, found in /bin.
./shutdown.sh ./startup.sh
Modifying "More Fields" WordPress plugin to work with new TinyMCE The "More Fields" plugin allows you to add custom fields within the WordPress GUI. At some point, the TinyMCE editor that is used for the WYSIWYG fields will stop working. This can be fixed by updating the javascript call that turns it on. The file to modify is "wp-content/plugins/more-fields/more-fields-field-types.php". Line 40 should be replaced with:
tinyMCE.execCommand("mceAddEditor", false, "%key%");
Adding AdMob to a Cordova/PhoneGap project On a command-line terminal:
cordova create AAA com.neromike.AAA AAA cd AAA cordova platform add ios cordova plugin add org.apache.cordova.console
In XCode, add the entire folder of AdMob files ("googlemobileadssdkios.zip") to the project.
In XCode, go to "Build Phases", then "Link Binary with Libraries" and add the following:
- AdSupport
- AudioToolbox
- AVFoundation
- CoreGraphics
- CoreTelephony
- EventKit
- EventKitUI
- MessageUI
- StoreKit
- SystemConfiguration
Edit the "Classes/MainViewController.h" file:
Add #import "GADBannerView.h" under the other import statements.
Modify the MainViewController to:
@interface MainViewController : CDVViewController { GADBannerView *bannerView_; } @end
Edit the "Classes/MainViewController.m" file:
Add the following lines to "webViewDidFinishLoad"
// Initialize the banner at the bottom of the screen. CGPoint origin = CGPointMake(0.0, self.view.frame.size.height - CGSizeFromGADAdSize(kGADAdSizeBanner).height); // Use predefined GADAdSize constants to define the GADBannerView. bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:origin]; // Specify the ad unit ID. bannerView_.adUnitID = @"ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX"; // Let the runtime know which UIViewController to restore after taking // the user wherever the ad goes and add it to the view hierarchy. bannerView_.rootViewController = self; [self.view addSubview:bannerView_]; // Initiate a generic request to load it with an ad. [bannerView_ loadRequest:[GADRequest request]];
Making Cordova external links open in Safari browser Add the following to each HTML page with external links. Requires jQuery.
$(document).on('click', 'a', function (event) { event.preventDefault(); window.open($(this).attr('href'), '_system'); return false; });
Freeing disk space on a Fedora instance Our m2.medium EC2 instance has a small 10GiB volume that unfortunately filled out quickly.
We have two main sources of large files:
-
Big and Recent Files
Starting at '/', use the following command and move up directories to find large files. This will help find files that can potentially be deleted.
du -h --max-depth 1
Recent files can be found using a find command and choosing how many minutes back you want to see:find -cmin -N
-
Log files
Most log files are located in '/var/log'. We have Apache TomCat running which also keeps logs in '/opt/apache-tomcat-X.X.XX/logs/'.
-
Yum Cache
yum clean all
0 * * * * rm -f /opt/apache-tomcat-6.0.44/logs/* 0 * * * * rm -f /var/log/cron* 0 * * * * rm -f /var/log/cloud* 0 * * * * rm /var/log/httpd/rewrite_log 0 * * * * rm /var/log/httpd/access_log 0 * * * * rm -f /var/log/httpd/audit/audit* 0 * * * * rm /var/log/lastlog 0 * * * * rm -f /var/log/dmesg* 0 * * * * rm -f /var/www/usage/usage* 0 0 * * * yum clean all
>Deleting recent files on Windows usind command prompt Deletes all text files recursively that were made in the same day.
forfiles /s /d +0 /m *.txt /c "cmd /c del @path"