If you need to request some data asynchronously via AJAX one option is to use the Ajax.request object from prototype. If you call/create this object you can create a callback function for when the function completes (onComplete) and this will have the return data in it ready for you to process.
In my case I used my Rails controller to return JSON data first on the backend:
result_lat_lon = processNgaNums(params[:map])
respond_to do |format|
format.json { render :json => result_lat_lon.to_json}
end
Then on the client side I created an ajax request:
new Ajax.Request(path, {
asynchronous:true,
evalScripts:true,
method:'get',
onComplete: function(transport){
var json = transport.responseText.evalJSON();
jQuery.each(json, function(i, val){
locations.push([i, val[0], val[1]]);
});
setMarkers(map, locations);
}
});
The main block of code to take note of here is to declare the transport variable which the onComplete function will receive when it is called. Then you can do an evalJSON on that text and treat it as an array. Also in the loop to process the JSON each entry contains a key and a value which corresponds to the i and val variables.
Posted 2 days, 1 hour ago at 10:26 am. Add a comment
>> arr = []
=> []
>> arr << [3,2,1]
=> [[3, 2, 1]]
>> arr<< [1,2,3]
=> [[3, 2, 1], [1, 2, 3]]
>> arr << [2,1,3]
=> [[3, 2, 1], [1, 2, 3], [2, 1, 3]]
>> arr.sort{ |a,b| a[0] <=> b[0]}
=> [[1, 2, 3], [2, 1, 3], [3, 2, 1]]
Posted 1 month, 3 weeks ago at 9:26 pm. Add a comment
On OSX,
Open Safari and go to Preferences
Under the Advanced tab, check “Show Develop menu in menu bar”.
Safari’s menu go to Develop->User Agent->Mobile Safari (there should be multiple versions) pick the most appropriate
Posted 5 months, 3 weeks ago at 12:15 pm. Add a comment
These instructions are to allow you to increase the size of a virtual machine’s harddrive. This was done on an ESX 4.0 system running ubuntu 8.10 with thin provisioning, meaning the harddrive only takes up as much space as it uses. The main problem was that the swap partition was created after the primary partition, so it would not allow the primary to expand to the “right” of the swap. The solution was to delete the swap and then reallocate the partition, then recreate the swap.
This command may be done via ssh access to ESX to change the VM to use thin provisioning.
vmkfstools -i Ubuntu-s001.vmdk new.vmdk -d thin -a lsilogic
-increase the size from the vsphere client of the hardrive in question
-load gparted iso and set it to boot on startup from vsphere client
-Make sure the cd-rom is “conenct at power on”
-I deleted the linux swap partition (turned it off first) by right clicking on the swap partition
-then I was able to resize my primary partition
-recreated the swap partition at the end [primary + additional partition][swap]
Doing a “df -h” shows that the disk space was automatically recognized by Ubuntu after running gparted.
Posted 7 months, 1 week ago at 12:49 pm. Add a comment
Original info was found here. It was posted about 3 years ago, so JQuery has changed a little since then with the implementation of JQuery.noconflict().
In a nutshell, just in clude JQuery first and then include the other libraries(s) that may use the $( function. Make sure you call JQuery stuff with JQuery(xxx) instead of $( from now on. You include JQuery in rails usually in your main layout file by typing:
<%= javascript_include_tag ‘jquery’ %>
Make sure the jquery download files are in your /public/javascript directory of your project.
The JQuery site suggested adding the noconflict at the end of the jquery.js file, but instead I did it this way in the layout file.
<script>jQuery.noConflict(); </script>
Posted 9 months ago at 2:10 pm. Add a comment
Put the below code in to your model. I found this info on railsforums.com.
HUMANIZED_COLUMNS = {
:Column_name => “New Name”,
:OtherColumn_name => “New Name 2″
}
def self.human_attribute_name(attribute)
HUMANIZED_COLUMNS[attribute.to_sym] || super
end
Posted 9 months ago at 2:01 pm. Add a comment
Installing ESXi 4.0 as the base metal Hypervisor OS. I tried to use converter to create a VM image of various redhat machines. Problems encountered with Converter:
1. Failed: File is larger than the maximum size supported by datastore
Solution: Split up the files to different datastores, or use Thin instead of Flat so it only takes the space used and not the full amount of allocated space for a partition.
2. Failed: MethodFault.summary
Solution: Changed number of processors from 8 to 4, because my VM server only has one quad core processor.
3. Failed: Unable to obtain the IP address of the helper virtual machine.
Solution: Assign a DHCP or static IP to the “Helper VM Network” at the bottom of the configuration. Edit this value.
4. Failed: An error occurred during the conversion. Error: Failed to clone the volume mounted on ‘/boot’
Solution: Add the DNS suffix to the Helper VM Network. Also, I needed to add the IP address to the hosts.allow in my Redhat Linux of the Helper VM, that I assigned in #3 from above.
UPDATE
5. Error: Failed to clone the volume mounted on ‘/’
Solution: again this was a problem with the fact that the machine to duplicate had the security settings setup to block the helper VM. I had to add the entry into the hosts.allow. But I can see other potential problems with the firewall (i.e. iptables) where certain ports must be open. Here is a link to vmware showing which ports to open.
Posted 11 months, 3 weeks ago at 11:47 am. 3 comments
I needed to do capture an existing physical machine to virtual (P2V) of an old linux box that was getting on in age. I thought that VMWare would be the clear solution to capture this through the VMWare Converter tool. Unfortunately, Converter doesn’t directly support capturing a linux machine.
The solution I found was to create a virtual VMWare ESXi OS install on my VMWare Workstation. This was not very straight forward as ESXi 4.0 is only for 64-bit systems. I found that ESXi 3.5 was 32-bit and decided to give it a try. For some reason the ESXi install would not proceed correctly choosing to throw PANIC errors. Later I realized that it was due to the fact that I did not allocate enough RAM to this machine. The default value was 256MB and the solution was to up that value to over 1GB of RAM. Then, I would get stuck during the installation in the first 10% or so and would just not move on. I found the solution through a youtube video which showed that I need to select an Intel VT option for the processor settings. This allowed me to continue with the installation.
Note: On a Dell Quad-core server I had to enable the hardware Intel VT instructions. Otherwise the installation of ESX may hang.
More to come…
ESXi booted up with some lvm error, but for some reason, I could not get an IP address. Edited my myvmName.vmx file with note pad and added the blow lines.
Check out this video here
monitor_control.restrict_backdoor = “TRUE”
monitor_control.vt32 = “TRUE”
SMBIOS.reflectHost = “TRUE”
ethernet0.VirtualDev = “e1000″
After that I was able to get a DHCP address! In my production environment we use static ip addresses, so for now I had to switch it to use NAT.
Now I can use Converter to capture a base virtual image of my remote physical machine. Make sure to give root remote access rights and use the IP address of your server as the source. For the destination, in a p2V situation using linux we can only use ESXi and so we need to capture to a VMWare Infrastructure virtual machine. The IP address is that of your virtual ESX installation and don’t forget to set a root password, otherwise it will not work.
After the image was transferred, I used converter again to bring it over from the VMWare Infrastructure virtual machine to the VMware Workstation or other VMware virtual machine. This allows me to open the vm from workstation instead of from ESX. At some point I may deploy to an ESX installation but for now I am content to access my linux box from workstation.
Posted 11 months, 4 weeks ago at 8:13 pm. Add a comment
Was having a big issue with selinux limiting access to my old legacy cgi-scripts in apache. Ended up removing selinux restrictions from this particular script file.
chcon -h -t httpd_unconfined_script_exec_t slides_by_pcd /usr/local/apache/cgi-bin/my_script
Some of the symptoms from apache access_log included :
1. Can’t open perl script
2. Premature end of script headers
Posted 1 year ago at 2:17 am. Add a comment
Typing \n printed out \n, typing <br/> printed <br/> in the text area.
Until I found this:
Posted 1 year, 1 month ago at 9:59 am. Add a comment