Categories
askquestion

IE6 performance with CSS expressions

IE6 performance with CSS expressions

Ask Question

Asked
11 years ago

Active
5 years, 6 months ago

Viewed
4k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

4

3

We are developing a web application that will be sold to many clients. There is already one client (a bank) which has decided that it will buy the product once it is ready. Unfortunately due to some miscommunication it came out rather late that the only browser they use is IE6. The application was already started with the thought in mind that it does not need to support anything else below IE7. The results are pretty good too – it’s fully useable on IE7/FF/Opera/Safari. Haven’t tested on Chrome, but expect little problems there. Unfortunately there is now the IE6 requirement after all…

The application isn’t too far developed yet, and the design is pretty much OK, so the change isn’t that horrible. Still, it’ll take some work.

A nice thing about IE6 is that it supports two nonstandard and very helpful features. First is conditional comments, which lets me include some CSS/JS files only for IE6. Second is CSS expressions. That is, things like this:

input
{
background-color: expression(this.type=’text’?’silver’:”);
}

In essence it binds CSS values to JavaScript expressions. This allows to easily emulate many CSS features that IE6 does not support natively, and could lighten my burden considerably.

Unfortunately IE is infamous for its JavaScript performance. I’m worried that using too many of these expressions might slow it down to a crawl. I also have no idea what computers the bank is using. Since it’s a pretty big one, I’d expect a wide variety in all their branch offices. I don’t expect to use anything much there – some simple math, ternary operators and looking at this element’s/parent element’s properties. Still there would be a couple dozen of these in the IE6_override.CSS file.

Can this be a problem?

Added: Blah, this was what I was afraid of. OK, will see how much I can use other hacks to get around the shortcomings. Thanx, people!

javascript css performance internet-explorer-6 css-expressions

share|improve this question

edited Apr 29 ’12 at 3:34

Knu

13.4k55 gold badges5252 silver badges8282 bronze badges

asked Feb 5 ’09 at 15:50

Vilx-Vilx-

91.4k7575 gold badges247247 silver badges386386 bronze badges

add a comment
 | 

8 Answers
8

active

oldest

votes

10

https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-7-avoid-css-expressions-7202.html

Turns out you might want to avoid using these, they are dangerous.

share|improve this answer

edited Aug 19 ’14 at 16:09

DeadlyChambers

4,06733 gold badges3535 silver badges5050 bronze badges

answered Feb 5 ’09 at 15:58

Luca MatteisLuca Matteis

27.4k1919 gold badges103103 silver badges159159 bronze badges

add a comment
 | 

5

Expressions are re-evaluated on many page events, which has the potential to slow down entire page performance when used too liberally. (And yet still, they can’t respond to all events that might cause them to need re-evaluating.)

MS have admitted expression() was a mistake, and are removing it from future browsers.

There are generally better individual JavaScript workarounds for IE6’s various CSS shortcomings.

It is rather sad that so many companies are still sticking with the dire IE6. Maybe if you deliver the project late they’ll have upgraded by then!

share|improve this answer

answered Feb 5 ’09 at 16:10

bobincebobince

470k9595 gold badges600600 silver badges786786 bronze badges

I inquired about that. Turns out that they’ve been wanting to upgrade to IE7 for ages now. Unfortunately some important banking application of theirs does not work on IE7. The upgrade date has been set further and further many times now. Next attempt is scheduled for January 1, 2010…

– Vilx-
Feb 5 ’09 at 16:22

1

sigh… yes, that kind of thing does sound depressingly familiar. If only MS hadn’t ‘helpfully’ integrated the browser we could all be running IE7 whilst keeping IE6 around for legacy apps, and MS wouldn’t have to build-in eternal bug-compatibility.

– bobince
Feb 5 ’09 at 18:56

add a comment
 | 

4

It is possible to make IE expressions perform optimally, not only to avoid things like continuous re-evaluation, but to also hook your desired style to IE-specific classnames, therefore making your IE-Specific CSS easier to maintain (as the expressions themselves are disgusting):

input
{
1:expression(this.executedExpressions ? void 0 : this.className += (this.type == ‘text’ ? ‘ ie-text’ : ”));
2:expression(this.executedExpressions = true);
}

input.ie-text
{
background-color:silver;
}

If you’re going to use IE expressions at all, this is the best way. (I really ought to write a thorough article about it).

share|improve this answer

edited Aug 20 ’14 at 9:07

answered Nov 19 ’09 at 9:35

Lee KowalkowskiLee Kowalkowski

10.8k33 gold badges3333 silver badges4444 bronze badges

add a comment
 | 

2

Unfortunately CSS expressions are very poor performance wise, as the result is calculated constantly, all the time the page is loaded, not just when the page is first loaded. If you have to use expressions then you’d be better off use using standard JavaScript with an onLoad event.

See this article for more info: http://www.robertnyman.com/2007/11/13/stop-using-poor-performance-css-expressions-use-javascript-instead/

share|improve this answer

answered Feb 5 ’09 at 16:00

Jack SleightJack Sleight

16.2k66 gold badges3535 silver badges5353 bronze badges

add a comment
 | 

2

I’d suggest you to switch to any JS Framework which supports CSS Selectors so you can emulate the behaiviour of CSS expressions

you can test JS Frameworks performance if you open this URL on IE6

http://slicktest.perrohunter.com

cheers

share|improve this answer

answered Feb 5 ’09 at 16:51

perrohunterperrohunter

2,86577 gold badges3131 silver badges5151 bronze badges

I’d personally choose mootools =)

– perrohunter
Feb 5 ’09 at 16:52

I have no experience with JS framweorks. Plus, My website is in ASP.NET+AJAX. Will I not have to call something like “RefreshCSS()” repeatedly?

– Vilx-
Feb 6 ’09 at 9:30

You could modify your request applying a decorator pattern to the .NET Ajax object so it’d call the function you need at the end of every request, else you could modify it. cheers

– perrohunter
Feb 13 ’09 at 15:10

add a comment
 | 

1

Yes, expressions are realy slow in IE period. Find ways to avoid them.

share|improve this answer

answered Feb 5 ’09 at 15:59

AnthonyWJonesAnthonyWJones

171k3030 gold badges225225 silver badges295295 bronze badges

add a comment
 | 

1

I haven´t tried it myself, but IE7-js looks promising. It claims to make IE6 compatible with IE7

Edit: By the way, to just add some styles for IE6, you can also use

<!–[if lt IE 7]>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”https://stackoverflow.com/ie6styles.css” />
<![endif]–>

And you can always use jquery to set css properties dynamically in all browsers including IE6.

share|improve this answer

answered Feb 5 ’09 at 16:48

