EzDevInfo.com

Boundary

Boundary is a CSS+Javascript library for Chrome extension developers to easily create HTML elements that won’t affect or be affected by the current webpage’s CSS. Strongly recommended if you are considering adding a sticker, a sidebar or any overlay box using content script.

Is \bword\b and \ equivalent in GREP and what usage of \<, \>?

Is \bword\b and \<word\> equivalent in GREP and what usage of \<, \> ?


Source: (StackOverflow)

setting non-linear boundary in 2D game

Normally to set a boundary at a certain area, I would implement something like:

if(player.X > 400){

   player.X = 400;

}

This acts as though there is a vertical line at X=400, blocking movement beyond that. I'm wondering how I would implement at boundary for an area that is at a slant or diagonal rather than vertical/horizontal.


Source: (StackOverflow)

Advertisements

Prevent to patch if the area is already filled

This is quite a tough challenge I have with my code. First of all the code I am putting here is not runnable because I am using an Excel sheet (but I am happy to email it if people want to try using my code).

What I have is an Excel sheet with data on cross-sectional fibres in a microscopic image I took. The information is basically: location of the section, area, angle of rotation.

From that I calculate the angle of orientation Phi, and Gamma. After that I use the scatter function to plot a dot of different colors for each Phi angle value. I use a constant color for a range of 10 degrees. Which gives me a picture like this:

enter image description here

Now my aim to is calculate the area of each homogeneous region. So I look for a way to plot let's say all the dots within the -10 +10 region (I'm doing 20 degrees for now, but will do 10 after). I used a look and I get a picture like this:

enter image description here

The white corresponds where the dots are within the range I selected. After that I use the toolbox in MATLAB to convert each dot into a pixel. So I'll get a black background with loads of white pixels, then I use imdilate to make circles, fill holes and isolate each region with a specific color. Finally I use the functions boundary and patch, to create each boundary and fill them with a color. And I get a picture like this:

enter image description here

Which is what I want and I can get the area of each region and the total area (I used a threshold to discard the small areas). Then I run the code several time for each region, and I use imfuse to put them back together and see what it looks like.

THE PROBLEM is, they overlap quite a lot, and that is because there are some errors in my data, and therefore some blue dots will be in the red and so on. So I want to run the code once, then when I rerun it with another range, it does the same thing but doesn't take into account value when there's already something plotted before.

I tried to do that by, after running once, saving the matrix bw4 and adding a condition when plotting the black and white pic, by saying if Phi is in my range AND there no white here then you can put white, otherwise it's black. But it doesn't seem to work.

I understand this is quite a complicated thing to explain, but I would appreciate any ideas, and open to chat via email or otherwise. I am putting the full code now, and I can send you my Excel sheet if you want to run it on your computer and see for yourself.

clearvars -except data colheaders bw4
close all
clc
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CHANGE DATA FOR EACH SAMPLE %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

cd 'C:\Users\dkarta\Desktop\Sample 12\12.6'
data=xlsread('Sample12_6res.xlsx');

cd 'C:\Users\dkarta\Documents\MATLAB'

%data=Sample121res; % Data name
imax=length(data); % Numbers of rows in data sheet
y=11900; % Number of pixels in the y on image j
%%

data(:,15)=data(:,9)*pi/180; % Convers Column 9 (angle of rotation) in rads
data(:,16)=y-data(:,6); % Reset the Y coordinate axis to bottom left
delta = 0 : 0.01 : 2*pi; % Angle in paramteric equations 
theta=45*pi/180; % Sample cutting angle in rads

