• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 19:16
CET 01:16
KST 09:16
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation13Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
[TLMC] Fall/Winter 2025 Ladder Map Rotation Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Clair Obscur - Expedition 33 Should offensive tower rushing be viable in RTS games? Stormgate/Frost Giant Megathread Nintendo Switch Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread About SC2SEA.COM Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2151 users

The Big Programming Thread - Page 74

Forum Index > General Forum
Post a Reply
Prev 1 72 73 74 75 76 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Craton
Profile Blog Joined December 2009
United States17266 Posts
August 18 2011 01:14 GMT
#1461
If something is O(n log n) and I'm sorting 1,000,000 numbers, how do I calculate that. I'm missing something.
twitch.tv/cratonz
Frigo
Profile Joined August 2009
Hungary1023 Posts
August 18 2011 15:06 GMT
#1462
On August 18 2011 10:14 Craton wrote:
If something is O(n log n) and I'm sorting 1,000,000 numbers, how do I calculate that. I'm missing something.

The constant term in the big O expression can be arbitrary, you need specific knowledge of how many steps does the algorithm take* and what are these steps, to calculate anything. In practice it is easier and better to measure the speed of the algorithm in msec instead of steps.

*: Also these steps can vary for the input data, so you are better off calculating maximum and average cases, assuming a specific distribution of the input data or extreme cases.

On August 15 2011 08:08 EvanED wrote:
Show nested quote +
On August 14 2011 14:49 Frigo wrote:
No sorry, the compiler is quite right about warning you, it simply can't be made safe. You need to know in advance whether the line fits in your buffer, and that is simply not possible with the standard input, only with files.

This is a bit of a red herring, which can be demonstrated two ways. First, calling fgets(buf, size, stdin) works fine, and is just like calling gets(buf) except that if it reads more than size bytes, it will stop early. (There's a difference in how it handles the trailing newline if it doesn't stop early, as well.) It's not like fgets is imbued with psychic powers to see what's coming up in the stream, it just makes a "best-effort" attempt to fit it in the given buffer. The second way you can see this is calling fgets on an actual file -- it doesn't figure out that the current line is too long to fit into the buffer and does nothing, it again makes that best-effort attempt.

(And as a third way: just because the runtime thinks something is a file doesn't mean it is -- it could be a device node, a fifo, etc. -- and doesn't mean it can seek randomly.)


Obviously the statement is true only for gets, fgets is completely different, it is not "just like" gets. This difference between gets and other methods makes it possible to employ various workarounds so you don't need to know the length of the line in advance to ensure safe operation. For the same reason it is also possible to use them on streams. I'd say the guy is best off by implementing an automatically growing vector structure and associated getline functions instead of sacrificing safety with gets or fooling around with a naked fgets.
http://www.fimfiction.net/user/Treasure_Chest
catamorphist
Profile Joined May 2010
United States297 Posts
August 18 2011 18:16 GMT
#1463
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Pigsquirrel
Profile Joined August 2009
United States615 Posts
August 18 2011 18:42 GMT
#1464
Quick Java question: Is it considered bad manner to have 600+ threads in a Java application?
Craton
Profile Blog Joined December 2009
United States17266 Posts
Last Edited: 2011-08-18 19:29:40
August 18 2011 19:29 GMT
#1465
Finished interview, went okay.

On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.
twitch.tv/cratonz
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-18 19:58:56
August 18 2011 19:49 GMT
#1466
On August 19 2011 04:29 Craton wrote:
Finished interview, went okay.

Show nested quote +
On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.


Well, yeah, I'm mostly talking about people who have some amount (maybe a year or two) of C# experience. But man, there's sure a lot of low-hanging fruit:

