Tuesday, October 17, 2023

Using hilite.me

I discovered that you can use hilite.me to format source code so it looks nice on blogger.

Paste the source into hilite.me. It gives you pretty html that you can paste into an html editor

print("Hello World");

Write code that uses django's settings.py file if django is installed

 

I'm writing a library file for django, and I want it to store settings in the settings.py file, which is django's default configuration location for settings. However, I still want the library to work if django isn't installed. Here's how I did it :

You can wrap an import statement in a try except block

This way, it doesn't crash if the reference doesn't exist

try:
    from django.conf import settings
except ImportError:
    pass

Test to see if the referenced object exists before using it in code

Research online said python doesn't have a direct way to check if the reference exists, so you can use a try / except block instead

try: settings
   except NameError: settings = None

Test to see if 'settings' is None

If settings exists, use the django settings.py file. Otherwise use a flat file

if settings != None:
   if not settings.configured:
      settings.configure()
      self._key_list = settings.MY_LIB_SETTINGS
   else:
      filename = "lib_api_config.txt"
      f = open(filename,"r")
      file_contents = f.read()
      f.close()
      self._key_list = json.loads(file_contents)

Friday, April 14, 2023

ArcGIS Developer Account "Hello World"

I just signed up for an ArcGIS developer account here. I'm working with the javascript developer SDK, and found some issues with the example code found in the edit api link tab

The edit api page has a sample html / javascript code that you can put on your server to display a "Hello World" type application that displays a map.


I had some issues, which I've noted above

  • The api key needs to be surrounded in quotes
  • The first time I loaded the page, I got a bunch of errors because I didn't expand the bottom section before I copied the code out of the editor with the "copy" button
Once I fixed these issues, I got a pretty map of highway 1 in Malibu.  Hooray!

Friday, March 30, 2012

How to Install / Uninstall VMware on SUSE

This page tells me how to unistall VMware on SUSE linux.  I was having trouble finding it.  Now I have.

Thursday, July 28, 2011

Placekitten.com : Placeholder images for demos




Found a new site called placekitten.com that auto-generates placeholder images.  Just pass the image size in the url, like this : http://placekitten.com/g/200/300

Tuesday, July 19, 2011

JQuery templates and tables : use tbody tag

Lets say you have a table, and you want to hide and show a couple of rows with JQuery.  If you're obsessed with div tags, you might try something like this :
<table id="tbData">
<tr><td>Name</td><td>Phone</td></tr>
<div id="phoneList">
</div>
</table>
You set up a template like this :
<script id="phoneTmp" type="text/x-jquery-tmpl">
<tr><td>${firstname},${lastname}</td><td>${address}</td><td>${phone}</td></tr>
</script>
If you do this, your header will show up at the bottom of the table in Firefox, but Internet Explorer will hate you. Or you will hate Internet Explorer. One of those. I get confused. The solution : use tbody tags instead of div tags when you're inserting, showing, or hiding rows in a table with jquery. This forces me to break my longstanding policy of not using any html tags developed after 2000, but it's saved me a lot of headaches.
<table id="tbData">
<tr><td>Name</td><td>Phone</td></tr>
<tbody id="phoneList">
</tbody>

</table>
Click "Result", or the little "play" arrow to see what this code does



JSFiddle : Javascript example website

JSFiddle lets you create editable javascript examples similar to those found on my previous post.  You can create an account and start building examples that other people can play with.  I'm looking forward to trying it out, but for now, I'll show what their examples look like when embedded in a page.

The example window needs to be 500px wide, or it won't work. I had to mess with my blog settings and make the main window wider to get it to work.

It looks like you can't edit the code and experiment with it when the code is embedded in another page. You have to go to the main site here to do that. So it's not as great as I thought it would be. Still useful for complicated examples though.

The following is one of their default examples that uses jquery to display a message and do an animated fade after a second.  Click the "run" arrow, or the "result" tab to see what the code does.






Monday, July 11, 2011

javascript isNumeric

My google search for a javascript isNumeric function yielded almost no useful information, so I thought I'd post something about validating data quickly using regular expressions.  If you are validating a form, you can use the jquery validation library for this, but I wanted something simpler.

On w3schools, I noticed that javascript supports the regular expression syntax that you'd use in perl or vi. 
var patt=/pattern/modifiers;
In my case, I wanted to see if my string contained anything that wasn't a number, period, or dollar sign.  The following code does the trick
function isNumeric(str) {
   var alpha = /[^0-9$.]/g
   return !alpha.test(str);
}
The regular expression [^0-9$.] searches the string for any character that isn't a number (0-9), a dollar sign, or a period. Alpha.test returns true if any "bad" characters are found.  If alpha.test is false, then we have a valid number




JQuery Templates

JQuery templates let you seperate data from display code on the client. I'll explain why this is useful in future posts (if I get around to it). For now, I'll show you how it works.

First, I include the jquery library, and the jquery Template library.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
Next, I embed a JSON string on my page. (This is javascript, so it goes in javascript tags).
var strData = '[{"firstname":"Dave","lastname":"Stillman","phone":"555-1212","address":"555 1212 Road, Nampa, ID"},{"firstname":"Donald","lastname":"Trump","phone":"555-5512","address":"255 Somewhere Lane, New York NY"}]';
I use eval to turn my json string into a javascript object.
var data = eval("(" + strData + ")");
 Next, I create a template script.  I create it the same way I would include inline javascript in a page, but I give it type='text/x-jquery-tmpl' instead of type='javascript'.  I also give it a unique ID, so I can access it later.
<script id="addressTmp" type="text/x-jquery-tmpl">
<b>${firstname},${lastname}</b><br>
${address}<br>
${phone}<br>
</script>
Next, I add a div where I want the data to be displayed
<div ID="addressDiv" />
Finally, I use a jquery template command to display the data
$("#addressTmp").tmpl(data).appendTo("#addressDiv");
Links

Continue reading to view source code and a live demo

Tuesday, September 1, 2009

Tuesday, July 28, 2009

Accessing a web service through javascript

You have to add the service reference to the service reference section of the web.config (I think).

Do a google search for ServiceReference.  That might help too.

Web services EnableSession = true

By default, Web Services can't access session information from the website.  To enable this, add [EnableSession=true] above the function definition.

Getting rid of scroll bars using CSS

In cascading style sheets, you can use the "overflow" or "overflowx" property to get rid of scroll bars.   You can use "scroll" or "scrollx" to show scroll bars.

Wednesday, July 15, 2009

JICS and Google Analytics

Google Analytics and JICS : ICS-L

Could use this for page usage tracking

Auto Login with Novell and Javascript

Use javascript nwdirlib object : C#Corner Forums
Says you can use the following javascript to retrieve the username

LdapObj = new ActiveXObject("NWDirLib.NWDirCtrl.1");
entry=LdapObj.FindEntry(LdapObj.LoginName);
usrId=entry.ShortName

More nwdirlib sample code : stackoverflow.com

This method is susceptible to url hacking.

Tuesday, July 14, 2009

Custom reports in PDF

Info on Point Loma's report generator - ICS-Dev-L

Winnovative PDF : Shareware PDF tool used at Point Loma
Dynamic PDF : My favorite PDF tool
iTextSharp : Free PDF tool written in C#
PDFizer : Free HTML to PDF converter

Logging errors to the Event Log

Logging errors to the Event Log : ICS-Dev-L

Connecting to CX using SQL

JICS 7 methadology for connecting to an ERP database : ICS-Dev-L
InformixHelper.zip : ICS-Dev-L Helper function for connecting to Informix databases

Copying a portlet

PDF on how to copy a portlet : JAM 2008 presentation