%AA=[data(:,5)' data(:,16)' phi']
% Define colors
beta=acos(data(1:imax,8)./data(1:imax,7));%./acos(0);
phi=atan(sin(beta).*cos(data(1:imax,15))./(sin(theta)*sin(beta).*sin(data(1:imax,15))+cos(theta)*cos(beta)))/(pi/2);
phi2=phi/2+1/2; % Scales in plane angle phi between 0 and 1
gamma=atan((cos(theta)*sin(beta).*sin(data(1:imax,15))-sin(theta)*cos(beta))./...
    (sin(theta)*sin(beta).*sin(data(1:imax,15))+cos(theta)*cos(beta)))/(pi/2);
gamma2=gamma+1/2; % Scales out of plane angle gamma between 0 and 1 
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% MESHGRID AND COLOURMAP %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1=data(1:imax,5);
y1=data(1:imax,16);
z1=phi*90;
z2=gamma*90;
n=300;
%Create regular grid across data space
[X,Y] = meshgrid(linspace(min(x1),max(x1),n), linspace(min(y1),max(y1),n));

% Creating a colormap with 10 degree constant colors
map4=[0 0 1;0 1/3 1;0 2/3 1; 0 1 1;0 1 2/3;0 1 1/3;0 1 0;1/3 1 0;2/3 1 0;1 1 0;1 0.75 0;1 0.5 0;1 0.25 0;1 0 0;0.75 0 0.25;0.5 0 0.5;0.25 0 0.75; 0 0 1];
Colormap4=colormap(map4);
h=colorbar;
caxis([-90 90])
set(h, 'YTick', [-90:10:90])
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% PLOT USING SCATTER - ISOLATE SOME REGIONS %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=-10; % Lower boundary for angle interval
b=10; % Upper boundary for angle interval
c=z1>a & z1 < b;
c=c.*1;
%j=1;

y1=(y1-min(y1)+1);
y2=max(y1)-y1+1;
[X1,Y1]=meshgrid(1:500,1:500);
griddata(x1,y2,c,X1,Y1);
clear c1


for i=1:imax
    if z1(i)< b && z1(i)> a %&& bw4(round(y1(i)),round(x1(i))) == 0
        c(i) = 1;
        c1(round(y2(i)),round(x1(i)))=1;
    else
        c(i)= 0;
        c1(round(y2(i)),round(x1(i)))=0;
    end

end
C=[c c c];

%c(find(c==0)) = NaN;
%contourf(X,Y,griddata(x1,y1,c,X,Y),100,'EdgeColor', 'None')
figure(1), scatter(x1,y1,3,z1,'filled');
axis equal
axis ([0 8000 0 12000]) 
axis off
figure(2), scatter(x1,y1,3,C,'filled');
axis equal
axis ([0 8000 0 12000]) 
axis off


se=strel('disk',50,8);
bw2=imdilate(c1,se);
bw4=bwlabel(bw2);
bw3=imfill(bw4,'holes');
max(bw4(:));
figure(3),imshow(c1,'InitialMagnification', 10);
figure(4), imshow(bw2,'InitialMagnification', 10);
figure(5), imshow(bw3,'InitialMagnification', 10);
figure(6),imshow(label2rgb(bw4),'InitialMagnification', 10);

k=ones(max(bw4(:)),1);
clear bw5
for i=1:length(x1)
    if bw3(round(y2(i)),round(x1(i))) ~= 0
        m=bw3(round(y2(i)),round(x1(i)));
        bw5{m}(k(m),1)=x1(i); bw5{m}(k(m),2)=y2(i);
        k(m)=k(m)+1;
    end
end

figure(7), imshow(~c1,'InitialMagnification', 10);
hold on 
for i=1:max(bw4(:))
    %scatter(bw5{i}(:,1),bw5{i}(:,2))
    j = boundary(bw5{i}(:,1),bw5{i}(:,2),0.5);
    %poly=convhull(bw5{i}(:,1),bw5{i}(:,2));
    %plot(bw5{i}(poly,1),bw5{i}(poly,2)), title('convhull')
    if polyarea(bw5{i}(j,1),bw5{i}(j,2))> 10^5;
        patch(bw5{i}(j,1),bw5{i}(j,2),'r'), title('boundary')
        indexminy(i)=find(min(bw5{i}(:,2)) == bw5{i}(:,2));
        indexminx(i)=find(min(bw5{i}(:,1)) == bw5{i}(:,1));
        indexmaxy(i)=find(max(bw5{i}(:,2)) == bw5{i}(:,2));
        indexmaxx(i)=find(max(bw5{i}(:,1)) == bw5{i}(:,1));
        %xmin = bw5{i}(indexminx); xmax = bw5{i}(indexmaxx); 
        %ymin = bw5{i}(indexminy); ymax = bw5{i}(indexmaxy);
        str=[(indexminx(i)+indexmaxx(i))/2,(indexminy(i)+indexmaxy(i))/2,'Region no.',num2str(i)];
        text((min(x1(i))+max(x1(i)))/2,(min(y1(i))+max(y1(i)))/2,str)
        polya(i)=polyarea(bw5{i}(j,1),bw5{i}(j,2));
    end
end
spolya=sum(polya(:))
print -dpng -r500 B

Just to show you more pictures of when I fuse several of them:

enter image description here enter image description here enter image description here And when I fuse:

enter image description here
As you can see they overlap, which I don't want, so I want each image that I create to 'know' what I'm doing on the previous runs so that it doesn't overlap. I want to get the percentage area of each region and if they overlap I cannot use the actual total area of my sample and the results are wrong.


Source: (StackOverflow)

What are non-word boundary in regex (\B), compared to word-boundary?

What are non-word boundary in regex (\B), compared to word-boundary?


Source: (StackOverflow)

GIT_DISCOVERY_ACROSS_FILESYSTEM not set

I have searched and read few post but my problem is not the same as descirbed. So here's the issue: using git clone into folder under external partition of the disk works fine but all git commands fails. can't execute git status or git log... I always get error

fatal: Not a git repository (or any parent up to mount parent /home/kozi) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Please help me out..

.
├── abi
├── bionic
├── bootable
├── build
├── cts
├── dalvik
├── development
├── device
├── docs
├── external
├── frameworks
├── gdk
├── hardware
├── libcore
├── libnativehelper
├── ndk
├── packages
├── pdk
├── prebuilts
├── .repo
├── sdk
├── system
└── tools


Source: (StackOverflow)

SVG draws outside canvas boundary in Internet Explorer 9

I am using the Raphael Javascript library to do some rudimentary drawing for a web page. I am just drawing some lines that radiate out from a point. In Chrome, Firefox, and Opera, these lines are subject to the size of the SVG canvas. This is the desired behaviour, because I want to draw a ray as long as I want but I do not want it to affect the size of the page. If I draw a 5000px wide box, only the part inside the canvas will be visible.

However, Internet Explorer (surprise surprise) completely ignores the size and bounds of the canvas and accommodates whatever is drawn. So if I draw a 5000px wide box starting at 0, 0, but the canvas is 50px by 50px and starts at 20, 20, you'll still see a box at 0, 0 that's 5000px wide, and the page will have a scrollbar at the bottom so you can scroll sideways to view the entire thing. I do not want this to happen.

How can I get Internet explorer to behave like the other browsers in this respect? I do not want the page to be able to scroll to view the other parts of the image drawn by Raphael, I want the edges to be clipped by the natural size of the document.


I have stupidly answered my own question with this newsgroup thread: http://groups.google.com/group/raphaeljs/browse_thread/thread/43c71ec89a6a01ed

Simply add this to your CSS:

svg { overflow: hidden; }

Source: (StackOverflow)

Form boundaries and writing php://input to a file in php

So I want users to be able to upload big files without having to worry about the post max size values. The alternative is using PUT and send a file as raw data. When using jquery I can do this:

var data = new FormData();
  jQuery.each($('#file_upload')[0].files, function(i, file) {
  data.append('file-'+i, file);
});
$.ajax({
  url: 'upload.php?filename=test.pdf',
  data: data,
  cache: false,
  contentType: false,
  processData: false,
  type: 'PUT',
});

In PHP I can do this:

$f = fopen($_GET['filename'], "w");
$s = fopen("php://input", "r");

while($kb = fread($s, 1024))
{ 
  fwrite($f, $kb, 1024); 
}
fclose($f);
fclose($s);
Header("HTTP/1.1 201 Created");

I am not doing:

$client_data = file_get_contents("php://input");

Since putting the whole file into a variable will surely fill up all memory when uploading huge files.

The thing I cannot figure out is how to write the file data without the form boundaries. Right now it writes at the top of the file something like this:

------WebKitFormBoundaryVz0ZGHLGxBOCUVQG
Content-Disposition: form-data; name="file-0"; filename="somename.pdf"
Content-Type: application/pdf

and at the bottom something like this:

------WebKitFormBoundaryVz0ZGHLGxBOCUVQG--    

So I need to parse the data. But for that I need to read the whole data stream into memory and with large video files I don't want to do that. I did read something about maybe creating a php://temp stream. But no luck yet with that. How can I write just the content to a file, without the boundary header? And without first pumping all the data into a variable?


Source: (StackOverflow)

Emacs regex word boundary (specifically concerning underscores)

I am trying to replace all occurrences of a whole word on emacs (say foo) using M-x replace-regexp.

The problem is that I don't want to replace occurrences of foo in underscored words such as word_foo_word

If I use \bfoo\b to match foo then it will match the underscored strings; because as I understand emacs considers underscores to be part of word boundaries, which is different to other regex systems such as perl.

What would be the correct way to proceed?

Thanks


Source: (StackOverflow)

Efficiently calculating boundary-adapted neighbourhood average

I have an image with values ranging from 0 to 1. What I like to do is simple averaging.
But, more specifically, for a cell at the border of the image I'd like to compute the average of the pixels for that part of the neighbourhood/kernel that lies within the extent of the image. In fact this boils down to adapt the denominator of the 'mean formula', the number of pixels you divide the sum by.

I managed to do this as shown below with scipy.ndimage.generic_filter, but this is far from time-efficient.

def fnc(buffer, count):
    n = float(sum(buffer < 2.0))
    sum = sum(buffer) - ((count - b) * 2.0)
    return (sum / n)

avg = scipy.ndimage.generic_filter(image, fnc, footprint = kernel, \
                                   mode = 'constant', cval = 2.0,   \
                                   extra_keywords = {'count': countkernel})

Details

  • kernel = square array (circle represented by ones)
  • Padding with 2's and not by zeroes since then I could not properly separate zeroes of the padded area and zeroes of the actual raster
  • countkernel = number of ones in the kernel
  • n = number of cells that lie within image by excluding the cells of the padded area identified by values of 2
  • Correct the sum by subtracting (number of padded cells * 2.0) from the original neighbourhood total sum

Update(s)

1) Padding with NaNs increases the calculation with about 30%:

    def fnc(buffer):
        return (numpy.nansum(buffer) / numpy.sum([~numpy.isnan(buffer)]))

    avg = scipy.ndimage.generic_filter(image, fnc, footprint = kernel, \
                                       mode = 'constant', cval = float(numpy.nan)

2) Applying the solution proposed by Yves Daoust (accepted answer), definitely reduces the processing time to a minimum:

    def fnc(buffer):
        return numpy.sum(buffer)

    sumbigimage = scipy.ndimage.generic_filter(image, fnc, \
                                               footprint = kernel, \
                                               mode = 'constant', \
                                               cval = 0.0)
    summask     = scipy.ndimage.generic_filter(mask, fnc, \
                                               footprint = kernel, \
                                               mode = 'constant', \
                                               cval = 0.0)
    avg = sumbigimage / summask