- Cruft from prior versions. Three separate framework ways to parse XML nowadays. Non-generic collections that are basically obsolete implementations of the generic ones. A ton of different threading APIs (i.e. Thread, ThreadPool, BackgroundWorker, Task, BeginInvoke, and to some degree the new C# 5 async) that all solve overlapping problems.

- Events and properties aren't first-class, which is frustrating. I can't even get a delegate pointing to the "get" method of a property without writing a big blob of reflection. I can't pass an event down to a method so that the method can fire it without making a wrapper function.

- Type inference is spotty. Why can it infer return types of initialized local variables, but not types of initialized class properties? Why can it infer return types of anonymous functions, but not named functions? These are just arbitrary decisions.

- While I'm at it, generic type constraints are crappy and limited. I can't even write public class X<T> where T : new(int, string) and make a constructor constraint. Come on!

- Reference types are nullable by default and can't be declared as permanently non-nullable, which may be the most crash-inducing design decision ever yet invented on this planet.

- No language support for purity or immutability constraints. I figured they would add an immutability check in 4.0 when they added generic covariance and contravariance, but nope.

- No language support for declaring or enforcing the thread safety of methods or declaring a method atomic with respect to callers. No language or library support for any kind of STM.

- No language support for pattern matching or destructuring function arguments.

- No language support to make tuples easier to work with (e.g. as they have in F#.)

A lot of the problems with .NET and C# won't seem like problems until you have some experience and encounter them a few times, or unless you have used other languages that do a better job of tackling them. But if someone can't think of *any* significant problems, then I get concerned, because I worry that the person in question just doesn't know what good code is and what's a hacky workaround.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
themikeman
Profile Joined July 2011
United States8 Posts
August 19 2011 02:20 GMT
#1467
What is inheritance by reference and how do you design a class implementing inheritance by reference?
There isn't a man in history that's led a life of leisure that has been worth remembering.
Sachem
Profile Joined May 2011
United States116 Posts
August 19 2011 02:43 GMT
#1468
You should add this as a guide to obfuscation, old, but I still get a great laugh out of it: http://thc.org/root/phun/unmaintain.html
rabidch
Profile Joined January 2010
United States20289 Posts
August 19 2011 03:05 GMT
#1469
On August 19 2011 11:43 Sachem wrote:
You should add this as a guide to obfuscation, old, but I still get a great laugh out of it: http://thc.org/root/phun/unmaintain.html

i spent 5 minutes laughing at the lisp code
LiquidDota StaffOnly a true king can play the King.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
August 19 2011 22:43 GMT
#1470
A project I'm contributing to at work involves parsing a WSDL using C#. I read about XMLReader being the best option in terms of performance, so at the moment have used that. What we want to be able to do is parse the WSDL once and get all the nodes, elements and attributes then. My main question is - how to best store all this information? I was thinking dynamic arrays, and have some experience doing it with ArrayLists (using Java), but I've heard recommendations for using List<T>. Perhaps there's a better way?

I'm back home now so I do not have access to the actual code being used, but this is the pseudocode for what we're trying to do:

User selects which WSDL they want to work with

After selecting the WSDL
- parse the WSDL for the operation names (CreateCart/ModifyCart/etc)
- display the operation names in a drop-down box

After selecting the operation names..
- other stuff involving the operation they want to do, and what course to follow based on the WSDL information for that operation

There will be a lot of information to parse through to display the options to the user for how to proceed from there. Oh, and the users will be internal quality assurance testers (it's a program to help them produce tests for the constantly changing software going out to customers)

Again, I just want to know what you think would be the best way to store these different types of information after parsing the WSDL (preferably just once), and perhaps if you think there's a better way to parse the WSDL than doing XMLReader in C#.
Undefeated TL Tecmo Super Bowl League Champion
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-19 23:40:28
August 19 2011 23:37 GMT
#1471
On August 20 2011 07:43 EscPlan9 wrote:
A project I'm contributing to at work involves parsing a WSDL using C#. I read about XMLReader being the best option in terms of performance, so at the moment have used that. What we want to be able to do is parse the WSDL once and get all the nodes, elements and attributes then. My main question is - how to best store all this information? I was thinking dynamic arrays, and have some experience doing it with ArrayLists (using Java), but I've heard recommendations for using List<T>. Perhaps there's a better way?

I'm back home now so I do not have access to the actual code being used, but this is the pseudocode for what we're trying to do:

User selects which WSDL they want to work with

After selecting the WSDL
- parse the WSDL for the operation names (CreateCart/ModifyCart/etc)
- display the operation names in a drop-down box

After selecting the operation names..
- other stuff involving the operation they want to do, and what course to follow based on the WSDL information for that operation

There will be a lot of information to parse through to display the options to the user for how to proceed from there. Oh, and the users will be internal quality assurance testers (it's a program to help them produce tests for the constantly changing software going out to customers)

Again, I just want to know what you think would be the best way to store these different types of information after parsing the WSDL (preferably just once), and perhaps if you think there's a better way to parse the WSDL than doing XMLReader in C#.


XmlReader is very low-level. The typical way to parse XML in C# nowadays is using the XDocument API, which is built on top of XmlReader. I don't really see why the parser's performance would be relevant when parsing a handful of WSDL files; one wouldn't expect them to be very large.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
August 20 2011 01:53 GMT
#1472
Wow XDocument looks really handy and easy to use compared to XMLReader thanks for the suggestion!

Good point about the performance part - the largest WSDL is maybe 1 MB? Either way its not like hundreds of MBs. I don't think there would be enough of a difference for that to be such a huge factor in the decision.

This application is going to be dynamically creating labels, text fields and checkboxes based on information it receives from the WSDL (i.e. checkboxes on boolean), so I will need to organize a lot of information parsed from the WSDL for later use. Is there any significant difference between storing a lot of this information in ArrayList rather than List<t> ? I suspect this question might be too context specific for what I'm working with. If that's the case, I'm more familiar with working on ArrayLists, so I would just choose that.
Undefeated TL Tecmo Super Bowl League Champion
catamorphist
Profile Joined May 2010
United States297 Posts
Last Edited: 2011-08-20 02:07:56
August 20 2011 02:06 GMT
#1473
On August 20 2011 10:53 EscPlan9 wrote:
Wow XDocument looks really handy and easy to use compared to XMLReader thanks for the suggestion!

Good point about the performance part - the largest WSDL is maybe 1 MB? Either way its not like hundreds of MBs. I don't think there would be enough of a difference for that to be such a huge factor in the decision.

This application is going to be dynamically creating labels, text fields and checkboxes based on information it receives from the WSDL (i.e. checkboxes on boolean), so I will need to organize a lot of information parsed from the WSDL for later use. Is there any significant difference between storing a lot of this information in ArrayList rather than List<t> ? I suspect this question might be too context specific for what I'm working with. If that's the case, I'm more familiar with working on ArrayLists, so I would just choose that.


The only significant difference is that ArrayList will be more of a pain in the ass to deal with, since it's not generic. (There's a performance problem with big ArrayLists containing value types due to boxing, but it wouldn't be significant unless you had much more data.)

I personally have literally never used an ArrayList since C# 3.0 came out, and I can't think of any reason to ever recommend it. List<T> is basically strictly better. But if you don't mind casting your data every time you access the list, then I guess you can use whatever you please.
http://us.battle.net/sc2/en/profile/281144/1/catamorphist/
Craton
Profile Blog Joined December 2009
United States17266 Posts
August 20 2011 02:07 GMT
#1474
Lists are basically the superior form of ArrayLists.
twitch.tv/cratonz
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 15:09 GMT
#1475
I just want to start this off with: I have no idea how to script or code. I've never done either and I've never taken classes or anything.

Having said that my question should be pretty simple.

Let me explain myself a bit, I'm working as a networking engineer for a company, we have this software called Paessler Network Monitor. We are using it to track devices on our network that are installed remotely, and to track their data usage.

This network monitoring software also comes with a separate application called the billing tool, this tool comes with a few scripts and templates scripted in lua.

Basically it has these scripts stored in a directory. You open up the billing tool, create a new customer name, and associate a template with it. Now the templates I'm guessing are customizable. And I've been playing around with it for a while, because I'm honestly not retarded, but I can't for the life of me get it to generate any kind of billing report.

If someone could explain to me specifically what I am able to modify in the script and possible values and things like that I would be eternally grateful

Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

if SensorChannel(1) ~= nil then
freeVolumeGB = 15
costPerGB = 50
currency = "$"
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024))
calculateGB = sumGB - freeVolumeGB
if calculateGB <= 0 then
calculateGB = 0
end

invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


I know it's probably very simple for one of you guys in here, but it's just not clicking for me.

Any help or advice is appreciated.
Craton
Profile Blog Joined December 2009
United States17266 Posts
Last Edited: 2011-08-22 19:21:31
August 22 2011 19:09 GMT
#1476
On August 23 2011 00:09 TadH wrote:
Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool") //load code
invoice = GetInvoice() //get invoice then stores it as 'invoice'

if SensorChannel(1) ~= nil then //dunno what sensorchannel is
freeVolumeGB = 15
costPerGB = 50
currency = "$" //probably sets as USD
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024)) //calculates total gigabytes
calculateGB = sumGB - freeVolumeGB //calculates unused gigabytes
if calculateGB <= 0 then //GB can't be negative
calculateGB = 0
end

