<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>tips on Kathleen&#39;s Blog</title>
        <link>https://blog.superfiretruck.com/tags/tips/</link>
        <description>Recent content in tips on Kathleen&#39;s Blog</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <lastBuildDate>Wed, 13 Oct 2010 21:36:00 +0000</lastBuildDate><atom:link href="https://blog.superfiretruck.com/tags/tips/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>Maintaining PHP Sessions Across Multiple Machines</title>
        <link>https://blog.superfiretruck.com/2010/10/maintaining-php-sessions-across/</link>
        <pubDate>Wed, 13 Oct 2010 21:36:00 +0000</pubDate>
        
        <guid>https://blog.superfiretruck.com/2010/10/maintaining-php-sessions-across/</guid>
        <description>&lt;p&gt;As you may know if you&amp;rsquo;ve ever tried to play PhotoCity, the website likes to randomly log you out and make you log back in again before uploading more photos or checking on your progress. The reason is that there are multiple machines in a round robin hosting the website, the website uses sessions, and when a different machine picks up your request, it doesn&amp;rsquo;t know about the session that says you were logged in that the first machine was using.&lt;/p&gt;
&lt;p&gt;How to keep sessions alive and consistent across multiple machines?? Some people told me a load balancer was the answer, but since I don&amp;rsquo;t actually maintain the machines myself, that wasn&amp;rsquo;t an option for me.&lt;/p&gt;
&lt;p&gt;Yesterday afternoon, I had a list of 4 potential things to work on. Vanquishing this obnoxious sessions problem was one of them. True story: I flipped a 4-sided coin/generated a random number in python, got a 3, and set to work investigating cookies vs. sessions and possible solutions. What I learned:&lt;/p&gt;
&lt;p&gt;This is the main website I read:&lt;br&gt;
&amp;lt;http://www.tuxradar.com/practicalphp/10/0/0&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lesson 1:&lt;/strong&gt; &lt;em&gt;Cookies are cool and all&lt;/em&gt; (and look easy to use) and are stored locally, but they are too easy to tinker with. I could have stored a player&amp;rsquo;s ID in a cookie and then checked which player was logged in, but the player could have changed a field in the cookie file to be someone else&amp;rsquo;s player ID and then logged in as someone else.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lesson 2:&lt;/strong&gt; You can write some magic code and make a new table in your database and then trick the &lt;em&gt;PHP session handler to save its data to a centralized database&lt;/em&gt;. I believe sessions also use really small cookies, so basically there is a cookie on the user&amp;rsquo;s computer that tells the database what session ID to look up. The session ID is complicated and hard to guess. E.g. &amp;ldquo;gm6uf16d20k3vt6kjq790q9fp0&amp;rdquo;. Yeah!&lt;/p&gt;
&lt;p&gt;The first step is to make a new table in your own database.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;CREATE TABLE sessions (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, SessionID CHAR(26), Data TEXT DEFAULT &#39;&#39;, DateTouched INT);&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The next step is to write your own session handler/steal this one that I just stole from someone else. Included is a php file that uses the new session handler.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;link: &lt;a class=&#34;link&#34; href=&#34;http://superfiretruck.com/stuff/magical_session_handler.txt&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;magical_session_handler.php&lt;/a&gt; (.txt file)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;link: &lt;a class=&#34;link&#34; href=&#34;http://superfiretruck.com/stuff/hello.txt&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;hello.php&lt;/a&gt; (.txt file)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;(I basically borrowed the code from this page, but that one had a bug or two)&lt;br&gt;
&amp;lt;http://www.tuxradar.com/practicalphp/10/3/7&amp;gt;&lt;/p&gt;
&lt;p&gt;You can play with the actual webpage here and watch sessions be preserved: &amp;lt;http://superfiretruck.com/stuff/hello.php&amp;gt;&lt;br&gt;
Without the special session handler, that page is just really simple example of sessions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lesson 3:&lt;/strong&gt; &lt;em&gt;THERE IS A BUG!&lt;/em&gt;&lt;br&gt;
&lt;a class=&#34;link&#34; href=&#34;http://us2.php.net/manual/en/function.session-destroy.php#51001%20&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;http://us2.php.net/manual/en/function.session-destroy.php#51001&lt;/a&gt;&lt;br&gt;
&amp;lt;http://bugs.php.net/32330&amp;gt;&lt;br&gt;
The super-easy answer:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;By calling session_set_save_handler() again after session_destroy() it will work.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Lesson 4:&lt;/strong&gt; If you want to display the name of the &lt;strong&gt;machine&lt;/strong&gt; currently serving up your webpage (which one in your round robin, for debugging/curiosity purposes) you can write in PHP:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;echo exec(&amp;ldquo;hostname&amp;rdquo;);&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The PHP variable $_SERVER did not have quite enough information for me. However, &amp;lsquo;hostname&amp;rsquo; is a standard unix command so you&amp;rsquo;re just getting PHP to run it for you.&lt;/p&gt;
&lt;p&gt;I haven&amp;rsquo;t transferred this play example to PhotoCity yet, but I will very soon.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>Android Dev Notes</title>
        <link>https://blog.superfiretruck.com/2010/10/android-dev-notes/</link>
        <pubDate>Mon, 04 Oct 2010 07:55:00 +0000</pubDate>
        
        <guid>https://blog.superfiretruck.com/2010/10/android-dev-notes/</guid>
        <description>&lt;img src="https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.46-PM.png" alt="Featured image of post Android Dev Notes" /&gt;&lt;p&gt;I forgot where all the android dev stuff lived because it&amp;rsquo;s been about 6 or 7 months since I used it. So, some notes to myself about what/where things are.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Eclipse&lt;/strong&gt; - Yeah.&lt;br&gt;
&lt;strong&gt;ADT&lt;/strong&gt; - Android Development Tools plugin for Eclipse.&lt;br&gt;
Accessible from within Eclipse, under Preferences.&lt;br&gt;
&lt;strong&gt;SDK and AVD Manager&lt;/strong&gt; - AVD = Android Virtual Devices.&lt;br&gt;
Accessible from within Eclipse, under Window-&amp;gt;SDK and AVD Manager, or by running &amp;lsquo;android&amp;rsquo; from my terminal.&lt;br&gt;
&lt;strong&gt;Emulator&lt;/strong&gt; - Good ol&amp;rsquo; fake phone.&lt;br&gt;
Start one from the AVD Manager. I think I can close the AVD manager after I&amp;rsquo;ve started up a fake phone. Yes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.46-PM.png&#34;
	width=&#34;788&#34;
	height=&#34;451&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.46-PM_hufc1c7bca6bd379f04d0a0e6972db4cf9_91571_480x0_resize_box_3.png 480w, https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.46-PM_hufc1c7bca6bd379f04d0a0e6972db4cf9_91571_1024x0_resize_box_3.png 1024w&#34;
	loading=&#34;lazy&#34;
	
		alt=&#34;ADT eclipse plugin preference page&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;174&#34;
		data-flex-basis=&#34;419px&#34;
	
&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.14-PM.png&#34;
	width=&#34;651&#34;
	height=&#34;364&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.14-PM_hu6b930db585712285490932ebc57081b8_66266_480x0_resize_box_3.png 480w, https://blog.superfiretruck.com/2010/10/android-dev-notes/Screen-shot-2010-10-03-at-11.55.14-PM_hu6b930db585712285490932ebc57081b8_66266_1024x0_resize_box_3.png 1024w&#34;
	loading=&#34;lazy&#34;
	
		alt=&#34;Android SDK and AVD manager!&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;178&#34;
		data-flex-basis=&#34;429px&#34;
	
&gt;&lt;/p&gt;
&lt;p&gt;Also, applications with &lt;strong&gt;maps work better once an api key has been obtained&lt;/strong&gt; (&amp;lt;http://code.google.com/android/maps-api-signup.html&amp;gt;) AND, for some silly reason, the &amp;lsquo;custom debug keystore&amp;rsquo; in android build preferences filled in/set to the same thing as the default debug keystore. I had been getting this error in logcat over and over again, &amp;ldquo;MapActivity Couldn&amp;rsquo;t get connection factory client&amp;rdquo;, until I did those 2 things.&lt;/p&gt;
</description>
        </item>
        <item>
        <title>ImageMagick</title>
        <link>https://blog.superfiretruck.com/2010/09/imagemagick/</link>
        <pubDate>Wed, 22 Sep 2010 05:28:00 +0000</pubDate>
        
        <guid>https://blog.superfiretruck.com/2010/09/imagemagick/</guid>
        <description>&lt;img src="https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-1.59.08-PM.png" alt="Featured image of post ImageMagick" /&gt;&lt;p&gt;This post is dedicated to the 10-years-younger version of myself when I was trying to put a photo album on my website and didn&amp;rsquo;t have an efficient way to resize all my images and make thumbnails. I think I opened them all up in photoshop and developed a fairly quick and repeatable sequence of clicks and key presses to manually resize each image. Basically, I&amp;rsquo;d go into mechanical robot mode, even though I was using a computer capable of automating all that for me.&lt;/p&gt;
&lt;p&gt;These days, if you search &amp;lsquo;batch image resize&amp;rsquo;, you&amp;rsquo;ll find a bunch of pointy-clicky software that will do the job. But I&amp;rsquo;m going to talk about the command line approach, since most of those programs are just awkward GUIs wrapped around this library anyway.&lt;/p&gt;
&lt;p&gt;Behold: ImageMagick! (&amp;lt;http://www.imagemagick.org/&amp;gt;)&lt;br&gt;
Perfect for the teen with the website photo album, perfect for the grad student who deals with a ton of images and photos.&lt;/p&gt;
&lt;p&gt;First: Get it installed. This part is probably the trickiest, and other &lt;a class=&#34;link&#34; href=&#34;http://www.imagemagick.org/script/binary-releases.php&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;places on the internet&lt;/a&gt; can tell you how it&amp;rsquo;s done. Essentially, you can download an installer for any operating system, though you might have to figure out how to change a &amp;lsquo;path&amp;rsquo; or two so your computer knows where to find imagemagick. I believe imagemagick is sexiest when used on linux or mac. I might have tried to get it through cygwin back in my windows days. If you get it through cygwin, you can just check the cygwin install box that says you want imagemagick included. Once it&amp;rsquo;s installed, it&amp;rsquo;s not a program that you launch so much as a COMMAND LINE TOOL that you run with a few sensible arguments that super-easily gets what you want done.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-1.59.08-PM.png&#34;
	width=&#34;543&#34;
	height=&#34;334&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-1.59.08-PM_huca2a0696f76f82f0d0ef93960cdefece_27503_480x0_resize_box_3.png 480w, https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-1.59.08-PM_huca2a0696f76f82f0d0ef93960cdefece_27503_1024x0_resize_box_3.png 1024w&#34;
	loading=&#34;lazy&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;162&#34;
		data-flex-basis=&#34;390px&#34;
	
&gt;&lt;/p&gt;
&lt;p&gt;Try typing &amp;lsquo;convert&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;You don&amp;rsquo;t actually type or run imagemagick anymore, that&amp;rsquo;s just what&amp;rsquo;s responsible for making the &amp;lsquo;convert&amp;rsquo; command available. If it spews a bunch of text about which version, how to use, etc, that&amp;rsquo;s great! That&amp;rsquo;s the documentation that you can look through later to find all the magical things that imagemagick is actually capable of.&lt;/p&gt;
&lt;p&gt;Now for some examples of what I often use the &amp;lsquo;convert&amp;rsquo; command for:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resizing a single image:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;convert -resize 200 boycat.jpg small_boycat.jpg&lt;/p&gt;
&lt;p&gt;(this makes the new image 200 pixels wide.)&lt;/p&gt;
&lt;p&gt;convert -resize x200 boycat.jpg taller_boycat.jpg&lt;/p&gt;
&lt;p&gt;(notice the x before the 200. this makes the new image 200 pixels TALL instead.)&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-2.06.00-PM.png&#34;
	width=&#34;1280&#34;
	height=&#34;800&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-2.06.00-PM_hu6fa8c1e183b3d8087a5ee3df26e351b5_1183445_480x0_resize_box_3.png 480w, https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-2.06.00-PM_hu6fa8c1e183b3d8087a5ee3df26e351b5_1183445_1024x0_resize_box_3.png 1024w&#34;
	loading=&#34;lazy&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;160&#34;
		data-flex-basis=&#34;384px&#34;
	
&gt;Here&amp;rsquo;s an image of the 3 different sizes of the photo of my cat!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resizing multiple images:&lt;/strong&gt;&lt;br&gt;
I have 3 images now of my cats. I want to make thumbnails of each of them. I COULD type out:&lt;/p&gt;
&lt;p&gt;convert -resize 200 boycat.jpg small_boycat.jpg&lt;/p&gt;
&lt;p&gt;convert -resize 200 boycat2.jpg small_boycat2.jpg&lt;/p&gt;
&lt;p&gt;convert -resize 200 girlcat.jpg small_girlcat.jpg&lt;/p&gt;
&lt;p&gt;OR I could type this magical &lt;a class=&#34;link&#34; href=&#34;http://www.cyberciti.biz/faq/bash-for-loop/&#34;  target=&#34;_blank&#34; rel=&#34;noopener&#34;
    &gt;bash for-loop&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;for i in *.jpg; do convert -resize 200 $i small_$i; done&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-2.15.04-PM.png&#34;
	width=&#34;681&#34;
	height=&#34;418&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-2.15.04-PM_hu81f8a51e67ded204b9db327c269f0855_40982_480x0_resize_box_3.png 480w, https://blog.superfiretruck.com/2010/09/imagemagick/Screen-shot-2010-09-12-at-2.15.04-PM_hu81f8a51e67ded204b9db327c269f0855_40982_1024x0_resize_box_3.png 1024w&#34;
	loading=&#34;lazy&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;162&#34;
		data-flex-basis=&#34;391px&#34;
	
&gt;&lt;/p&gt;
&lt;p&gt;You can see that there are now 2 versions of each image and that the &amp;ldquo;small_&amp;rdquo; ones are much smaller in filesize!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Converting between image types:&lt;/strong&gt;&lt;br&gt;
This is so ridiculously easy. You want to make one of your .jpg photos into a .png?&lt;/p&gt;
&lt;p&gt;convert small_boycat.jpg small_boycat.png&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Combining several images into a single image:&lt;/strong&gt;&lt;br&gt;
Sometimes I need to stick a few images together for whatever reason.&lt;br&gt;
There are 6 images in my folder of cat images right now (3 original-sized and 3 smaller ones from the multiple resize command), and I only want to use the 3 small ones. To do so, I use this command:&lt;br&gt;
convert -append small_*.jpg catstrip.jpg&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/catstrip.jpg&#34;
	width=&#34;200&#34;
	height=&#34;402&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/catstrip_hua1c4fba72c52c4ae3529656200845589_21736_480x0_resize_q75_box.jpg 480w, https://blog.superfiretruck.com/2010/09/imagemagick/catstrip_hua1c4fba72c52c4ae3529656200845589_21736_1024x0_resize_q75_box.jpg 1024w&#34;
	loading=&#34;lazy&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;49&#34;
		data-flex-basis=&#34;119px&#34;
	
&gt;&lt;/p&gt;
&lt;p&gt;That makes the image form a tall column, like from a photo booth. It turns out that to make a horizontal montage, change -append to +append!&lt;br&gt;
convert +append small_*.jpg catstrip2.jpg&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/catstrip2.jpg&#34;
	width=&#34;600&#34;
	height=&#34;134&#34;
	srcset=&#34;https://blog.superfiretruck.com/2010/09/imagemagick/catstrip2_huc01d144da62b40954dd663c3d7a5bb40_21166_480x0_resize_q75_box.jpg 480w, https://blog.superfiretruck.com/2010/09/imagemagick/catstrip2_huc01d144da62b40954dd663c3d7a5bb40_21166_1024x0_resize_q75_box.jpg 1024w&#34;
	loading=&#34;lazy&#34;
	
	
		class=&#34;gallery-image&#34; 
		data-flex-grow=&#34;447&#34;
		data-flex-basis=&#34;1074px&#34;
	
&gt;&lt;/p&gt;
&lt;p&gt;There! Cute cats and some useful image-manipulation tidbits. Find out all the other cool stuff you can do with &amp;lsquo;convert&amp;rsquo; here: &amp;lt;http://www.imagemagick.org/script/convert.php&amp;gt;&lt;/p&gt;
</description>
        </item>
        
    </channel>
</rss>