3) Building on Yves' tip to use an additional binary image, which in fact is applying a mask, I stumbled upon the principle of masked arrays. As such only one array has to be processed because a masked array 'blends' the image and mask arrays together.
A small detail about the mask array: instead of filling the inner part (extent of original image) with 1's and filling the outer part (border) with 0's as done in the previous update, you must do vice versa. A 1 in a masked array means 'invalid', a 0 means 'valid'.
This code is even 50% faster then the code supplied in update 2):

    maskedimg = numpy.ma.masked_array(imgarray, mask = maskarray)

    def fnc(buffer):
        return numpy.mean(buffer)

    avg = scipy.ndimage.generic_filter(maskedimg, fnc, footprint = kernel, \
                                       mode = 'constant', cval = 0.0)

--> I must correct myself here!
I must be mistaken during the validation, since after some calculation runs it seemed that scipy.ndimage.<filters> cannot handle masked_arrays in that sense that during the filter operation the mask is not taken into account.
Some other people mentioned this too, like here and here.


The power of an image...

  • grey: extent of image to be processed
  • white: padded area (in my case filled with 2.0's)
  • red shades: extent of kernel
    • dark red: effective neighbourhoud
    • light red: part of neighbourhood to be ignored

enter image description here


How can this rather pragmatical piece of code be changed to improve performance of the calculation?

Many thanks in advance!


Source: (StackOverflow)

What are valid characters for creating a multipart form boundary?

In an HTML form post what are valid characters for creating a multipart boundary?


Source: (StackOverflow)

Using view.bounds to make boundaries

I'm working on a few basic apps/utilities/games with the iPhone to get a better grip on it.

I currently have a setup where a CGRect moves wherever the finger moves, however I don't want the CGRect to go outside the bounds of the view.

Original Method

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    startLocation = [touch locationInView:self];
    if (startLocation.x < 33){
    	touchLocation.x = 33;
    		//NSLog(@"Touch At:%f, %f", touchLocation.x, touchLocation.y);
    	[self setNeedsDisplay];
    }
    if (startLocation.x > 288){
    	touchLocation.x = 288;
    		//NSLog(@"Touch At:%f, %f", touchLocation.x, touchLocation.y);
    	[self setNeedsDisplay];
    }
    if (startLocation.y < 84){
    	touchLocation.y = 84;
    		//NSLog(@"Touch At:%f, %f", touchLocation.x, touchLocation.y);
    	[self setNeedsDisplay];
    }
    if (startLocation.y > 460){
    	touchLocation.y = 460;
    		//NSLog(@"Touch At:%f, %f", touchLocation.x, touchLocation.y);
    	[self setNeedsDisplay];
    }
    else {
    	touchLocation = startLocation;
    	[self setNeedsDisplay];
    }
}