jeroenjeroen

86k1919 gold badges104104 silver badges126126 bronze badges

add a comment
 | 

0

If you do have to use them, the techniques found at One-time execution of IE CSS expressions will help with the performance (but not security) issues.

share|improve this answer

answered Aug 18 ’10 at 22:25

Kevin HakansonKevin Hakanson

37k2222 gold badges118118 silver badges146146 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged javascript css performance internet-explorer-6 css-expressions or ask your own question.

Blog

Podcast: Coaching a Developer Interview

Trying to find your first dev job? Here’s what employers are actually looking…

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Linked

17

How to style <input type=“text”> in IE6 CSS?

Related

3252Set cellpadding and cellspacing in CSS?2243How do I give text or an image a transparent background using CSS?3066Is there a CSS parent selector?2914Improve INSERT-per-second performance of SQLite?3917Change an HTML5 input’s placeholder color with CSS2050How can I transition height: 0; to height: auto; using CSS?1813How do CSS triangles work?2761Is it possible to apply CSS to half of a character?

Hot Network Questions

Technique for driving hinge screws to minimize misalignment

How to apply PCA on 3 dimensional image data in python

Is there a good way to communicate choose at least one?

Is this violation of academic integrity if I ask a question on Github public repository and post it as an issue?

Co-authorship for grammatical editing

Has a recent update broken mathbf when using mathspec?

In a mathematics publication, is it preferable to state all definitions immediately, or as they arise?

Is it possible to change the current GPLv3 license to something else?

How to indicate that “I need more time to consider your draw offer” in a formal game?

Is there any way to remove a rear cassette WITHOUT a cassette wrench?

Contractor day rate – calculating based off pro rata annual ‘salary’

Why do goblins never form societies bigger than about 500 members?

Why do airliners park with the nose facing the terminal?

Dystopia of a world where old people get killed

Can a world where everyone has a time machine be consistent?

How to make Minimize with Sqrt calculate faster?

When is it appropriate to introduce a new layer of abstraction into a class hierarchy?

How to use rounding with 6809 multiplication

How the first IAM page is found by SQL Server

ASCII Pizza (no pineapple)

Managing New Player “Murder Hobos”

Exit doesn’t work

Instance of my rocket and original model both displaying in render

I need to examine an 82.7 GB (!) text file. What can open it?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-js

Categories
askquestion

Add last n lines of files to tar/zip

Add last n lines of files to tar/zip

Ask Question

Asked
11 years ago

Active
1 year, 9 months ago

Viewed
628 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

0

I need to regularly send a collection of log files that can grow quite large, so I would like to only send the last n lines of the each of the files.

for example:

/usr/local/data_store1/file.txt (500 lines)
/usr/local/data_store2/file.txt (800 lines)

Given a file with a list of needed files named files.txt, I would like to create an archive (tar or zip) with the last 100 lines of each of those files.

I can do this by creating a separate directory structure with the tail-ed files, but that seems like a waste of resources when there’s probably some piping magic that can happen to accomplish it. Full directory structure also must be preserved since files can have the same names in different directories.

I would like the solution to be a shell script if possible, but perl (without added modules) is also acceptable (this is for Solaris machines that don’t have ruby/python/etc.. installed on them.)

unix shell zip tar

share|improve this question

edited May 4 ’18 at 14:13

Paul Floyd

3,04333 gold badges2222 silver badges3535 bronze badges

asked Feb 5 ’09 at 15:52

Dan McNevinDan McNevin

21.4k44 gold badges3232 silver badges2828 bronze badges

add a comment
 | 

5 Answers
5

active

oldest

votes

1

You could try

tail -n 10 your_file.txt | while read line; do zip /tmp/a.zip $line; done

where a.zip is the zip file and 10 is n or

tail -n 10 your_file.txt | xargs tar -czvf test.tar.gz —

for tar.gz

share|improve this answer

edited Feb 5 ’09 at 16:03

answered Feb 5 ’09 at 15:58

Johannes WeissJohannes Weiss

43.7k1414 gold badges9191 silver badges124124 bronze badges

add a comment
 | 

1

You are focusing in an specific implementation instead of looking at the bigger picture.

If the final goal is to have an exact copy of the files on the target machine while minimizing the amount of data transfered, what you should use is rsync, which automatically sends only the parts of the files that have changed and also can automatically compress while sending and decompress while receiving.

Running rsync doesn’t need any more daemons on the target machine that the standard sshd one, and to setup automatic transfers without passwords you just need to use public key authentication.

share|improve this answer

answered May 18 ’09 at 20:24

windenwinden

2,11711 gold badge1212 silver badges66 bronze badges

add a comment
 | 

0

There is no piping magic for that, you will have to create the folder structure you want and zip that.