//these lines seem to add text to the invoice being made
invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

//seems to calculate the USD cost per Kilobit
if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

//adds text to invoice
invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


Added comments. You should have documentation about what else you're able to use.
twitch.tv/cratonz
Sentient
Profile Joined April 2010
United States437 Posts
Last Edited: 2011-08-22 20:06:33
August 22 2011 20:04 GMT
#1477
On August 19 2011 04:49 catamorphist wrote:
Show nested quote +
On August 19 2011 04:29 Craton wrote:
Finished interview, went okay.

On August 19 2011 03:16 catamorphist wrote:
When I interview C# programmers I ask them what things in C# and .NET bother them the most and what they would fix if they were designing the language. Don't be that guy who says "I can't think of anything."

What would you change? This strikes me as a question more relevant for programmers with a couple years experience than someone fresh out of college.


Well, yeah, I'm mostly talking about people who have some amount (maybe a year or two) of C# experience. But man, there's sure a lot of low-hanging fruit:


I've done C# exclusively for about six years, and I want to criticize some of your low-hanging fruit decisions, but first let me offer my own.

I can't stand how the DependencyProperty system in WPF and Silverlight so flagrantly violates type safety. Consider the following cases:


int a = 5;
double b = a; // totally fine
SetValue(SomeDependencyPropertyOfTypeInt, a); // success
SetValue(SomeDependencyPropertyOfTypeInt, b); // exception! b is a double, int was expected
SetValue(SomeDependencyPropertyOfTypeDouble, 5); // exception! 5 is an int. Need to pass 5.0 instead.