Problem

I've tried a few different methods of this, including using && and making it just one statement. The boundaries are obviously hard coded, and I'm not sure that manually setting the touchLocation is the best way to keep it in bounds.

This all seems silly to me when I can easily self.view.bounds and get the bounding CGRect. How do I make use of bounds to do this? Is there a better way to prevent it from happening other than setting touchLocation manually? Can I somehow place a hard limit on it instead?

What about a switch statement? Would that work better than the attempted-ifs?


Attempt

I am now attempting to utilize @Brad Goss's method posted below, however it isn't working?

Touch Started: (319.000000,350.000000)
Touch Result: (319.000000,350.000000)
Boundaries calculated: X:(0.000000,288.000000) Y(0.000000,328.000000)

Touch Started is the actual starting touch. Touch Result should be the changed result.

The above log is showing it outside of the defined bounds, aka not working. I'm not going to repost the code he wrote because it is the exact same.


Attempt Problem

I've discovered the problem. This is the same type situation as above, but with logging for the individual values as they are set.

Touch Started: (293.000000,341.000000)
min x:288.000000
max x:293.000000
min y:328.000000
max y:341.000000
Touch Result: (293.000000,341.000000)
Boundaries calculated: X:(0.000000,288.000000) Y(0.000000,328.000000)

I haven't figured it out, I posted it here as soon as I discovered it. Otherwise I'd forget to update at all, ADD heh.