mkdir tmp
for i in /usr/local/*/file.txt; do
mkdir -p “`dirname tmp/${i:1}`”
tail -n 100 “$i” > “tmp/${i:1}”
done
zip -r zipfile tmp/*

share|improve this answer

edited Feb 5 ’09 at 16:56

answered Feb 5 ’09 at 16:06

soulmergesoulmerge

65.2k1717 gold badges108108 silver badges144144 bronze badges

add a comment
 | 

0

Use logrotate.

Have a look inside /etc/logrotate.d for examples.

share|improve this answer

answered Feb 5 ’09 at 20:03

hendryhendry

7,2771111 gold badges5656 silver badges9090 bronze badges

add a comment
 | 

-1

Why not put your log files in SCM?

Your receiver creates a repository on his machine from where he retrieves the files by checking them out.

You send the files just by commiting them. Only the diff will be transmitted.

share|improve this answer

answered Feb 5 ’09 at 16:01

mouvicielmouviciel

59.6k1010 gold badges9999 silver badges133133 bronze badges

Yes. And this is extremely easy to implement and to use, given that cvs or svn is already installed of course.

– mouviciel
Feb 5 ’09 at 21:02

It’s definitely an interesting solution, but not really applicable for this case. I need to tar up logs to send to an external support origination on an infrequent basis. I also don’t want to send gigantic logs, just the last few lines when an error occurs.

– Dan McNevin
Feb 5 ’09 at 22:30

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged unix shell zip tar or ask your own question.

Blog

Podcast: Coaching a Developer Interview

Trying to find your first dev job? Here’s what employers are actually looking…

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Linked

0

how to tar last few lines

Related

828Shell command to sum integers, one per line?1414Why should text files end with a newline?615How can I reverse the order of lines in a file?778Shell command to tar directory excluding certain files/folders1572How to count all the lines of code in a directory recursively?1310Looping through the content of a file in Bash1722Delete lines in a text file that contain a specific string1768How can I recursively find all files in current and subfolders based on wildcard matching?249Tar a directory, but don’t store full absolute paths in the archive932How are zlib, gzip and zip related? What do they have in common and how are they different?

Hot Network Questions

Jumping off of a cliff into water – survival tips

How to make Minimize with Sqrt calculate faster?

Conceptual reason that monadic functors create limits?

Why is carbon dioxide a non-polar molecule?

ASCII Pizza (no pineapple)

How to indicate that “I need more time to consider your draw offer” in a formal game?

Can a university legally enforce a policy preventing students from creating their own wireless networks?

Where to store passport during day trip in foreign country

What’s the difference between “люблю” and “обожаю”?

Difference between hfil and hfill

I need to examine an 82.7 GB (!) text file. What can open it?

What is the word for an animal species which only eats one type of food?

Can a Loxodon PC wield a 2-handed sword and a shield with one hand and their trunk?

Supermarket Product Inventory Management with Polymorphic Product Types

What is the moustache mode in Plants vs Zombies?

Why is learning mathematics compulsory?

Managing New Player “Murder Hobos”

Why does the same proportion of a radioactive substance decay per time period? (half life)

Are There Energy Monitoring Smart Plugs That Don’t Compromise my Privacy/Security?

Can a professor tell you that you can’t use your phone before or after their class?

Egg, sausage, bacon and spam (lovely spam!)

Any tips for photographing a political rally?

Where in Sphere-Space is Telene?

Is this violation of academic integrity if I ask a question on Github public repository and post it as an issue?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-sh

Categories
askquestion

Create a semi-transparent cursor from an image

Create a semi-transparent cursor from an image

Ask Question

Asked
11 years ago

Active
3 years, 6 months ago

Viewed
9k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

9

3

Is it possible to create a cursor from an image and have it be semi-transparent?

I’m currently taking a custom image and overylaying the mouse cursor image. It would be great if I could make this semi-transparent, but not necessary. The sales guys love shiny.

Currently doing something like this:

Image cursorImage = customImage.GetThumbnailImage(300, 100, null, IntPtr.Zero);
cursorImage.SetResolution(96.0F, 96.0F);
int midPointX = cursorImage.Width / 2;
int midPointY = cursorImage.Height / 2;
Bitmap cursorMouse = GetCursorImage(cursorOverlay);
Graphics cursorGfx = Graphics.FromImage(cursorImageCopy);
cursorGfx.DrawImageUnscaled(cursorMouse, midPointX, midPointY);

Cursor tmp = new Cursor(cursorImage.GetHicon());

alt text http://members.cox.net/dustinbrooks/drag.jpg

c# winforms cursor transparency

share|improve this question

edited May 1 ’14 at 7:27

tshepang

9,8051919 gold badges7575 silver badges118118 bronze badges

asked Feb 5 ’09 at 15:54

Dustin BrooksDustin Brooks

2,36722 gold badges2121 silver badges3232 bronze badges

add a comment
 | 

4 Answers
4

active

oldest

votes

6

I’ve tried following example, and it was working fine…

public struct IconInfo
{
public bool fIcon;
public int xHotspot;
public int yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}

[DllImport(“user32.dll”)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);

[DllImport(“user32.dll”)]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);

public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
{
IntPtr ptr = bmp.GetHicon();
IconInfo tmp = new IconInfo();
GetIconInfo(ptr, ref tmp);
tmp.xHotspot = xHotSpot;
tmp.yHotspot = yHotSpot;
tmp.fIcon = false;
ptr = CreateIconIndirect(ref tmp);
return new Cursor(ptr);
}

And i’ve put this on button click event (you can call from where you like):

Bitmap b = new Bitmap(“D:/Up.png”);
this.Cursor = CreateCursor(b, 5, 5);

And the Up.png image is saved with 75% opacity in AdobePhotoshop.

share|improve this answer

edited May 17 ’12 at 2:58

azian.otaku

9722 silver badges1515 bronze badges

answered Sep 11 ’09 at 6:52

ZokiManasZokiManas

68255 silver badges88 bronze badges

add a comment
 | 

0

On the top of my head (I would try that first):

create new bitmap with same size as original, but with ARGB structure
drawimage: existing bitmap to the new bitmap
access raw bitmap data, and replace A bytes with 128

You should have nice semitransparent bitmap there.

If performance allows, you can scan for fully transparent pixels and set A to zero for them!

share|improve this answer

answered Sep 4 ’09 at 21:39

Daniel MošmondorDaniel Mošmondor

18.2k1111 gold badges5151 silver badges9494 bronze badges

add a comment
 | 

0

If you want to set transparency of a custom mouse cursor bitmap ‘on the fly’ you may find this function helpful. It uses a color matrix to set the amount of transparency to any given bitmap and will return the modified one. To have just a touch of transparency the TranspFactor should be between 225 and 245, just try it out. (You need to import System.Drawing and System.Drawing.Imaging)

public static Bitmap GetBMPTransparent(Bitmap bmp, int TranspFactor)

{

Bitmap transpBmp = new Bitmap(bmp.Width, bmp.Height);
using (ImageAttributes attr = new ImageAttributes()) {
ColorMatrix matrix = new ColorMatrix { Matrix33 = Convert.ToSingle(TranspFactor / 255) };
attr.SetColorMatrix(matrix);
using (Graphics g = Graphics.FromImage(transpBmp)) {
g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attr);
}
}
return transpBmp;

}

share|improve this answer

edited Aug 9 ’16 at 13:56

answered Aug 9 ’16 at 13:42

pewehhpewehh

122 bronze badges

add a comment
 | 

-2

that is very easy, I don’t use API.

the code is

Bitmap img = new Bitmap(new Bitmap(@”image.png”), 30, 30); //this is the size of cursor

Icon icono = Icon.FromHandle(img.GetHicon()); //create the Icon object

Cursor = new Cursor(icono.Handle); //the icon Object has the stream to create a Cursor.

I hope that is your solution

share|improve this answer

edited Sep 21 ’12 at 18:10

Gonzalo.-

10.4k44 gold badges4343 silver badges7171 bronze badges

answered Sep 21 ’12 at 17:23

MC.Martin Sarabia AquinoMC.Martin Sarabia Aquino

11

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged c# winforms cursor transparency or ask your own question.

Blog

Podcast: Coaching a Developer Interview

Trying to find your first dev job? Here’s what employers are actually looking…

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Linked

3

WPF Adorners in WinForms

Related

1841How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?881Creating a byte array from a stream1361How do I update the GUI from another thread?1755Get int value from enum in C#248How can I make the cursor turn to the wait cursor?1Am I responsible for Disposing a BackgroundImage?405SVG fill color transparency / alpha?602How to make a background 20% transparent on Android19How do I draw a rectangle onto an image with transparency and text

Hot Network Questions

Does the Z80 allow interrupts after processing and ignoring a 0xdd prefix?

I need to examine an 82.7 GB (!) text file. What can open it?

Why do airliners park with the nose facing the terminal?

What is the moustache mode in Plants vs Zombies?

What happens to Victor Creed after “X-Men Origins: Wolverine”?

ASCII Pizza (no pineapple)

How to use rounding with 6809 multiplication

Integrating acceleration – wrong choice of bounds in textbooks?

First treatment of autism in speculative fiction

Why is offering draw not recorded but giving a check recorded?

Is Planning Poker Bad for Software Development Teams?

How to deal with parents that enforce a curfew on an adult

In a mathematics publication, is it preferable to state all definitions immediately, or as they arise?

Why did equal temperament become the standard tuning system for keyboard instruments?

Can a Loxodon PC wield a 2-handed sword and a shield

Why do goblins never form societies bigger than about 500 members?

What is the word for an animal species which only eats one type of food?

Why did the Z80 with 4-bit ALU out-perform the fully 8-bit Intel 8080?

Incorporating fruits in creme brulee

Why do most countries have so many members of parliament?

What verb forms εἴσηκται as 3 s pf m/p?

Is this picture of Trump, Bloomberg, and Clinton playing golf real?

I hate Valentine’s Day

When a spell asks for targets, can I choose the same target multiple times?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-cs

Categories
askquestion

Is there a “canonical” name for a function combining min() and max()?

Is there a “canonical” name for a function combining min() and max()?

Ask Question

Asked
11 years ago

Active
5 years, 9 months ago

Viewed
2k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

23

2

I find that I frequently end up writing a function that I always call “clamp()”, that is kind of a combination of min() and max(). Is there a standard, “canonical” name for this function?

It always looks something like this:

function clamp($val, $lower, $upper)
{
if ($val < $lower)
return $lower;
else if ($val > $upper)
return $upper;
else
return $val;
}

Or simply using built-in min() and max() functions:

function clamp($val, $lower, $upper)
{
return max($lower, min($upper, $val));
}

Variations exist: You can also check for invalid input, where lower > upper, and either throw an exception or reverse the inputs. Or you can ignore order of the inputs and call it a median-of-three function, but that can be confusing.

language-agnostic standards nomenclature

share|improve this question

edited Oct 18 ’12 at 18:38

Kip

asked Feb 5 ’09 at 15:55

KipKip

92.5k7979 gold badges215215 silver badges254254 bronze badges

I’d avoid giving your parameters the same names as the functions used, particularly as they’re not used in matching pairs (i.e. $min is used with max() and vice-versa). Perhaps $lower and $upper, instead.

– Ben Blank
Feb 5 ’09 at 16:39

@BenBlank: good idea. edited the question

– Kip
Oct 18 ’12 at 18:39

I use the name InRange() but my comment is not about the name, it is about the ordering of the parameters. I find it easier to read: InRange(min,value,max) than (value,min,max)

– Manuel Gonzalez
Oct 24 ’12 at 18:39

add a comment
 | 

8 Answers
8

active

oldest

votes

37

clamp is a good name.

Let us make it the standard.

share|improve this answer

answered Feb 5 ’09 at 16:00

NiyazNiyaz

45.6k5454 gold badges139139 silver badges179179 bronze badges

2

Seems to be standard (at least in graphics) already: en.wikipedia.org/wiki/Clamping_%28graphics%29

– Zach Scrivena
Feb 5 ’09 at 16:05

Kind of a great name after I understood what it was. Plus one to the standard.

– Rodrigo
Feb 5 ’09 at 16:10

1

I think “clip” is more commonly used.

– John D. Cook
Feb 5 ’09 at 16:29

Numbers may be clamped, while images may be clipped.

– yfeldblum
Jul 9 ’09 at 16:44

1

C++17 has std::clamp.

– Knu
Jun 28 ’16 at 2:46

add a comment
 | 

5

In some languages you have the function limit

num = limit(val, min, max)

share|improve this answer

answered Feb 5 ’09 at 16:06

Jim CJim C

5,0011818 silver badges2525 bronze badges

add a comment
 | 

3

clip(val, lo, hi)

share|improve this answer

answered Feb 5 ’09 at 16:26

jfsjfs

304k115115 gold badges746746 silver badges13531353 bronze badges

add a comment
 | 

1

We use pin here. Actually, we use pin for simple ranges and clamp for other stuff.

share|improve this answer

answered Feb 5 ’09 at 16:43

MSNMSN

46.9k77 gold badges6565 silver badges9494 bronze badges

add a comment
 | 

0

I’d just go for a function name “rangeCheck”

share|improve this answer

answered Feb 5 ’09 at 15:59

tehvantehvan

8,62344 gold badges2424 silver badges3131 bronze badges

1

not good, rangeCheck sounds like it CHECKS. But what it does is CHANGING values to be in a range.

– Thorsten79
Feb 5 ’09 at 16:03

add a comment
 | 

0

median

Because it generalizes to more values.

share|improve this answer

answered Feb 5 ’09 at 16:41

Craig GidneyCraig Gidney

15.3k44 gold badges5757 silver badges119119 bronze badges

1

This isn’t about finding statistical information about a sample set. It’s about forcing a number to be in a particular range.

– MSN
Feb 5 ’09 at 16:44

2

@MSN: technically median(val, min, max) will do the same thing as clamp(val, min, max). plus, the order of the parameters to median() wouldn’t matter. but that’s not immediately obvious (at least, it wasn’t to me).

– Kip
Feb 5 ’09 at 17:46

Median has the advantage of being self descriptive. You get the median element back. For example, will “clamp” throw an exception if my min is less than my max? In that case, which argument is the min? First or second? These details might change from place to place.

– Craig Gidney
Feb 6 ’09 at 1:25

I must disagree with median being self descriptive, since we don’t want the median of a given set of values, but clamp a given value to some boundaries. While that may be the same operation internally (well not exactly, but close enough), the purpose of that median call wouldn’t be as clear as for example clamp, so it gets harder for other people to read the code.

– Grizzly
Dec 31 ’09 at 13:12

add a comment
 | 

0

What about bound?

bound(min, val, max)

Or constrain?

constrain(val, min, max)

share|improve this answer

edited Oct 24 ’12 at 2:43

answered Oct 17 ’12 at 19:14

KnuKnu

13.4k55 gold badges5252 silver badges8282 bronze badges

add a comment
 | 

0

What do you think of things like InRangeClosestTo(Number, RangeLowerBound, RangeUpperBound), or ClosestInRange(Number, LowerBoundOfRange, UpperBoundOfRange)? They mean ‘Get me the element of the range closest to the number’, as I hope is obvious.

The concept is more precise than a Clamp that yeah has two sides but not much more, or a Limit or Bound that might not want to return anything if the number is not within the range,

To me they are clearer then the rest I saw; although it can take a couple of seconds to understand them, you only need to reason about the name, and at most have a brief look at the comment for confirmation; and it’s nice when you see how precise it is (it is precise, right?).

You might only have doubts on whether the range is inclusive or not, but I think most people would correctly assume it’s inclusive. Alternatively you might use InInclRangeClosestTo and InExclRangeClosestTo, althought I don’t see a lot of uses for exclusive ranges.

Of course you should have an auto-completing IDE if you wanted to use them.

share|improve this answer

edited Apr 30 ’14 at 14:57

answered Apr 17 ’14 at 20:18

gbrgbr

99444 silver badges2323 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged language-agnostic standards nomenclature or ask your own question.

Blog

Community working group updates: February 2020

Podcast: Coaching a Developer Interview

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Linked

31

How to force a number to be in a range in C#?

Related

732What is a lambda (function)?780Should a function have only one return statement?1702What’s the difference between a method and a function?669What is a callback function?211File name? Path name? Base name? Naming standard for pieces of a path286Coding Conventions – Naming Enums45International phone number max and min?337How to explain callbacks in plain english? How are they different from calling one function from another function?

Hot Network Questions

Are There Energy Monitoring Smart Plugs That Don’t Compromise my Privacy/Security?

Contractor day rate – calculating based off pro rata annual ‘salary’

What happens to Victor Creed after “X-Men Origins: Wolverine”?

What verb forms εἴσηκται as 3 s pf m/p?

Can a university legally enforce a policy preventing students from creating their own wireless networks?

What is the moustache mode in Plants vs Zombies?

set duo tone color of fontawesome5 duotone icons

Three way switch with two common wires?

Any tips for photographing a political rally?

Where to sell metals with numismatic value

What is right way to set up King & Queen In the beginning of game?

Has any accident been prevented by bending or breaking the rules?

Were Vietnam veterans spat on?

My name is akin to my size

Is there a good way to communicate choose at least one?

Where in Sphere-Space is Telene?

How to use rounding with 6809 multiplication

Octahedra+tetrahedra space-filling tessellations in 3D

Is Planning Poker Bad for Software Development Teams?

Is this violation of academic integrity if I ask a question on Github public repository and post it as an issue?

Detect manual changes to an autogenerated C header

Daily magnitude of Betelgeuse

Apocryphal (?) tale of hard drive platter propelled through a wall?

Conceptual reason that monadic functors create limits?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Categories
askquestion

Is there a Vim equivalent to the Linux/Unix “fold” command?

Is there a Vim equivalent to the Linux/Unix “fold” command?

Ask Question

Asked
11 years ago

Active
4 years, 5 months ago

Viewed
779 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

6

3

I realize there’s a way in Vim to hide/fold lines, but what I’m looking for is a way to select a block of text and have Vim wrap lines at or near column 80.

Mostly I want to use this on comments in situations where I’m adding some text to an existing comment that pushes it over 80 characters. It would also be nice if it could insert the comment marker at the beginning of the line when it wraps too. Also I’d prefer the solution to not autowrap the entire file since I have a particular convention that I use when it comes to keeping my structured code under the 80 character line-length.

This is mostly for Python code, but I’m also interested in learning the general solution to the problem in case I have to apply it to other types of text.

python vim formatting comments word-wrap

share|improve this question

edited Aug 8 ’12 at 18:02

Keith Pinson

6,37155 gold badges4747 silver badges9191 bronze badges

asked Feb 5 ’09 at 15:56

Joe HollowayJoe Holloway

23k1212 gold badges7474 silver badges8989 bronze badges

add a comment
 | 

2 Answers
2

active

oldest

votes

11

gq

It’s controlled by the textwidth option, see “:help gq” for more info.

gq will work on the current line by default, but you can highlight a visual block with Ctrl+V and format multiple lines / paragraphs like that.

gqap does the current “paragraph” of text.

share|improve this answer

edited Sep 17 ’15 at 22:25

Sagar Jain

5,61177 gold badges3737 silver badges6969 bronze badges

answered Feb 5 ’09 at 16:02

Philip ReynoldsPhilip Reynolds

8,76433 gold badges2525 silver badges3535 bronze badges

add a comment
 | 

0

Take a look at “:help =” and “:help ‘equalprg”

:set equalprg=fold

and in normal mode == filters the current line through the external fold program. Or visual-select something and hit =

share|improve this answer

answered Feb 6 ’09 at 12:12

user55400user55400

3,44511 gold badge1818 silver badges1313 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged python vim formatting comments word-wrap or ask your own question.

Blog

Community working group updates: February 2020

Podcast: Coaching a Developer Interview

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Related

1902How to replace a character by a newline in Vim1597Duplicate a whole line in Vim4711Calling an external command from Python107What is the recommended way to use Vim folding for Python code1854Vim clear last search highlighting1112What’s a quick way to comment/uncomment lines in Vim?1614How to do case insensitive search in Vim1372How does the vim “write with sudo” trick work?1061What is the difference between the remap, noremap, nnoremap and vnoremap mapping commands in Vim?3626How do I exit the Vim editor?

Hot Network Questions

Linux backup utility for incremental backups

Is this picture of Trump, Bloomberg, and Clinton playing golf real?

What is the word for an animal species which only eats one type of food?

Single NPN or NPN+PNP (push pull) to drive a P-MOSFET

Drawing from the Deck of Many Things with a Simulacrum

Siunitx comma as separator in unit exponent

My name is akin to my size

Why doesn’t the ‘bm’ package work with the ‘unicode-math’ package?

Is there any material which cannot be cut by a lightsaber?

How does the Control Weather spell interact with the Dispel Magic spell?

Why did the Germans use the Enigma machine rather than the far superior “Lorenz” cipher machine?

If a device is rated at 12 V/80 mA what does that mean as far as the length of time that it will draw 80 mA?

Looking for an Animated Children’s TV Show about Time Travel

Dystopia of a world where old people get killed

Why is carbon dioxide a non-polar molecule?

Why do airliners park with the nose facing the terminal?

Why does adverse yaw exist?

When is it appropriate to introduce a new layer of abstraction into a class hierarchy?

Why do goblins never form societies bigger than about 500 members?

Can a pilot initiate an enroute descent to an IAF without ATC ‘s approval?

Why is late Russian Empire associated with Byzantium while having little in common with it?

Any tips for photographing a political rally?

Can I use 12-2 wire on a 20amp breaker to power an entire bathroom?

Managing New Player “Murder Hobos”

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-py

Categories
askquestion

How do I add more than one project/solution on the same path to TFS

How do I add more than one project/solution on the same path to TFS

Ask Question

Asked
11 years ago

Active
4 years ago

Viewed
629 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

2

2

I am working on a C# project which must be built for more than one platform (.Net and CF.Net) and from past experiences I have found that the best approach that works for me is to have multiple parallel solutions present side by side in the same folder corresponding to each platform. All the code files, resources etc are shared by these projects/solutions and are common for all parallel projects.

Eg.

/SolutionFolder
MySolution.sln
MySolution_CE.sln
/MyProject
MyProject.csproj
MyProject_CE.csproj

Now the problem is once I add MySolution.sln to source control I cannot add MySolution_CE.sln. It says something on the lines of “Cannot add two solutions on the same path”.

<edit>
To answer ctake’s question, I am trying to add the solution from VS2008 by right clicking on the solution and saying “Add to source control”.

Also I forgot to mention that I added the solutions manually anyway but VS2008 does not bind to this solution i.e. the files cannot be checked in/out from these “forced” solutions from within VS2008.
</edit>

visual-studio-2008 tfs

share|improve this question

edited Feb 18 ’16 at 15:52

Daniel Mann

44.9k1010 gold badges7676 silver badges9696 bronze badges

asked Feb 5 ’09 at 15:57

AutodidactAutodidact

23.8k1515 gold badges5959 silver badges7979 bronze badges

1

We have a large number of solutions in the same TFS folder. Can you give more details on how you’re adding to TFS and what the actual error is?

– ctacke
Feb 5 ’09 at 16:01

add a comment
 | 

3 Answers
3

active

oldest

votes

1

Try using the command line tools – tf.exe, and then setting up the bindings by using the File/Source Controls/Change Source Control… dialog once you’ve opened the unbound solution.

share|improve this answer

answered Feb 15 ’09 at 19:15

Dominic HoptonDominic Hopton

7,12411 gold badge1919 silver badges2929 bronze badges

add a comment
 | 

1

Ok, here is a possible work around to this problem. Needless to say it’s inelegant but it works nevertheless without going through the pains of writing a custom source control addin for VS2008…

Steps:
1. Open MySolution.sln in visual studio and then say add to source control then check in the first version.
2. Goto File->Source Control->Change Source control and unbind the solution from the source control.
3. Close the MySolution.sln
4. Open MySolution_CE.sln
5. Goto File->Source Control->Change Source control and bind the solution from the source control by clicking on Bind VS2008 should pick up the correct bindings automatically if the dir structure mentioned in the question was adhered to.
6. Add CE specific files to the solutions/projects and do an initial checkin.
7. Repeat this bind/unbind operation each time you wish to do a checkin from the other solution (I know this is a pain).

Hope this helps.

share|improve this answer

answered Mar 23 ’09 at 16:37

AutodidactAutodidact

23.8k1515 gold badges5959 silver badges7979 bronze badges

add a comment
 | 

1

The “Add Solution To Source Control” wizard isn’t really necessary if you are using TFS + you already have workspace mappings set up. (If you are using another source control system, or the solution folder is not mapped, this is not true.)

All you need to do is write bindings into the sln/proj files using the Change Source Control dialog. Unlike the full-blown wizard, the CSC dialog should not have any checks that stop you from binding >1 solution that live side by side.

share|improve this answer

answered Jun 6 ’09 at 22:33

Richard BergRichard Berg

19.7k22 gold badges5959 silver badges8585 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged visual-studio-2008 tfs or ask your own question.

Blog

Community working group updates: February 2020

Podcast: Coaching a Developer Interview

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Related

52Howto resolve… Visual Studio Source Control notification “Projects have recently been added to this solution”146The project file has been moved renamed or is not on your computer0TFS: Choose which Team Project to add a solution too69Why does Visual Studio check out the .vspscc file when I add a file to a project?4VS 2008 – Star Team and multi project solution?98Visual Studio retrieving an incorrect path to a project from somewhere1How do I save the start-up project I selected in VS20084Add solution to different TFS team project0VS 2010 – Adding additional projects to Solution26How to add existing project to Visual studio 2012 after renaming the project path

Hot Network Questions

How to deal with parents that enforce a curfew on an adult

Can random forest detect squared terms?

Is Planning Poker Bad for Software Development Teams?

Can I use 12-2 wire on a 20amp breaker to power an entire bathroom?

Coupling Theory vs reality

Why is late Russian Empire associated with Byzantium while having little in common with it?

Is this violation of academic integrity if I ask a question on Github public repository and post it as an issue?

Why is learning mathematics compulsory?

Does the Z80 allow interrupts after processing and ignoring a 0xdd prefix?

ASCII Pizza (no pineapple)

set duo tone color of fontawesome5 duotone icons

Three way switch with two common wires?

Detect manual changes to an autogenerated C header

Drawing from the Deck of Many Things with a Simulacrum

How to use rounding with 6809 multiplication

Is it ever neccesary to burn a starter out?

Egg, sausage, bacon and spam (lovely spam!)

“Guardians of the Galaxy” soundtrack and Quill’s “Awesome Music Mix”

Where to store passport during day trip in foreign country

Is there any way to remove a rear cassette WITHOUT a cassette wrench?

Two network cards, which provides internet?

How does apt upgrade running programs?

Why doesn’t the ‘bm’ package work with the ‘unicode-math’ package?

How do I know whether an airline seat upgrade at gate was free?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Categories
askquestion

Has anyone been able to edit text in an OpenWYSIWYG control dynamically?

Has anyone been able to edit text in an OpenWYSIWYG control dynamically?

Ask Question

Asked
11 years ago

Active
10 years, 1 month ago

Viewed
689 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

2

1

Like the question says has anyone been able to take a OpenWYSIWYG control and change its contents dynamically with JavaScript? It’s hard because it takes your textarea and transforms it into a WYSIWYG editor by making the textarea invisible and inserting some kind of iframe and uses that as the editor.

I’ve tried code like this but failed:

document.getElementById(“textarea-wysiwyg”).value = “BLARG”;

javascript openwysiwyg

share|improve this question

edited Feb 5 ’09 at 17:03

Andrew G. Johnson

asked Feb 5 ’09 at 15:59

Andrew G. JohnsonAndrew G. Johnson

24.3k2929 gold badges8585 silver badges132132 bronze badges

add a comment
 | 

1 Answer
1

active

oldest

votes

1

If you know that is it the only frame on the page then you can do something like this:

window.frames[0].document.body.innerHTML = ‘blarg’

The above works when I tried it on http://www.openwebware.com/wysiwyg/demo.shtml in firebug.

Hope this helps…

share|improve this answer

answered Feb 9 ’09 at 18:12

JackJack

17k1111 gold badges4141 silver badges4545 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged javascript openwysiwyg or ask your own question.

Blog

This week, #StackOverflowKnows fast planes, math with dates, and code comments

Community working group updates: February 2020

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Related

495Resizing an iframe based on content181jQuery .ready in a dynamically inserted iframe0how to add text to openwysiwig editor by javascript code outside openwysiwig474Detect when browser receives file download2197How to decide when to use Node.js?145YouTube iframe API: how do I control a iframe player that’s already in the HTML?1Proxying a site to be able to WYSIWYG edit in iframe – How does it work?

Hot Network Questions

ASCII Pizza (no pineapple)

Are There Energy Monitoring Smart Plugs That Don’t Compromise my Privacy/Security?

Why doesn’t the ‘bm’ package work with the ‘unicode-math’ package?

Dystopia of a world where old people get killed

How do I know whether an airline seat upgrade at gate was free?

When a spell asks for targets, can I choose the same target multiple times?

Were Data and Lore created as a ‘pair’?

Is there any advantage of using a travel agent in this day and age?

Hessian Matrix and Physical directions: Potential Energy Surface

Is there any way to remove a rear cassette WITHOUT a cassette wrench?

“electricity was suddenly turned off” or ” electricity suddenly turned off ”

What would be the best way to capture a Giant?

Three way switch with two common wires?

How to access Tridion Config Component in Event System

First non-elected person in line of succession for British Government or Parliament?

I need to examine an 82.7G (!) text file. What can open it?

Any tips for photographing a political rally?

Unexplained muscle mass loss

Integrating acceleration – wrong choice of bounds in textbooks?

Creating a Continuous Decision Variable between 0 and 1 in Python-MIP Interface

Drawing from the Deck of Many Things with a Simulacrum

Can a world where everyone has a time machine be consistent?

Overloading a function using templates

What early middle ages weapons would suit an extremely strong child?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-js

Categories
askquestion

Sql Server (Entity Framework): created_at , updated_at Columns

Sql Server (Entity Framework): created_at , updated_at Columns

Ask Question

Asked
11 years ago

Active
11 years ago

Viewed
3k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

4

4

I think I should mention I’m trying to get Entity FrameworkSQL server to do something that I was used to coming from Rails. I really just want to know the ‘best’ way to have automatic created_at & updated_at column values for records that I insert/update in the database.

Right now I’ve hooked into the ObjectContext.SavingChanges event and things are working well. After I wrote and tested my code however I realize that there may be a better or faster way to do this.

sql-server ruby-on-rails entity-framework

share|improve this question

edited Feb 5 ’09 at 17:25

Bill

asked Feb 5 ’09 at 15:59

BillBill

1,52311 gold badge1515 silver badges2828 bronze badges

add a comment
 | 

1 Answer
1

active

oldest

votes

9

One method is to use insert/update triggers to set the created_at and updated_at columns to the current time.

The Insert trigger would look something like this:

CREATE TRIGGER [dbo].[inserted_myTable] ON [dbo].[myTable] AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
UPDATE [dbo].[myTable] Set AdmitDateTime = GetDate() where pkid in (SELECT pkid FROM Inserted)
END

The Update trigger would look something like this:

CREATE TRIGGER [dbo].[updated_myTable] ON [dbo].[myTable] AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE [dbo].[myTable] Set AdmitDateTime = GetDate() where pkid in (SELECT pkid FROM Inserted)
END

One advantage of the trigger approach is that the time/date will always be in the same time zone. Another advantage is that if someone modifies the database record outside of your application, the fields are still updated.

share|improve this answer

edited Feb 5 ’09 at 17:08

answered Feb 5 ’09 at 16:23

Friend Of GeorgeFriend Of George

46811 gold badge44 silver badges1414 bronze badges

See here for an explaination of NOCOUNT: msdn.microsoft.com/en-us/library/ms189837.aspx

– Friend Of George
Feb 25 ’10 at 17:36

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged sql-server ruby-on-rails entity-framework or ask your own question.

Blog

This week, #StackOverflowKnows fast planes, math with dates, and code comments

Community working group updates: February 2020

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Linked

1

Automatically update Last Modified Date in ASP.Net MVC app

Related

818Entity Framework vs LINQ to SQL2700Add a column with a default value to an existing table in SQL Server1737How to return only the Date from a SQL Server DateTime datatype1817How to check if a column exists in a SQL Server table?1099Check if table exists in SQL Server1867How to concatenate text from multiple rows into a single text string in SQL server?1545LEFT JOIN vs. LEFT OUTER JOIN in SQL Server3608How do I UPDATE from a SELECT in SQL Server?1147Find all tables containing column with specified name – MS SQL Server1219How to Delete using INNER JOIN with SQL Server?

Hot Network Questions

What’s the difference between “люблю” and “обожаю”?

Any tips for photographing a political rally?

Who were the seven dwarves Sauron gave the Rings of Power to?

Three way switch with two common wires?

Do the US NTSB and other investigative agencies charge airlines for investigations?

How to modify a method which dynamically calls upon a set of various child classes to work for any new child class

Is it ever neccesary to burn a starter out?

Is there a unix-like system that doesn’t come with Perl?

Is there any material which cannot be cut by a lightsaber?

Hessian Matrix and Physical directions: Potential Energy Surface

First non-elected person in line of succession for British Government or Parliament?

My name is akin to my size

How do you name nodes/vertices with this type of code?

Is there any way to remove a rear cassette WITHOUT a cassette wrench?

Why did equal temperament become the standard tuning system for keyboard instruments?

How does apt upgrade running programs?

Incorporating fruits in creme brulee

Paint 21 Squares of a 7×7 Board Without Forming a Rectangle

What would be the best way to capture a Giant?

I need to examine an 82.7G (!) text file. What can open it?

Is it possible to run a monochrome LCD without driver circuit with an Arduino Uno?

ASCII Pizza (no pineapple)

Do UK visa documents not in English or Welsh have to be translated officially?

Why do airliners park with the nose facing the terminal?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-sql

Categories
askquestion

Altering the user-agent string with the HTMLControl

Altering the user-agent string with the HTMLControl

Ask Question

Asked
11 years ago

Active
6 years, 6 months ago

Viewed
72 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

0

I’m writing an app (VS2005, C++, targeting WM5) which is hosting the HTML Control. Can I modify the user-agent this control uses when making a request to a server?

windows-mobile

share|improve this question

edited Jul 29 ’13 at 22:11

meshy

6,21366 gold badges4040 silver badges6565 bronze badges

asked Feb 5 ’09 at 15:59

brismithbrismith

66633 silver badges1313 bronze badges

add a comment
 | 

1 Answer
1

active

oldest

votes

-1

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.addheader.aspx

Use AddHeader to modify the useragent.

Since you are in a control, use this to get to your current HttpResponse object.
this.Page.Response.AddHeader

share|improve this answer

edited Feb 5 ’09 at 16:28

answered Feb 5 ’09 at 16:06

Chris BallanceChris Ballance

30.4k2525 gold badges9898 silver badges147147 bronze badges

He doesn’t have an HttpResponse object. The question wants to know how to change the agent string being sent from an HTMLControl.

– ctacke
Feb 5 ’09 at 16:08

Sure he does. Just reference the current page’s HttpResponse object.

– Chris Ballance
Feb 5 ’09 at 16:29

I’m not using .Net CF. Is the HttpResponse object available by accessing a particular COM Interface?

– brismith
Feb 10 ’09 at 14:47

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged windows-mobile or ask your own question.

Blog

This week, #StackOverflowKnows fast planes, math with dates, and code comments

Community working group updates: February 2020

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Related

2Possible to detect the *type of mobile device* via javascript or HTTP Headers?2Windows Mobile Emulator networking to host machine1Auto-size controls in .NET CF to avoid horizontal scrolling?0Wrapping the HTML Control on Windows Mobile1HTML Control in Windows Mobile 6.1 Professional8Passing a C# string to an unmanaged C DLL in Windows Mobile1How to disable WM6.5.3 gestures?0Mobile Compact Framework 2.0 Install unsuccessful from Win7 generated from VS20081How to: WCF Service check if Windows Forms user is still active?

Hot Network Questions

Unexplained muscle mass loss

What’s the difference between “люблю” and “обожаю”?

What is the word for an animal species which only eats one type of food?

ASCII Pizza (no pineapple)

Dystopia of a world where old people get killed

Why are the clouds white and Australia black in weather satellite infrared images?

Any tips for photographing a political rally?

Incorporating fruits in creme brulee

Managing New Player “Murder Hobos”

Single NPN or NPN+PNP (push pull) to drive a P-MOSFET

Contractor day rate – calculating based off pro rata annual ‘salary’

How to deal with parents that enforce a curfew on an adult

How do I execute/test a large set of test cases with limited time and resources?

Regexp for matching quoted strings that may have control characters in them

How do I know whether an airline seat upgrade was free?

Linux backup utility for incremental backups

Fastest yes in the west

Flexibility over solidity? Defending against 1. e4

Is it ever neccesary to burn a starter out?

Why is learning mathematics compulsory?

How can I say “to be tired of verbING” in Japanese?

Who first solved the classical harmonic oscillator?

Detect manual changes to an autogenerated C header

What is this narrow band of clouds?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Categories
askquestion

Why doesn’t WebBBS work now that I’ve migrated to a new server?

Why doesn’t WebBBS work now that I’ve migrated to a new server?

Ask Question

Asked
11 years ago

Active
9 years, 8 months ago

Viewed
86 times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

0

I’ve moved a WebBBS board from one server to another. Ever since the board doesn’t work.
I’m getting an Apache error whenever I try to access the board. Don’t even know where to start the debugging, I’m not a Perl person. The file paths remained the same and there isn’t any DB involved.

http://gammonline.com/members/board/

Any ideas?

After a bit of testing I believe that the problem has something to do with the index.cgi which is located in that folder (not getting the error when renaming it).

Thanks,

Roy.

perl apache webbbs

share|improve this question

edited May 31 ’10 at 2:31

Sampson

239k6565 gold badges494494 silver badges540540 bronze badges

asked Feb 5 ’09 at 15:59

Roy PelegRoy Peleg

92022 gold badges88 silver badges2525 bronze badges

add a comment
 | 

2 Answers
2

active

oldest

votes

3

More information about this error may be available in the server error log.

Says it all. You will have to find the error log and look at it.

If you are using CGI, the first step is to check you have given it the right permissions so it is an executable script at all.

chmod 755 index.cgi

share|improve this answer

answered Feb 5 ’09 at 16:14

bobincebobince

470k9595 gold badges600600 silver badges786786 bronze badges

add a comment
 | 

1

This is caused by Apache config errors. Set LogLevel debug and tail -f the error log. It will probably be something to do with .htaccess permission for override, or, it’s requiring a module which isn’t loaded. The error log will tell you instantly.

share|improve this answer

answered Feb 5 ’09 at 16:07

Andrew TaylorAndrew Taylor

1,8641818 silver badges1919 bronze badges

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged perl apache webbbs or ask your own question.

Blog

This week, #StackOverflowKnows fast planes, math with dates, and code comments

Community working group updates: February 2020

Featured on Meta

TLS 1.0 and TLS 1.1 removal for Stack Exchange services

How do the moderator resignations affect me and the community?

Related

177How can I install Apache Ant on Mac OS X?35How to solve import errors while trying to deploy Flask using WSGI on Apache20URL rewriting question2Perl module Image::Imlib2 trouble saving gifs0Why is this .htaccess file mod_rewrite not working?2Perl library not working on WampServer0Issue moving file1Cygwin Perl CGI with Xampp

Hot Network Questions

How do Trump’s public statements make DOJ’s job impossible?

How can I say “to be tired of verbING” in Japanese?

“electricity was suddenly turned off” or ” electricity suddenly turned off ”

What is this narrow band of clouds?

Who were the seven dwarves Sauron gave the Rings of Power to?

Definition of a general rule

Coupling Theory vs reality

What happens if an aircraft tries to land at MTOW (if greater than MLW)?

Can random forest detect squared terms?

What is right way to set up King & Queen In the beginning of game?

How do Aarakocra fly with a backpack?

My name is akin to my size

How do I sail rafts in Breath of the Wild?

Since the caster of the Zone of Truth spell knows whether a creature failed the save, can they use it to detect hidden/invisible creatures?

Why do airliners park with the nose facing the terminal?

Why is learning mathematics compulsory?

Artificier Resistant Armor Infusion

When a spell asks for targets, can I choose the same target multiple times?

Can you Rappel with an Old Climbing Rope?

SQL Query timing out – Optimization Help?

DAD and link local address

Three way switch with two common wires?

How to access Tridion Config Component in Event System

Are There Energy Monitoring Smart Plugs That Don’t Compromise my Privacy/Security?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-perl