Worse yet, GetValue(SomeDependencyPropertyOfTypeInt) returns type object! You have to cast it to the appropriate type. More than once my head has exploded trying to refactor a DependencyProperty from one type to another, because it requires hunting down every single cast operation. I don't understand why you can't do SetValue<type>(SomeDependencyProperty, a) and GetValue<type>(SomeDependencyProperty). Then the compiler could warn you and even disambiguate the 5/5.0 issue.

About some of your examples:

- Reference types are nullable by default and can't be declared as permanently non-nullable, which may be the most crash-inducing design decision ever yet invented on this planet.

This is the one that prompted me to reply. It is not a crash-inducing design decision, but a crash-prevention design decision.

If you ever have a null reference exception, then it means your program is in a state that the programmer didn't anticipate. You can cover it up with a valid reference, but ultimately the state is still undefined. Worse, your program will probably still crash anyway, but it will happen later and in a place where it is difficult to find the original cause. Null reference exceptions pinpoint the exact place the programmer went wrong, so I make it a point to never catch them. I throw them as exceptions all the time because they are a symptom, not the cause.

If you really need a value type then use struct, not class. Or, if the object is well encapsulated, you can do something like this:

class MyClass
{
private ObjectOfSomeType myObject = new ObjectOfSomeType(); // myObject will never be null unless you set it explicitly

public MyClass()
{
// Constructor doesn't need to initialize MyObject
}
}