I'm going to go back and see exactly what's going on in each of the possible situations.


Mistake

Found another problem, the code that calculates the boundaries subtracts from the maximums, but doesn't add to the minimums. This is important as this is what the boundary is for, to stop the rect from going off the screen.

maxX = b.origin.x + b.size.width/* - [box bounds].size.width */;
minX = b.origin.x/* + [box bounds].size.width */;
maxY = b.origin.y + b.size.height/* - [box bounds].size.height */;
minY = b.origin.y?/* + [box bounds].size.height */;

With this fixed, I can continue working on the original problem.


Mistake 2

Alright, I've fixed another problem. I was adding to the y value when it was being displayed. I forgot to add it into this new code/mention it. The code now looks like this:

maxX = b.origin.x + b.size.width/* - [box bounds].size.width */;
minX = b.origin.x/* + [box bounds].size.width */;
maxY = b.origin.y + b.size.height/* - [box bounds].size.height + 20*/;
minY = b.origin.y/* + [box bounds].size.height + 20*/;

The size of the circle being displayed is inside of a 64px CGRect, so 20px was sufficient to display the circle just above the thumb. Though this is fixed, it still hasn't helped to solve our original problem.

Upper Left corner:

Touch Started: (14.000000,20.000000)
min x:14.000000
max x:32.000000
min y:20.000000
max y:84.000000
Touch Result: (32.000000,84.000000)
Boundaries calculated: X:(32.000000,288.000000) Y(84.000000,276.000000)

It works as it should, but I am confused as to why the correct values are coming out of MAX instead of MIN. Something is mixed up here.

Upper right corner:

