How to create a new line above one being catched? - rector

I have this
$last_data=date("Y-m-d",strtotime(mysql_result($res,0,0)));
I need to do a first step of refactoring
$tmp_date_string=mysql_result($res,0,0));
$last_data=date("Y-m-d",strtotime($tmp_date_string);
Can rector create a new line above the one being considered? If yes, how ?

Related

what kind of variable/function/object is session("var") = "Value"

I am trying to make modifications to a vbscript that uses the line:
Session("Variable") = "MyVariable String"
This line requires it to be ran within a different program which is not available where I am doing my development. This line is NOT important to the development that I am doing and I just need it to NOT blow up with 'undefined variable session' when I am running with 'Option explicit'. What class, dictionary, variable type, or whatever do I need to create in order for that line to work without warnings/errors? I am currently just commenting them out, but when I copy and paste my code back in production I have to go back through and hope that I have uncommitted all of them back out. I'd rather just add a for instance "Set Session = New FooSomething" at the top of the code that will make it work and just remove that line when I add to production code. Thanks for your time.

How to copy faces and preserve transformation in Sketchup Ruby

I am new to Sketchup Ruby and am blown away this is not more simple but here goes...
I would like to copy all the groups matching a certain layer name to a new temporary group. I have basically given up on trying to copy the whole group because that appears to be fraught with peril and Bugsplats if not done in some super-anal retentive way that considers context, immediate exploding of objects, etc...
So, I have resorted to trying to loop through all matching groups entities and copying faces instead, which seems much more straight-forward. My goal here is not to become a Ruby wizard but just accomplish this one script.
I have been able to copy faces BUT the faces lose their transformation on copy and just end up at some random size at the origin rather than wherever they were at the model.
Here is the code:
SKETCHUP_CONSOLE.clear
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
temp_wall_primitives = ent.add_group #create a new empty temporary group
mod.definitions.each{|d|
next if d.image? || d.group? || d.name!="WALL"
d.entities.each{ |wall_primative_group|
if wall_primative_group.layer.name == "WALL_PRIMITIVES"
wall_primative_group.entities.each{ |wall_primative_group_entity|
if wall_primative_group_entity.is_a? Sketchup::Face
new_face = temp_wall_primitives.entities.add_face(wall_primative_group_entity.vertices)
end
}
end
}
}
I believe I need to somehow get the transformation of each face and apply it to the new faces as they are created?
Instead of trying to copy the entities from an instance to another one, place a new instance;
# Lets say we have a group.
source_group = model.entities.grep(Sketchup::Group)
# We can "copy" this to another group by fetching it'd definition and adding a new one:
new_group = model.entities.add_group
new_group.entities.add_instance(source_group.definition, source_group.transformation)
In your current solution, where you re-create each face, the reason for the transformation being lost is that vertex positions are relative to their parent. You pass in the vertices you copy from directly: temp_wall_primitives.entities.add_face(wall_primative_group_entity.vertices)
But you need to apply the transformation for the instance they relate to as well.
Additionally your current solution doesn't seem to take into account nested instances. And that faces can have holes in them - in which case face.vertices would not form a valid single loop. Manually recreating faces quickly gets complicated. If you want the whole content of a group or component instance, just make a copy of the instance itself. You can explode the new instance if you want.
But I would question why you have a temporary group in the first place. (Often this turns out to not be necessary. It would help if you explained the higher level task you are trying to perform here.)

Update a matrix into a text file without appending the results

I have a Fortran 77 code like this, more or less:
nMaxRow=100
nMaxStep=100
! initialization of the matrix if Step=1
do step=1,nMaxStep
if (step.eq.1) then
do ii=1,nMaxRow
do jj=1,nMaxStep
A(ii,jj)=0
end do
end do
end if
!now for each step and for each row update the cell of the matrix
do ii=1,nMaxRow
A(ii,step)=X(ii) !X(ii) is a number associated with the specific ow at that specific step
end do
!Now I want to write the updated matrix at this step into a text file,
!How can I do that????
end do !close the do step...
Is it possible to update the values of the matrix and write the updated matrix at that specific step into a text file? I mean, without appending the results each step...
I found out that for Fortran 90 the 'REPLACE' command exists... but I couldn't find anything similar for Fortran 77.
One simple idea would be deleting the file just before writing a new one... but I don't like it and I don't know how to do it anyway.
If the file is already open (from the previous writing), you can just go the the start of the file using
rewind(unitnumber)
and start writing again. It will delete the original content of the file and start again. If you wan't to go back just be several records, you can use backtrace(), but you probably don't want that here.
If it isn't open, just open it and start writing. Unless you open it of appending, it will overwrite the original content.

AutoCad script: running a few objects in a row

I'm really new to AutoCad and I'm trying to write a first script. I have problem with it, though.
I want to have a few objects in my picture and I'm trying to call them one after another but they seem to work only separately. When I run the whole script, just two objects are drawn, no more. What is missing between the lines? I'd be grateful for your help!
This is my script:
_pline 297.3806,3728.9307
#3744.8216,0
#0,-3178.5797
#-3744.8216,0
#0,3178.5797
_ellipse 2847.31,2621.88 2647.16,2403.75 120.6928
_ellipse 2010.64,2594.83 1922.96,2478.61 109.6986
_circle 2350.2332,2121.3065 891.402
New lines and spaces are important in scripts.
In AutoCAD [ENTER] default means "repeat the last command".
so it's enougth to remove empty lines from Your code:
_pline 297.3806,3728.9307
#3744.8216,0
#0,-3178.5797
#-3744.8216,0
#0,3178.5797
_ellipse 2847.31,2621.88 2647.16,2403.75 120.6928
_ellipse 2010.64,2594.83 1922.96,2478.61 109.6986
_circle 2350.2332,2121.3065 891.402

How to only read one line (its head) from a file?

I want to get the head of a file. How to only read one line (its head) from a file? (spring-batch)
I suppose you use FlatFileItemReader.
In such case it possible to set setLinesToSkip(1) to skip header and use setSkippedLinesCallback to get its value. If you want to ignore other lines - just alwasy return null in LineMapper.
But if you really need only one line - implement your Tasklet or ItemReader for it.

Resources