[The rest is spoilered so as not to clutter the thread. The ones I don't mention I either agree with (especially the type constraints with new) or am neutral on.]
+ Show Spoiler +

- Events and properties aren't first-class, which is frustrating. I can't even get a delegate pointing to the "get" method of a property without writing a big blob of reflection. I can't pass an event down to a method so that the method can fire it without making a wrapper function.

I'm not sure why you would want to do this. For events, it seems like a bad idea to release control of your events. If you really need to, you can pass an Action object via lambda with () => MyEvent(...), which saves a lot of typing. I agree it would be nice to have access to the property getters and setters, but this is only useful in the context of reflection anyway, and it doesn't take all that much to get the MethodInfo for the property's getter and setter.



- Cruft from prior versions. Three separate framework ways to parse XML nowadays. Non-generic collections that are basically obsolete implementations of the generic ones. A ton of different threading APIs (i.e. Thread, ThreadPool, BackgroundWorker, Task, BeginInvoke, and to some degree the new C# 5 async) that all solve overlapping problems.

The threading pool examples all serve very different problems that overlap only tangentially. The XML parsers make more sense in the context of mobile platforms and Silverlight where they aren't all available simultaneously.


- Type inference is spotty. Why can it infer return types of initialized local variables, but not types of initialized class properties? Why can it infer return types of anonymous functions, but not named functions? These are just arbitrary decisions.

I'm confused. It can do all of those things.

public int Blah()
{
return 5;
}

public void Blarg()
{
var a = Blah(); // works fine, a is type int
}



- No language support for purity or immutability constraints. I figured they would add an immutability check in 4.0 when they added generic covariance and contravariance, but nope.

There is the readonly keyword, which is perfectly suitable if your data is truly immutable.
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 20:04 GMT
#1478
On August 23 2011 04:09 Craton wrote:
Show nested quote +
On August 23 2011 00:09 TadH wrote:
Script 1
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool") //load code
invoice = GetInvoice() //get invoice then stores it as 'invoice'

if SensorChannel(1) ~= nil then //dunno what sensorchannel is
freeVolumeGB = 15
costPerGB = 50
currency = "$" //probably sets as USD
sumGB = math.ceil((SensorChannel(1):GetRawSum()/1024/1024/1024)) //calculates total gigabytes
calculateGB = sumGB - freeVolumeGB //calculates unused gigabytes
if calculateGB <= 0 then //GB can't be negative
calculateGB = 0
end

//these lines seem to add text to the invoice being made
invoice:AddItem(SensorChannel(1).Name , sumGB .. "GB");
invoice:AddItem("Free volume" , freeVolumeGB);
invoice:AddItem("Each GB over " .. freeVolumeGB, costPerGB .. currency);
invoice:AddItem(calculateGB .. "GB to pay", calculateGB*costPerGB .. currency);
invoice:SetTotal("Total", calculateGB*costPerGB .. currency);
else
invoice:AddItem("Error: " , "Channel 1 not available in this type of sensor");
end


Script 2
+ Show Spoiler +

luanet.load_assembly("Paessler.Billingtool")
invoice = GetInvoice()

//seems to calculate the USD cost per Kilobit
if GetPercentile() ~= nil then
percentile = math.ceil(GetPercentile()/1000*8)
costPerKbit = 1.50
currency = "$"
totalCost = percentile * costPerKbit

//adds text to invoice
invoice:AddItem("Percentile", percentile .. "kbit/s");
invoice:AddItem("Charge per kbit/s", costPerKbit .. currency);
invoice:SetTotal("Total", totalCost .. currency);
else
invoice:AddItem("No percentile available", "");
end


Added comments. You should have documentation about what else you're able to use.



I actually just found the readme file with the templates.

+ Show Spoiler +


PRTG Billing Tool Scripting Documentation
2011

To customize the billing calculations and output it is necessary to edit or write
scripts in the Lua scripting language (see Lua documentation:
http://www.lua.org/docs.html).

There are already some example scripts in the “\scripts” folder as well as example
templates in the “\templates” folder. The Billing Tool executes the script to
assign data to the template placeholders. The templates will be rendered as HTML
and PDF files afterwards.


Load Lua assembly
-----------------
To access the Billing Tool functions and data in Lua scripts, the Lua assembly
needs to be loaded:

luanet.load_assembly("Paessler.Billingtool")


Available Lua functions
-----------------------

After this step the following functions are available:

SensorChannel([channel_ID]):GetRawSum()
- Return the total bytes of the selected sensor channel for the specified
period.
- The [channel_ID] can to be found in the PRTG web interface under the
channels tab in the sensor details view.

SensorChannel([channel_ID]).Name
- Return the name of the selected sensor channel.

SensorChannel([channel_ID]).Id
- Return the ID of the selected sensor channel.

GetPercentile()
- Return the calculated percentile value for the spcified period if
available.

invoice = GetInvoice()
- Save the invoice object in the invoice variable to access invoice
functions later.

invoice:AddItem([name], [value])
- Add an item to the <#itemtable> placeholder in the template.
- With style sheets it is possible to customize the layout. Each item is
seperated into 2 columns (<td> tags).
- The columns are accessible via the CSS class "itemkey" for [name] and
"itemvalue" for [value].

invoice:SetTotal([totaltext], [totalvalue])
- Add the total value to the <#itemtable> placeholder in the template.
- The <tr> tag in the generated HTML file is accessible via the CSS ID
"total".
- Via the CSS class "totalvalue" it is possible to style the <span> tag
where the [value] will be visible.


Itemtable HTML
--------------

The following HTML is generated for the <#itemtable> placeholder:

<tr>
<td class="itemkey">
[name]
</td>
<td class="itemvalue">
[value]
</td>
</tr>
<tr id="total">
<td class="itemkey" >
[totaltext]
</td>
<td class="itemvalue">
<span class="totalvalue">[totalvalue]</span>
</td>
</tr>


So for example it says: SensorChannel([channel_ID]):GetRawSum()

Do I need to add the [ and ] or do I just add the sensor channel between the () so does it look like ([sensor channel]) or (sensor channel)

(sensor channel is the device name we're using to pull the data from, so it could be a router or a 3G card etc)

Also this: invoice:AddItem([name], [value])
- Add an item to the <#itemtable> placeholder in the template.

There is no "<#itemtable> int he template. Would I just type in <#itemtable> at the bottom of the script?

I'm just really confused, I've never had to do anything like this before. And I know it's only a basic script lol

Thanks for the help.
UltimateHurl
Profile Blog Joined September 2010
Ireland591 Posts
August 22 2011 20:19 GMT
#1479
How did I just see this thread? Did my undergrad in software engineering, about to learn lua in my spare time just because.
TadH
Profile Blog Joined February 2010
Canada1846 Posts
August 22 2011 20:22 GMT
#1480
On August 23 2011 05:19 UltimateHurl wrote:
How did I just see this thread? Did my undergrad in software engineering, about to learn lua in my spare time just because.



You wanna give me a hand then? :D
Prev 1 72 73 74 75 76 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
23:00
WardiTV Mondays #59
CranKy Ducklings103
LiquipediaDiscussion
BSL 21
20:00
ProLeague - RO32 Group D
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
ZZZero.O247
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nathanias 181
Ketroc 50
StarCraft: Brood War
Artosis 580
ZZZero.O 247
NaDa 30
Light 8
yabsab 6
Dota 2
monkeys_forever230
NeuroSwarm55
League of Legends
JimRising 476
Counter-Strike
fl0m1623
Super Smash Bros
hungrybox564
AZ_Axe126
Heroes of the Storm
Khaldor170
Other Games
summit1g4465
Grubby4110
ToD143
Maynarde114
febbydoto3
Organizations
Other Games
EGCTV863
gamesdonequick703
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Hupsaiya 77
• RyuSc2 40
• HeavenSC 25
• musti20045 24
• Adnapsc2 15
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• HerbMon 4
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21387
• Ler49
League of Legends
• Doublelift3145
Other Games
• imaqtpie1722
Upcoming Events
Wardi Open
11h 44m
Monday Night Weeklies
16h 44m
Replay Cast
22h 44m
WardiTV Korean Royale
1d 11h
BSL: GosuLeague
1d 20h
The PondCast
2 days
Replay Cast
2 days
RSL Revival
3 days
BSL: GosuLeague
3 days
RSL Revival
4 days
[ Show More ]
WardiTV Korean Royale
4 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
IPSL
5 days
Julia vs Artosis
JDConan vs DragOn
RSL Revival
6 days
Wardi Open
6 days
IPSL
6 days
StRyKeR vs OldBoy
Sziky vs Tarson
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.