Touch Started: (303.000000,21.000000)
min x:288.000000
max x:303.000000
min y:21.000000
max y:84.000000
Touch Result: (303.000000,84.000000)
Boundaries calculated: X:(32.000000,288.000000) Y(84.000000,276.000000)

It's preventing me from going off the top of the screen, again from MAX instead of MIN. I am still able to fly off the right, as shown above.

Bottom right corner:

Touch Started: (317.000000,358.000000)
min x:288.000000
max x:317.000000
min y:276.000000
max y:358.000000
Touch Result: (317.000000,358.000000)
Boundaries calculated: X:(32.000000,288.000000) Y(84.000000,276.000000)

It's failing on both directions. Now the actual values are coming from MAX, and the maximum values are coming from MIN. WTF?

Bottom left corner:

Touch Started: (8.000000,354.000000)
min x:8.000000
max x:32.000000
min y:276.000000
max y:354.000000
Touch Result: (32.000000,354.000000)
Boundaries calculated: X:(32.000000,288.000000) Y(84.000000,276.000000)

Predictably, it only worked for the minimum value. I'm still very confused as to what these functions are supposed to do. Insight would be much appreciated!


SOLVED!

Our long road draws to a close, thankfully. So, because I had no clue, here is what MIN and MAX do. It wasn't initially obvious to me due to the confusion that had taken place.

MAX(x,y) will output the larger of the two numbers
// MAX(13,37) = 37
MIN(x,y) will output the smallest of the two numbers
// MIN(13,37) = 13

So this is what you have to do to make use of these functions correctly in this situation:

1. Calculate the Maximum & Minimum values for X and Y.

The lowest value for each is calculated as

view.origin + keepOnScreenRect.width

The highest value of each is calculated as

view.origin + view.size.height/width - keepOnScreenRect.height/width

Don't forget the offset for the finger!
If you are doing what I did, and have the keepOnScreenRect positioned slightly above the user's finger, you should only be adding the extra offset to the Maximum value of Y, as the minimum value of Y is the bottom of the screen/view, which you are physically unable to go lower than 0 at.

If you're wondering why this is done, it is because the user cannot see through his/her finger.

2. Get the location of the touch on touchesBegan:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    startTouchLocation = [touch locationInView:self];
    NSLog(@"Touch Started: (%f,%f)", startTouchLocation.x, startTouchLocation.y);

3. Apply the mathematic constraints:

First, we get the MAX, or highest value, of both the lowest possible value according to our limits, minX, and startTouchLocation, for X. This calculates the limit for the left side of the screen. The result of this is set to currentTouchLocation.

currentTouchLocation.x = MAX(minX, startTouchLocation.x);

Second, we get the MIN, or lowest value, of both the highest possible value according to our limits, maxX, and currentTouchLocation, for X. Note that we aren't using the location of the original touch, but instead the resulting location of the MAX function we just used. This value has already been checked for the left side of the screen, so we check the right.

currentTouchLocation.x = MIN(maxX, currentTouchLocation.x);

That gives us an X location that is guaranteed to be within our limits. We then perform the same on Y.

currentTouchLocation.y = MAX(minY, startTouchLocation.y);
currentTouchLocation.y = MIN(maxY, currentTouchLocation.y);

With all this finished, we can now tell the view to redraw itself and no longer fear having our lovely little rectangle cut off in any way.

[self setNeedsDisplay];


Finished Product

/* Generates the limits based on the view's size, taking into account 
   the width/height of the rect being displayed in it. This should only
   be run once, unless the size of the view changes, in which case limits
   would have to be recalculated. The same goes for if you were to change
   the size of the displaying rect after calculation */

- (void)boundsCalculation {
    CGRect viewBounds = [self bounds];

    	// calculate constraints
    maxX = viewBounds.origin.x + viewBounds.size.width - 32;
    minX = viewBounds.origin.x + 32;
    maxY = viewBounds.origin.y + viewBounds.size.height - 32;
    minY = viewBounds.origin.y + 84;
    NSLog(@"Boundaries calculated: X:(%f,%f) Y(%f,%f)", minX, maxX, minY, maxY);
}

