Wednesday, 11 September 2013

Get list of calls to a method and arguments passed with the call from source code

Get list of calls to a method and arguments passed with the call from
source code

Question
Given the following code, I want to extract muffinize and all the
arguments passed with it:
$ask = false
muffinize("Shoop")
muffinize("Woop") if($ask == true)
if($ask == false)
muffinize("Pants")
end
This is the output that I would expect:
Call#:Args
1:"Shoop"
2:"Woop"
3:"Pants"
What I'm doing so far
I'm parsing the source code with Ripper to find the locations where the
method is called. Then I'm finding the range of characters in the line of
code where the method is called. After extracting the method from the
line, I'm then analyzing it with the Parser gem. I will post the code as
an answer once I've complete it, but I'm interested in hearing if there's
a better way to do this. I don't know code parsing that well so I'm kind
of flailing around blindly at this point.
Why not just use a Regex
A regex would still capture commented code blocks. There's probably other
corner cases that I haven't considered yet.

Change encoding of text file (shell archive or script for antique kernel text to ASCII text, with CRLF, LF line terminators)

Change encoding of text file (shell archive or script for antique kernel
text to ASCII text, with CRLF, LF line terminators)

I'm writing a small bash script to look up the 1st line of FILEA in FILEB,
if it matches then it returns over a text with the filename.
Problem is when i'm extracting text from FILEA and then comparing it with
a simple == as an if condition, it returns as different.
I've narrowed down the issue being to the encoding of the 2 files i'm
using being different
(FILEA=shell archive or script for antique kernel text)
(FILEB=ASCII text, with CRLF, LF line terminators)
Is there a way to convert FILEA to ASCII to avoid this issue when
comparing through UNIX? Or outside of UNIX would work for me too.
Really appreciate any help or comment.
Thanks

How to resize UILabel in code

How to resize UILabel in code

I have got a UILabel which is placed in between two UITableViews inside a
scrollview. What I want is to resize the UILabel height depending upon the
total text , which gets generated at runtime.
I have a solution but it doesnt work
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
CGRect titleLabelBounds = self.lblPreparation.bounds;
titleLabelBounds.size.height = CGFLOAT_MAX;
// Change limitedToNumberOfLines to your preferred limit (0 for no limit)
CGRect minimumTextRect = [self.lblPreparation
textRectForBounds:titleLabelBounds limitedToNumberOfLines:0];
CGFloat titleLabelHeightDelta = minimumTextRect.size.height -
self.lblPreparation.frame.size.height;
CGRect titleFrame = self.lblPreparation.frame;
titleFrame.size.height += titleLabelHeightDelta;
self.lblPreparation.frame = titleFrame;
lblPreparation.text = @"sdjshdjshd sjhdjdd jjsjjsdhjsd \njsdhjshjshdjs
djs djsdh";
}
This above solution was proposed in a question but doesn't seem to be
working for me. Please suggest a suitable way.

Trouble restoring database using T-sql

Trouble restoring database using T-sql

backup database Clinical_Data_Extension to
disk='c:\Clinical_Data_Extension_full.bak'
restore filelistonly from disk='c:\Clinical_Data_Extension_full.bak'
restore database Clinical_Data from
disk='c:\Clinical_Data_Extension_full.bak'
with move 'Clinical_Data_Extension' to 'C:\Program Files\Microsoft SQL
Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Clinical_Data.mdf',
move 'Clinical_Data_Extension_log' to 'C:\Program Files\Microsoft SQL
Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Clinical_Data.ldf',
REPLACE
Error:
Msg 3234, Level 16, State 2, Line 3
Logical file 'Clinical_Data_Extension' is not part of database
'Clinical_Data'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 3
RESTORE DATABASE is terminating abnormally.
Yet for some reason the following identical code works fine:
backup database Clinical_Data to disk='c:\Clinical_Data_full.bak'
restore filelistonly from disk='c:\Clinical_Data_full.bak'
restore database Clinical_Data_Extension from
disk='c:\Clinical_Data_full.bak'
with move 'Clinical_Data' to 'C:\Program Files\Microsoft SQL
Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Clinical_Data_Extension.mdf',
move 'Clinical_Data_log' to 'C:\Program Files\Microsoft SQL
Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Clinical_Data_Extension.ldf',
REPLACE
Basically, what I am doing is creating database "Clinical_Data_Extension"
and doing work on it. Once I am done, I have a script for removing
"Clinical_Data", and then I use the script which I mentioned first to
restore "Clinical_Data" using data from "Clinical_Data_Extension"
essentially overwriting "Clinical_Data". However for some reason the first
script gives me an error and the second does not yet they are totally
identical. Why do you think this would happen?

redirect to a content page when a link is clicked

redirect to a content page when a link is clicked

ive just started PHP and MYSQL, and been trying to figure out how i can
redirect to a page and display the content.
i have this PHP code that lists all my topic rows from my database
while ($row = $result->fetch_array()) {
echo '<a href="#"><p class="list" st>' . $row['topic'] . '<br /></a>';
}
it will list all the topics inside the <a href> markup.
when link is clicked, i will be redirected to a page where the content is
displayed based on the topic link.
i just need the logic how to create that page. basically i have page.php
which i plan to put the logic. but i dont know how to start.

Show a message if the browser is not internet explorer 9 or greater

Show a message if the browser is not internet explorer 9 or greater

I would like to show my users a bar like this, if they are not browsing
the site with IE9 or greater

I found this nice jquery plugin, but I dont want to use popups.
http://jreject.turnwheel.com/
Please notice the site where I will implement this is a Sharepoint 2013
site, so I will use a content editor webpart to include the html content
you provide and the bar should be at the top of everything else.
Please incluse css if needed to make it look as the screenshot?
The screenshot is just a guide of what I need, the real condition is: Show
the bar if:
browser is not IE
ie is older than version 9

Avoiding iCloud conflicts with non CoreData app

Avoiding iCloud conflicts with non CoreData app

I am working on a non CoreData based app (sqlite), now that it must be
ported to iPad, all hell has broken loose.
Since syncing is not needed, I am trying to stay with my good old sqlite
solution. However I have noticed that even now I have an ugly problem: if
the same app is used by the same user in different devices. The database
file is automatically backed up to iCloud, but now more than one device
want to upload different databases into the same location.
Which one is the common solution to this problem? My immediate guess is
saving the database into a subfolder like .../Documents/some_type_of_id/
and use iCloud to backup different databases and settings for each device.
How should I generate that ID? My first choice seems to be this:
[[[UIDevice currentDevice] identifierForVendor] UUIDString]
However, now that I am getting my hands dirty, I am wondering which
equivalent solution should be used with a Mac app (same iCloud user on
different macs). UIDevice is not within the Mac SDK.
How should I generate a Mac unique ID?
Although I am asking now about UIDs, my first concern is still avoiding
iCloud conflicts. I would appreciate any guidance or references to how
properly handle this case.