rem We can run a process remotely with psexec
rem
rem cmd /C allows us to run a process in a cmd window and it automatically terminates
for /l %a in (1,1,50) do psexec \\station-%a cmd /C "move c:\path\to\folder c:\path\to\backup"
rem Now lets replace that folder with a new one using xcopy
rem
rem We use our local copy of the folder c:\path\to\folder and copy it to each station
rem
rem /S /E /H /I switches for xcopy ensure that we get hidden files, sub directories, and empty directories. /I assumes that the destination is a folder.
for /l %a in (1,1,50) do start cmd /k "xcopy /S /E /H /I c:\path\to\folder \\station-%a\c$\path\to\folder"
Wednesday, June 24, 2009
Wednesday, June 17, 2009
Get mac serial no from terminal
system_profiler SPHardwareDataType | grep "Serial Number" | sed 's/Serial Number://'
Tuesday, June 16, 2009
Php basics : error handling, tests, array functs, classes, and scope
Checking if a file exists
if (file_exists($some_file)){
...
}
Basic Error Handling
function($var) or exit("some error");
Printing an array
print_r();
Creating a class
class SomeClass{
private some_var;
public function SomeClass(){}
public function new_fun($r){
print_r($r);
echo $this->some_var;
}
}
Defining an array
$my_array = array('elem1','elem2');
Adding an array element
array_push($array,$elem)
Checking if a key exists
array_key_exists("some_name",$r)
Using a global var in a function
global $global_var;
if (file_exists($some_file)){
...
}
Basic Error Handling
function($var) or exit("some error");
Printing an array
print_r();
Creating a class
class SomeClass{
private some_var;
public function SomeClass(){}
public function new_fun($r){
print_r($r);
echo $this->some_var;
}
}
Defining an array
$my_array = array('elem1','elem2');
Adding an array element
array_push($array,$elem)
Checking if a key exists
array_key_exists("some_name",$r)
Using a global var in a function
global $global_var;
JQuery basics : working with divs and text boxes, and checking for null elements
Adding text to a div's innerHTML
$("div#some_div").append(s);
Getting text from a div
var text = $("div#some_div" ).html();
Getting/Setting value from text box
var text = $("#some_textbox").val();
$("#some_textbox").val("bla");
Checking if document element is null
if (!$("#some_elem").length){
...
}
$("div#some_div").append(s);
Getting text from a div
var text = $("div#some_div" ).html();
Getting/Setting value from text box
var text = $("#some_textbox").val();
$("#some_textbox").val("bla");
Checking if document element is null
if (!$("#some_elem").length){
...
}
Monday, June 15, 2009
Get the distance between two latitude/longitude points in km (example)
Here is a python script to convert lat/lng point to meters. It expects the points to be entered in as decimal degrees. It outputs the distance in km.
For example:
python distlatlng.py 36.12 -86.67 33.94 -118.40
the distance in km is 2887.25995061
For example:
python distlatlng.py 36.12 -86.67 33.94 -118.40
the distance in km is 2887.25995061
#uses the haversine formula
# based on code from http://www.movable-type.co.uk/scripts/latlong.html
import math, sys
def main(*args):
if len(args) < 5:
print args[0]," lng1 lat1 lng2 lat2 (finds distance between two lat/lng pairs)"
return
lat1 = float(args[1])
lng1 = float(args[2])
lat2 = float(args[3])
lng2 = float(args[4])
radius = 6372.8 # earth's mean radium in km
dlat = math.radians(lat2-lat1)
dlng = math.radians(lng2-lng1)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlng/2)*math.sin(dlng/2)
c = 2*math.atan2(math.sqrt(a),math.sqrt(1-a))
dist = radius*c
print "the distance in km is " , dist
if __name__ == "__main__":
main(*sys.argv)
Python basics : math functions, main funct
Math functions
#Unfortunately, you need to import math, but python has a nice library of math functions
Main function
#Making a main function in Python is a little tricky. Here is an example:
#Unfortunately, you need to import math, but python has a nice library of math functions
import math
math.pow(2,3)
math.cos(math.pi/2) #<-- radians!
math.pi
math.sqrt(4)
Main function
#Making a main function in Python is a little tricky. Here is an example:
def main(*args):
if len(args) < 4:
return
print "main : args[0] ", args[0], " args[1]", args[1]
print "(main) : args[1] ", args[2]
print "(main) : args[3] ", args[3]
if __name__ == "__main__":
Sunday, June 14, 2009
Mysql -- get table engine type
Get table engine type
You have to go to the mysql system database 1st
This allows you to see which type of table engine you're using
Common types:
myisam: doesn't support the features listed below for innodb
innodb (default) : supports r-trees (good for spatial extensions), enforces foreign keys, and supports transactions
select table_name, engine from tables where table_schema = "vsn";
You have to go to the mysql system database 1st
This allows you to see which type of table engine you're using
Common types:
myisam: doesn't support the features listed below for innodb
innodb (default) : supports r-trees (good for spatial extensions), enforces foreign keys, and supports transactions
select table_name, engine from tables where table_schema = "vsn";
Subscribe to:
Posts (Atom)