/* Magic goodness that happens when the user touches the screen.
   Note that we don't calculate the bounds every time the user touches
   the screen, that would be silly. */

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    startTouchLocation = [touch locationInView:self];
    NSLog(@"Touch Started: (%f,%f)", startTouchLocation.x, startTouchLocation.y);

    	// apply constraints
            // highest x value between the lowest allotted x value and touch
    currentTouchLocation.x = MAX(minX, startTouchLocation.x);
            // lowest x value between the highest allotted x value and touch
    currentTouchLocation.x = MIN(maxX, currentTouchLocation.x);
            // highest y value between the lowest allotted y value and touch
    currentTouchLocation.y = MAX(minY, startTouchLocation.y);
            // lowest y value between the highest allotted y value and touch
    currentTouchLocation.y = MIN(maxY, currentTouchLocation.y);
           // NSLog(@"Touch Result: (%f,%f)", currentTouchLocation.x, currentTouchLocation.y);

           // If you don't do this you won't see anything
    [self setNeedsDisplay];
}

Today was a good day for learning.


Source: (StackOverflow)

Scipy boundary conditions on a sparse matrix pattern

My system is best described by a diagonal sparse matrix (Poisson). I have my diagonal sparse matrix, however, I want to change the boundary conditions (ie the "edges" of my matrix) to zero. It must be a common situation where a modeler wants to describe a system in a sparse diagonal matrix with distinct boundary conditions, is there a best practice for doing this?

[[0,0,0,0,..0],
 [0,2,1,0,..0],
 [0,1,2,1,..0],
 ...
 [0,0,0,0,..0]]

Source: (StackOverflow)

How to get parcel or zipcode boundaries for display in map?

I want to add a boundary to a specified parcel of land so that it stands out in the map with a colored outline/border. In google maps, this is done using the polygon functionality if you know that path of coordinates to enter to surround the land parcel. However, I do not have the polygon path info, but I do have the both the geocode coordinates for the location and also the Assessor's Parcel Number (APN) for the parcel as well.

I found this other SO post that talks a little about how to get the polygon for zipcodes using the free Census Bureau data coupled with some open source software, but it's quite involved (as you have to download and host the data) and I'm not sure it even does percision down to parcel boundaries. It's definitely an option if it supports parcels, but it looks to be very time consuming albeit free.

I also found a paid solution (price not displayed) called ParcelStream, but thinking it's expensive and probably just using the above solution in the other SO post. This is also an option if it's a small one time fee, but not if it's expensive or a subscription fee.

I am aware you can manually create overlays on maps, save, and then share them, but I'm looking for an automated/programatic solution.

UPDATE: okay, ParcelStream from Digital Map Products, is not an option and around 10k/month. They advised the subscription service is intended for national coverage (not local) and Google is among their clients.

UPDATE #2: Using the US Census Bureau data solution mentioned above (coupled with other open source software) doesn't seem to provide boundary data down the parcel after browsing the features available on it's TIGERweb2010 site.


Source: (StackOverflow)

In vim, how do I make a custom word boundary motion?

As I understand, w recognizes word boundaries by splitting text into 3 groups:

1) characters that are specified in the iskeyword setting (alphabetic, digits, and underscore)

2) other non-printable characters (symbols)

3) whitespace characters

Each time you press w it goes to the next group 1 or group 2. I'd like to customize it so it only goes to the next group 1, jumping over "symbol words".

What almost works is this:

nnoremap w /\k\+<CR>

which uses the iskeyword character class \k. But it is ugly because it simulates me performing a search, which changes my highlighting, clutters my search history, and who knows what else. Is there way to make this work "cleanly" like the w command normally is?


Source: (StackOverflow)

what rule for creating an MIME boundary (for Mail attachments)

i'm using the PHP mail() function to send mails with attachment. Therefore the PHP source contents an boundary to define where the attachment begins and ends.

So the question is: are there any ruels for creating this MIME boundary (exampt that are only letters and numbres are allowed) i still know this SO question -> What rules apply to MIME boundary? Is it necessary to create an boundary form an HASH? Because the following also works:

$headers .= "Content-Type: multipart/related; boundary=\"abc\"";
[...]
$msg .="--abc\n";
[...]
$msg .= "--abc--\n\n"; 

Is there a reason, why a MIME boundary should be an unique value?

..i didn't found any information at the Internet.

Thank you!


Source: (StackOverflow)