relationship between anti-spam solutions and whois databases

Question: Are there anti-spam SMTP proxies(like ASSP, qpsmtpd) or e-mail spam filtering solutions in general(like SpamAssassin) out there which create for example block filters based on objects in RIR databases? If yes, then which objects(inetnum? route?) do they use and how?
Comment: Anti-spam based on RIR databases ?  Don't make me laugh !  Spammers are much more sophisticated than that !
Answer: Not sure if helps, but I have used RBL lists for a long in my mail servers and they do a pretty decent job (they take care about 90% - 95% of the spam).
It works much better than SpamAssassin (and without hassle). Still, I use SpamAssassin for the rest of the spam.
Now, about your specific question: If I understand correctly, what you want is to block complete segments automatically, right?
I think Whois inetnum and route are the same, just different representations. Don't take my word as the holly truth, as I have no so much experience with those values, but that is what I believe.
I think this question and this one may give you some clue on how to achieve what you want.
While I see an advantage on blocking entire segments, I think you won't get so much benefits from that. The reason is because spam comes from many different segments and blocking one segment will only block very few positive IPs.
One problem I see, is that you may over-block IPs:
I will give an example in real life: Here in Japan the company NTT owns a mail service with the "ocn.ne.jp" domain. It has several smtp servers which are originated in the same segment (randomly assigned to their customers). Sometimes one of those servers gets black listed (RBL) and my servers block emails coming from there. Sometimes they are blocked for hours due to some misuse in some account. But that doesn't mean I should block all the segment. If I do that, it would be a big problem as its commonly used here in Japan.
OCN is not the only case, I have seen it too with yahoo servers and others.
Answer: Personally, I think you're better off keying on a few countries and languages that you are certain you do not want and then penalize them in SpamAssassin using RelayCountry, TextCat, etc.

I've experimented with RIR data in SpamAssassin rules in the past.  My conclusion was that there was nothing terribly useful even as features within a machine learning environment.
The criteria are a little stale (I'm not updating the CIDRs that RIRs trade and this is just IPv4), but this should be roughly representative:
  S/O   Flow%  RIR
0.282  50.052  ARIN
0.785  26.186  RIPE
0.845  16.274  APNIC
0.129   9.983  Legacy Class A
0.915   1.348  LACNIC
0.763   0.744  AFRINIC

("S/O" is relative precision using a balanced sample of spam and legit mail. It very roughly correlates with spam probabilities.  "Flow%" is the percent of all traffic flow that I saw in this sample period (and it includes some overlap).  The lower the Flow%, the less you should trust the S/O – i.e. don't block Latin America.)
This obviously reflects my sampling, which is a very very small subset of the data I have available.  As you can see, I have far more data fom North America and Europe than I do in Latin America or Africa.  This does not necessarily reflect real life (or even my own data set; I randomly downsampled!).
If you know your communications channels very intimately, you can consider something like this, but it's way too broad to safely deploy.
Since my data is so stale, I'm not going to dump all of it here, but as an example, here's my definition of the Legacy Class A space (the ^ should remove the overlap issue experienced above):
header  __RCVD_VIA_LEGACY  X-Spam-Relays-External =~ /^\[ ip=(?:[689]|2(?:[025689]|1[45]?)|1[12356789]|3[023458]?|5[1234567]|4[0478]?)\b/

If I recall correctly, I just went to the website of each of the five Regional Internet Registries and found their announced blocks.  I generated each RIR's regex using Regexp::Assemble (which fails to create character class ranges).  This uses a special SpamAssassin pseudo-header for a cleaner definition.

There are other very useful aspects of whois for spam detection, but there's a major hurdle to overcome: it's way too much data to do anything with on a local deployment.  You need major cloud services populating databases in close to real-time in order to catch things like hailstorm (side note:  my team did this.).
Another service relying on whois data is the Day Old Bread List, which merely lists any domain that is 0-5 days old on the assumption that it's worth penalizing email sending from (or linking to) such domains.


Trying to install OS to new computer; Won't detect HDD

Question:
Possible Duplicate:
Trying to install OS to new computer; Won't detect HDD

Mobo: Biostar th67+
CPU: i3 2100
GPU: AMD 6850 (using integrated right now)
PSU: Antec 400 Watts
HDD: 80gb Deskstar IDE + external seagate
I am trying to install Windows 7. My problem is that it won't recognize my HDD during installation.
I have an old IDE HDD which I'm using with an adapter for SATA. It's not working.
Currently I'm trying to update the BIOS without windows since it might help. I cannot get to the BIO-FLASHER by pressing F12. I've restarted and tried the other F keys as well. I can only get to the boot item menu with F9. I tested F keys on another computer to verify that the keyboard is working. I have placed the current H67BRC15.BST BIOS file at the root of a blank FAT32 USB stick and it's in a working USB port in the computer. This gives me two questions:

How do I update the BIOS without windows?
Why won't my IDE HDD work?

Other possibly useful information:
I have successfully ran ubuntu 11.10 off of a USB stick, so everything seems to work.
The IDE to SATA adapter appears to work since my HDD shows up in the BIOS (I have the HDD set to master as well).
I have tried to get both Ubuntu and the Windows installer to read the HDD to no avail. I've tried using 15 pin and 16 pin master modes for the HDD as well.
In the BIOS I've tried setting the SATA settings to IDE mode, and to AHCI mode and tested those, with and without the extra options like SMART and Power Link Management. I've tried most of the SATA slots. With IDE mode the windows installer won't display the HDD (it says it needs drivers!). With AHCI mode it finds the HDD but says that I can't install to it, and I need to enable the controller in the BIOS, but both of them are enabled.
I cannot understand why the HDD can show up in the BIOS and not to the OS. Any help is appreciated! I didn't know where else to ask, and Ubuntu is the only OS that I can boot right now.
Comment: You should really look into upgrading your Hard Drive as it will be the bottle neck on your system. Even though the Sata port is capable of performing faster, the HDD interface is still IDE and limited to 100/133.
Answer: I say install ubuntu on the drive, or run the live version and check if the drive is there, make sure the IDE are shorted to either cable select/master[I prefer master]
check this link out http://www.pchell.com/hardware/masterslaveorcableselect.shtml for help with selecting between CS=cable select M=Master
Comment: Yep, it's set to master. I'm going to try installing Ubuntu to the drive from another PC since it's system independent (and the usb install isn't detecting the drive). Good advice, I'll post back if it works.


Legality around demolishing a building without shutting off gas or electricity

Question: Is there any legality in Texas, or anywhere, around requiring a company or entity that is demolishing a building to have 1) The property's electricity provider properly shut off power to the property and/or 2) Having the property's gas provider properly shut off gas to the property. This seems like it would be at least be subject to a fine given the danger of preforming a demolition without these steps having take place.
Comment: Are you getting or applying for a demoliton permit from your local building/zoning office before the demo work? That process usually requires a checklist of things like turning off power, gas, water, sewer. etc.
Answer: Laws regarding building demolitions and disconnection of utilities are very local in nature - the city or county - and different everywhere; and, different building codes apply to commercial buildings and private, as well as public and private buildings.
But generally, building and fire codes will require the disconnection of electric and gas service to any building that is to be demolished, and process to do the disconnects and ensure that they are done is handled in the permitting process for the actual demolition.
To (legally) demolish a building, a contractor or a private individual needs to apply for a permit from the local building permit and/or zoning office, because the demolition work has various liabilities in terms of safety, toxic waste remediation, traffic, pollution and impacts to other property owners.
The application (which states the building owner, the contractor and their license (which includes the insurance company) if uses, location, etc.) and the cost of the permit includes the process to ensure that utilities are disconnected by the utilities. For commercial and public buildings, the permit/zoning office and the city will take the lead in the permit process and oversee the demolition; for private buildings, the owner (and contractor, if involved) are responsible for scheduling and ensuring the disconnects take place.
The permits require the signature of the individual (or the contractor, if involved) that states that utilities have been or will be correctly disconnected before work begins. That permit is a contract and it will clearly state what can be significant fines for not following the process, as well as the potential liabilities for fire, adjacent property damage and injuries.
The details on these applications are sometimes forwarded to the utilities themselves and the local fire department, especially in the case of public and commercial buildings, for coordination and verification.
Of course, in rural areas outside of cities, permits and building codes can be minimal. But they can still exist; any city or county building/zoning office will have complete information and applications for the demolition process.


Finding domains of functions

Question: I'm doing college algebra homework and I always think that if something seems too easy, you're probably wrong, so I wanted to check.
The domain of a function is all real numbers unless it creates a zero in the denomonator, yes?
So for the following, the domain would be negative infinity to positive infinity?
$$\begin{align} f(x)&=3x-18\\ \\
f(x)&=4x^2-3x+2 \\ \\
f(x)&=x^3-3x^2+5x+7 \\ \\
f(x)&=|3x|+17 \\ \\
f(x)&=x \end{align}$$
There are some more that are square roots and at the bottom of fractions, so I know the answer to those will have numbers excluded, but it seems like this is a lot of examples where the answer would be "all real numbers" so I wanted to make sure I wasn't missing something.
Thanks in advance people!
Comment: If you can say that $f(whatever)$ has a definite value, then $whatever$ is in the domain of $f$. Is there any $whatever$ for which these functions do not have a value?
Answer: Informally (and most probably that is enough in your situation) you are correct if you say that $\mathbb R$ is the domain of these functions. More careful would be the statement that $\mathbb R$ can serve as domain of these functions. This because you can also have a function prescribed by e.g. $x\mapsto 3x-18$ that has a subset like $(0,1)$ of $\mathbb R$ as domain. In that sense I would call $\mathbb R$ the maximal domain of these functions.
If this is new to you then don't bother about it. In that case always make domains as large as possible (=maximal).
Your remark ending with "...unless it creates a zero in the denominator" is not correct. That is sufficient condition for not belonging to the domain, but not a necessary condition. You can have a function prescribed by $x\mapsto\sqrt{x}$. There is no denominator, but nevertheless all values $<0$ cannot belong to the domain.
Comment: I thought that if the denominator was zero, it was undefined and therefore could not be a function so I would have to exclude it from the domain.
Comment: I should have gone to college after high school when all this was fresh in my head ;) thanks for your help

Finding domains of functions


developing sql application using local database

Question: I am starting an application (c#, .net) that will interact with a Microsoft SQL database. I need the ability for multiple clients to access the data concurrently so I an going to use a service based database (.mdf). Is it possible to develop the application using a local database (.sdf) and then easily switch it over to a service based database when it comes time for deployment? Is that how this type of development it typically done?
Answer: You can control the data source by providing connection string to your database in .config file.
You can even create Debug and Release versions of your .config file with different connection strings. Debug can point to your local machine and Release to production.
Answer: Development shops vary, but it is pretty common to develop apps using SQL Express locally and then use a full installation of SQL Server for the production environment.
The only thing I would advise is make sure that the DB you chose for your dev environment supports the same features as what you expect in production. For example don't use SQL Express on your dev box when you expect to use Oracle in production.
Answer: If the database schema in both backends is exactly the same than the only thing you will need to do is change the connection string when you are ready to move to the service based database.
Be aware that the slightest change in the schema can (and probably will) cause problems.
Answer: You want to use SQL Compact Edition (as you said database file extension is .sdf), right? You can use MSSQL Express Edition instead, as it acts more like full MSSQL Server, and is still free and not so hard to install on developer's machine (I personally prefer this option). There are differences between the two (as explained here: http://blog.sqlauthority.com/2009/04/22/sql-server-difference-between-sql-server-compact-edition-ce-and-sql-server-express-edition/). If you don't want features like triggers/procedures/views in your database, you can still use CE, though.
Answer: If you have multiple clients then you should use SQL Server Express (.mdf file) - SQL Server Compact (.sdf file) is useful when you are building an application that is going to be deployed on client machines and will run standalone, e.g. windows forms application with a local database. SQL Server Compact is just an alternative for MS Access .mdb files or SQLite, the so called "embedded databases", while SQL Server Express is a real database server (albeit with some limitations to render it unsuitable for large commercial applications) and should be used in the cases where multiple clients use central database, e.g. web applications and smart client apps (the latter could also make use of a local embedded database though).


Can I change a asp control from image handler?

Question: I have an asp page with a button on it that uses an image handler to show a jpg.  Can I disable a button on the page from the image handler base on what image is loaded.  for example if c:/x.jpg is loaded, disable the button.
Thanks
Charles
Answer: The image handler will not be able to do anything - an image doesn't contain any scripts that can be executed.
You can check for the image loaded event in javascript and act on the value. See this SO question and answers.
Answer: This is inherently impossible.
The image is loaded with a separate HTTP request that has nothing to do with the page.


What is the reason for blocking Russian duma Youtube channel?

Question: According to BBC News the Russian duma's YouTube channel was blocked. What is the reason for that given that this would potentially mean that YouTube will be banned in Russia and the alternative access to independent information channels would be cut off?
Comment: I have no doubt that Russian parliament will be pro war etc, however is th banning worth the risk of depriving Russian society of information alternative to official government propaganda
Comment: There are plenty of other sources of "information alternatives", e.g. Telegram hosts RFE/RL, BBC, The Guardian, and everything from pro-russian to anti-russian propaganda, as well as allowing video uploads. Russia tried and failed to block Telegram, and now the state is actively using it itself, so it's unlikely they'll try to censor it again. As for YouTube in Russia, I'm not sure if it's a news source, instead being more of an entertainment and education source.
Answer: While I haven't seen anything detailed about his Duma TV ban by YT, it's worth recalling that about a month ago (when they took down RT globally) they had announced

YouTube is immediately blocking access around the world to channels associated with Russian state-funded media, it said on Friday, citing a policy barring content that denies, minimises or trivialises well-documented violent events. [...]
YouTube spokesman Farshad Shadloo said the blocking of the Russian outlets was in line with that policy.

Frankly, taken at face value, that would have probably meant they should have banned other Russian channels besides RT, back then, probably including Duma's.
As my own limited sampling has shown, the Russian MoD's channel (with 1M subscribers) is still on YT, although I did notice that some Ukraine-related Russian MoD videos that were previously easy to find are now "unlisted" (e.g. one showing Russian paratroopers disembark at Hostomel). So it does appear that YT is tightening the screws on that previously announced policy, although the steps and schedule aren't exactly announced in advance.
Also, if the ban on Duma TV is (indeed) global, that probably excludes that it is as a result of a letter from the EU, which is how YT's parent company has taken some related steps, e.g. removing RT from web search results (just in the EU).
It may or it may not be a concidence that the ban on Duma TV comes around the time that the Ukrainians have retaken areas north of Kyiv, where they and the international press have highlighted some (alleged) war crimes. The Russian media has tried to portray these as staged, which I'm guessing might have been the position taken by some Russian MPs too. (Both the Kremlin and the Russian MoD have dismissed these allegations on similar grounds.)
Answer: According to news reports, the channel was "terminated for a violation of YouTube's Terms of Service." YouTube is a commercial entity with a long history of deciding what content violates their TOS, without judicial or government oversight. A number of countries tried to make YouTube comply with local laws, with mixed success. The lever to do that is usually YouTube's advertising revenue.
Answer: There are two primary options:

YouTube was explicitly told to do that, by a channel that they obey. Who could that be is left as an exercise for a reader.
YouTube decided to show an initiative ("проявил инициативу" in Russian), deciding that their Russian business is less important than sending the correct political signals right now. They were not running ads in Russia anyway, starting late February, by that basically giving every Russian an YouTube Premium.

YouTube has also banned a channel by Yuri Polodyaka recently, a vlogger who reiterated the current course of Russian military action in a calm voice, whose only apparent crime before YouTube was his 3M of subscribers. I'm repeating this as my earlier comment on that matter has mysteriously disappeared.
YouTube got a lot of leniency from the Russian government despite banning official Russian TV channels, since you go to YouTube to watch how to assemble your baby stroller, not to mention courses posted by Russian education institutions - it was too big to get rid of. I can see them burn it through, however, and getting banned in the future.
Comment: Not sure if [this](https://www.youtube.com/channel/UCarzryI9rENG8zlgbWP40kA/videos) is the Yuri channel you mentioned or if that's just a set of translations. But he seem to know a whole lot of foreign languages to subtitle in (those aren't YT-generated subtitles), even though he only ever speaks Russian. So, either he has a ton of fans doing the translations or it's a thinly veiled state-backed operation. As for the content, it's much more propagandistic than you portray it: he claims Ukrainians clearly staged everything etc.
Comment: This is some sort of translation/reupload channel.


Is topological string theory a topological field theory?

Question: Topological string theory comes from a topological twist (in the suitable spacetimes) of the sigma model defining it. Does the topological twist make the sigma model a topological field theory?
Comment: $\uparrow$ Yes.
Comment: There are two questions above.  The answer to the first is "Not necessarily", and the answer to the second is "Yes".
Answer: The answer is essentially yes. Topological string theory is a topological field theory of the Witten-type. This is evident when you study the Witten's construction as appeared in the classical references Topological Sigma Models and Mirror Manifolds and Topological Field theory or as is reviewed in the excellent Mini-Course in Topological Strings.
A subtelty should be recalled. Topological string theory satisfy Witten's axioms (BRST-exact stress tensor and graviton vertex operators, topological observables and metric-independent correlation functions) in the weakly coupled limit (large target space volume) but the holy grail of the theory is to find a definition for the topological string in the compact (target space) case. In that regime things become different because at finite volume Newton's constant becomes finite and the graviton vertex operator is no longer BRST-exact. Interesting developments (related to 6d SCFTS) have been discovered recently: Divulgative , SCFTs, Holography, and Topological Strings.


Adding a header view to a UIWebView similar to Safari and Articles

Question: I'd like to add a header view to an UIWebView similar to the address/search bar in MobileSafari and the excellent Articles.app by Sophia Teutschler. More precisely, I'd like to create a "pull to fix orientation" view above a UIWebView, just like in Articles. Articles does use a UIWebView, so it seems to be possible. Is there a way to accomplish this without having to embed the UIWebView into a UIScrollView and updating its size all the time, as described in this article? Apparently, I do need the scrolling events to have the "pull to fix orientation" behave accordingly.
Comment: Have you tried asking Sophie?
Comment: Have you tried adding a subview to the UIWebView?
Answer: After several attemps, I've decided to go with this solution:
Basically I've just added my header UIView as a webview.scrollview subview.
To avoid having the header overlap the browser view:

cycle through all [webview.scrollView subviews]
look for the biggest, wich should contains the browser (the others are for shadows and lines)
change its origin.y
here's the code:
CGRect browserCanvas = web.bounds;
for(int i=0; i< [[web.scrollView subviews] count]; i++)
{
  UIView* subview = [[web.scrollView subviews] objectAtIndex:i];
  CGRect f = subview.frame;
  NSLog(@"sub %d -> x:%.0f, y:%.0f, w:%.0f, h:%.0f", i, f.origin.x, f.origin.y, f.size.width, f.size.height);

  if(f.origin.x == browserCanvas.origin.x &&
     f.origin.y == browserCanvas.origin.y &&
     f.size.width == browserCanvas.size.width &&
     f.size.height == browserCanvas.size.height)
     {
         f.origin.y = header.frame.size.height;
         subview.frame = f;
     }
}

if(![header superview])
{
  [web.scrollView addSubview:header];
  [web.scrollView bringSubviewToFront:header];
}

Comment: What about using the contentInsets of the scrollView (and set your frame y to be negative) ?
Comment: @kenji that works well, as @Manesh details in another Answer. Except for the case when your webView has an element with the css position set to `fixed-top`. If you're expecting widely varied web content, you WILL encounter a page with a fixed-top navigation bar so @sosergio's suggestion works best.
Answer: I think the best solution is to add the header as a subview of your UIWebView's scrollView, adjust UIEdgeInsets, and in the scrollViewDidScroll delegate function adjust the scrollIndicatorInsets as needed.
Every other solution I found didn't account for the scroll indicators.
Since getting the behavior just right has a bit of complexity to it, I decided to write a class to handle all of it: MMWebViewWithSmartHeader. It's still a little rough around the edges but should help.
Comment: add
`CGRect headerFrame = self.headerView.frame;`
`headerFrame.origin.x = scrollView.contentOffset.x;`
`self.headerView.frame = headerFrame;`
at the end of your `- (void)scrollViewDidScroll:(UIScrollView *)scrollView` to solve the problem
Comment: +1, although I wasn't able to get things working with a `UIImageView` set as the headerView. I had to wrap the `UIImageView` inside a `UIView`.
Comment: Not bad, but ugly when the webview is zoomed, or panned on x axis. The header should lock on x axis and shouldn't be affected by scrollview zooming.
Comment: My bad: zooming behavior is good, but the x axis problem remains.
Comment: i had a problem where after adding a subview to the webview's scrollview half the webpage would be unclickable, i fixed it by inserting the subview at position 0 (so its at the back in the view hierarchy), not sure why it works but it did.
Comment: i also had a problem when viewing the webview in landscape mode, the header bar would not be clickable, i fixed it by means of [this answer](http://stackoverflow.com/a/17966145/1219956)
Comment: This answer also has some issues when the webView is showing content with a navbar that's css position is `fixed-top`. I had to use @sosergio's answer. If you control the web content, this solution is more elegant, but if you're going to be viewing random web pages, you're going to encounter a fixed-top nav-bar.
Answer: I like AutoLayout specially because I can make the height of the header dynamic.
This is my code using AutoLayout in a controller with a reference 'headerView' to the header view and a 'webView' to the webView.
// Function called in ViewDidLoad:
func addHeaderToWebView(){
    // We load the headerView from a Nib
    headerView = NSBundle.mainBundle().loadNibNamed(WebViewHeader.nibName, owner: self, options: nil).first as! WebViewHeader

    headerView.translatesAutoresizingMaskIntoConstraints = false

    webView.scrollView.addSubview(headerView)

    // the constraints
    let topConstraint = NSLayoutConstraint(item: headerView, attribute: .Bottom, relatedBy: .Equal, toItem: webView.scrollView, attribute: .Top, multiplier: 1, constant: 0)
    let leftConstraint = NSLayoutConstraint(item: headerView, attribute: .Leading, relatedBy: .Equal, toItem: webView, attribute: .Leading, multiplier: 1, constant: 0)
    let rightConstraint = NSLayoutConstraint(item: headerView, attribute: .Trailing, relatedBy: .Equal, toItem: webView, attribute: .Trailing, multiplier: 1, constant: 0)

    // we add the constraints
    webView.scrollView.addConstraints([topConstraint])
    webView.addConstraints([leftConstraint, rightConstraint])
}

// Function called in viewWillLayoutSubviews: to update the scrollview of the webView content inset
func updateWebViewScrollViewContentInset(){
    webView.scrollView.contentInset = UIEdgeInsetsMake(headerView.frame.height, 0, 0, 0)
}

Comment: Great solution! This works very well also to Xcode 14.0 Swift 5.7
Answer: Articles may not be using a UIWebView to display the main article text. To accomplish your task, UIScrollView will be required almost certainly. Resizing its subviews may not be necessary. Check out the UIScrollView code samples provided by Apple.
Comment: Articles almost certainly uses a `UIWebView`.
Answer: I could not say for sure, but Twitter seems to use UITableView to achieve this. Perhaps you can try to put your view in the header of the table view, and your content in a cell.
Here is an interesting example you might consider looking at - How to make a Pull-To-Reload TableView just like Tweetie 2
Comment: I think Adam was suggesting to make a tableView with a single custom cell that contains a UIWebView with your web content loaded in it.
Comment: I don't have any problems with implementing this stuff for any sort of `UITableView`, but I need to have it for an `UIWebView`.
Answer: Enormego published some sample code to make the pull-to-refresh thing happen:
https://github.com/enormego/EGOTableViewPullRefresh
It's really not so complicated. You can get a Safari/Articles-style header bar in your table view simply by creating your header bar and just adding it to your UITableView as a subview. I'm doing exactly that on the app I'm working on now:
GBSpendingMeter *meterView = [[[GBSpendingMeter alloc] initWithFrame:CGRectMake(0,0,320,44)] autorelease];

// The meterView will appear pinned to the top of the table, similar to a headerView
[self.tableView addSubview:meterView];

The tricky part is observing the scroll events on the table (FYI, UITableView is a subclass of UIScrollView so all the same notifications/callbacks should work), but the sample code I linked to has a good example of how that works.
Comment: I don't have any problems with implementing this stuff for any sort of `UITableView`, but I need to have it for an `UIWebView`.
Answer: Try this:
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, -100, WIN_WIDTH, 100)];
    redView.backgroundColor = [UIColor redColor];
    self.view.scrollView.contentInset = UIEdgeInsetsMake(100, 0, 0, 0);
    [self.view.scrollView addSubview:redView];
    NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.baidu.com"]];
    [self.view loadRequest:request];


Current and resistance

Question: Can anybody explain why my tongue gets a reading on a multimeter. Do I have a current? Why do i have resistance? Why do some things have resistance? I am very confused.
Answer: You might find Conduction of Electrical Current to and Through the Human Body: A Review interesting.
An excerpt from paragraph Skin resistance protects the body from electricity:

The body has resistance to current flow. More than 99% of the body's
  resistance to electric current flow is at the skin. Resistance is
  measured in ohms. A calloused, dry hand may have more than 100,000 Ω
  because of a thick outer layer of dead cells in the stratum corneum.
  The internal body resistance is about 300 Ω, being related to the wet,
  relatively salty tissues beneath the skin.

This is also the reason why your tongue has a not so high resistance.
Answer: Setting your multimeter to measuring resistance (ohm) it will read somewhere between some kilo ohms and up to more than a mega ohm depending on how your are holding the probes. Moist fingers will result in lower contact resistance.
Many materials including your body will have some resistance and will be able to conduct current.
Moving on to voltage; your muscles including your heart will have a tiny measurable voltage across them when they are moving your arm or pumping blood around your body. This is why a ECG can measure your heart rates, as the different muscles of your heart is activated at every heart beat.
Comment: Amusing anecdote : In a factory, the paint shop foreman had exceptionally dry skin on his hands from years of handling paint, thinners, turps etc. So much so that he could grab a pair of live mains wires with impunity. The maintenance electricians even used to ask him to test wires for them before they started work, and sometimes, out of devilment, he would lie!
Answer: You do have some currents inside you, mostly in your nerves and muscles.  But these are tiny, and not what the multimeter is measuring.
The multimeter measures resistance by using its battery to apply a low voltage between the two probes, and seeing if a current flows.  Lots of current means a low resistance.  Little or no current means a high resistance.
The resistance of a substance depends on how many free charge carriers there are in it, where "free" means able to move around in the substance and "charge carriers" are usually electrons, but could be positive or negative ions.
Plastic, glass and similar substances have very few free electrons, and so a very high resistance.  Metals have lots of free electrons, and so have a low resistance.
You are essentially a bag of slightly salty water, with bones inside to keep you the right shape.  The ionic salts produce positive and negative ions when dissolved in water.  This makes you an electrical conductor, albeit with a fairly high resistance.

Current and resistance


I can't log into my wordpress site

Question: I can't log into my website https://www.destressxpress.com.au/.
All the suggested answers appear to say to change folders etc within the website, but I can't get in to do that.
It appears that the Bloom plugin has depreciated.
If anyone could point me in the right direction I'd be thankful, or should I contact my hosting site
Thanks
Comment: Do you mean your usual login doesn't work any more, or you get an error (from the Bloom plugin?) when you try to log in?
Comment: If you don't have enough access to fix things then you will need to contact your host, yes, especially if it's managed WordPress hosting.
Comment: You probably just need to upgrade your Bloom plugin to make the deprecation warnings go away (and/or turn on WP_DEBUG in your wp-config file to hide the warnings, but I'd do the upgrade). I doubt these would be breaking your login though.
Comment: IF you can access your FTP/SFTP, add an underscore to the from of the Bloom plugin's directory.  This will deactivate it. So assuming the directory is `bloom`, change it to `_bloom`.
Answer: Using FTP/ SFTP go to wp-content/plugins/ and change the plugin folder name from "bloom" to "bloom-" it will disable the plugin, and you will be able to use WordPress native login.
Comment: Is this a known issue then, that the Bloom plugin breaks the login flow? The deprecation warnings on the home page look like they're just for the admin dashboard.
Comment: Yes, seems bloom plugin has a dashboard and warning should be displayed on Admin screen :).
FYI: As I checked bloom plugin has closed and last updated 8 years ago (https://wordpress.org/plugins/bloom/).

I can't log into my wordpress site


Is there a way to getting Remix to run offline?

Question: Could you please help me getting Remix IDE run in an offline environment?
I've researched that way from google but found no answers for it.
Answer: Yes, you can use it. Check out here.
Answer: Remix Desktop IDE allows to run Remix offline. Here is the releases page.
You can connect it to a wide range of VMs, testnets, RPCs, even some L2 !

I find it very useful because it has access to my computer's file system. No need to connect buggy Remix-D anymore, and you can use it even offline without a connection !
I still wonder why not so many people use the Desktop version !


Give the order of nucleophilic addition reaction in the following -

Question:
I am confused that whether we should take only inductive or hyperconjugation effect also into consideration while finding the order. As the answer in the book is only according to inductive effect . Will hyperconjugation effect come into play or not ?
If we take hyperconjugation effect then order must be 2>4>3>1.
Answer: The question is: how will these molecules react to the presence of a nucleophile (which would add to the more electrophilic center, i.e. the carbonyl carbon atom)?
The more the carbon atom of the carbonyl group has a partial positive charge, the more it is susceptible to be attacked by a nucleophile, so the problem is to compare the relative positive charge on the carbonyl carbon atom between those molecules.
Remember that an alkyl group has an electron-donating effect AND that a longer alkyl group has more electron-donating effect.
With all that, you should be able to answer your problem.
Comment: Yes I understand, but i am asking that won't hyperconjugation have any role . As more the hyperconjugation structures lesser will be the positive charge on carbon hence less reactive.
Comment: Structure 4 have more hyperconjugation than 2, while 2nd have more inductive effect. And hyperconjugation> inductive


Welcome pages in java ee 6

Question: As a follow up to this question, can one specify the welcome pages without web.xml? If possible, how? If not possible, are welcome pages simply not used? If not used, what are the advantages and disadvantages?
Answer: You can specify the welcome page without declare in web.xml. You use some html file and forward to your desire start page.see sample,
index.jsp
<code>  <html>
  <body>
  <jsp:forward page="/pages/welcome.jsf" />
  </body>
  </html>
</code>
The index.jsp page forward to welcome.jsf page without declare to welcome-file-list tag in your web.xml.
Advantages of using welcome-file-list
When the URL request is a directory name, Application Server serves the first file specified in welcome-file-list element.
Disadvantages of without using welcome-file-list
If that welcome-file-list is not found, the server then tries the next file in the web.xml.Its taken more time and 404 error may be found.
Comment: What are the advantages and disadvantages?
Answer: The welcome files mechanism allows you to specify a list of files that the web container will use for appending to a request for a URL (called a valid partial request) that is not mapped to a web component.(from link)
Why don't you use a web.xml file ?
If you really don't want to use a web.xml file, then you could use a Filter to forward a request to your welcome page.
Update:
The web container should have a welcome file list of its own. For example Tomcat has a web.xml file in its conf folder. It has
<code><welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</code>

Welcome pages in java ee 6


global positioning an image with itext

Question: Anybody knows if there are any special coordinates in iText to global positioning an image at the bottom right of the document?
I'm not sure it exists...
Comment: not sure but i have done to table like tblGiven.setAlignment(tblGiven.ALIGN_BOTTOM); check if there any such method exist in case of image.
Answer: First we need to know if you're talking about a Document that is created from scratch or about adding an Image to an existing document.
If you create a document from scratch, then the coordinate of the bottom-right depends on the page size you've used when creating the Document object. For instance: for an A4 page, the bottom right corner has x = 595 ; y = 0 (the measurements are done in 'user unit' which correspond with points by default). So if you want to position an image in the bottom right corner, you need to use img.setAbsolutePosition(595 - img.getScaledWidth(), 0); and then just use document.add(img); to add the image.
DISCLAIMER: if you use a page size that differs from the default, or if you define a CropBox, you'll need to adapt the coordinates accordingly.
If you want to add an image to an existing document, you need to inspect the page size, and you need to check if there's a CropBox. You need to calculate the offset of the image based on these values. Again you can use setAbsolutePosition(), but you need to add the image to a PdfContentByte object obtained using the getOverContent() or getUnderContent() method (assuming that you're using PdfStamper).

global positioning an image with itext


Salesforce1 Publisher Actions

Question: I'm having troubles adding a custom Publisher Action (PA) to the PA pop up window on my IPAD using Salesforce1 (accessed via the PLUS sign).  I've created a new PA via the new 'Action' feature for the Leads object.  I have successfully modified the page layout to clear the default PAs that were showing (except for Dropbox and Evernote - which is a different issue - no concern here).  I have added my new PA to the layout but it does not show on the IPAD via SF1.  Any suggestions?
Comment: Do you see it if you go to https://instance.salesforce.com/one/one.app in a desktop browser?
Comment: Do you see it in the standard web UI layout?
Comment: I'm not sure about the standard web UI.  I'm not 100% sure where to look.  Regarding the emulator, that doesnt seem to work on my PC (I could be doing something wrong).
Comment: Sometimes the emulator for me doesn't work properly, to use it I log into the org first, as usual, and then open a new tab in the same browser and use the same URL as metadaddy said after that it works. ( example : https//na15.salesforce.com/one/one.app )
Answer: Assuming that you are sure you're editing the correct publisher layout (since you said you managed to remove existing actions), this type of issue is most often due to record types.
Publisher actions are specific to individual record types, so if you create an action for a record type that your profile doesn't have access to, you will not see the action. The big sneaky one is the "Master" record type, because until recently it was the default, but if you have access to any other record type you can't also have access to Master.

Salesforce1 Publisher Actions


Copy files between sites in Sharepoint 2019

Question: On Sharepoint 2019 on premise i don't see my other sites when i use copy to or move to buttons to copy/move files between sites. Its similar when i want to copy/move files between document libraries from same site.

Thanks
Answer: For now, in SP2019 the copy to action does not support moving files between sites. You can only move it between folders in the same library. If you want to move files between sites, try to open it in explorer view.
Comment: But its similar for copy action, i dont see my other sites when i want to copy files between sites. You know why?
Comment: @Geeku What is similar for copy action?


How do I determine the size of an object in Python?

Question: How do I get the size occupied in memory by an object in Python?
Answer: Just use the sys.getsizeof function defined in the sys module.

sys.getsizeof(object[, default]):
Return the size of an object in bytes.
The object can be any type of object.
All built-in objects will return
correct results, but this does not
have to hold true for third-party
extensions as it is implementation
specific.
Only the memory consumption directly attributed to the object is
accounted for, not the memory consumption of objects it refers to.
The default argument allows to define
a value which will be returned if the
object type does not provide means to
retrieve the size and would cause a
TypeError.
getsizeof calls the object's
__sizeof__ method and adds an additional garbage collector overhead
if the object is managed by the
garbage collector.
See recursive sizeof recipe for an example of using getsizeof() recursively to find the size of containers and all their contents.

Usage example, in python 3.0:
>>> import sys
>>> x = 2
>>> sys.getsizeof(x)
24
>>> sys.getsizeof(sys.getsizeof)
32
>>> sys.getsizeof('this')
38
>>> sys.getsizeof('this also')
48

If you are in python < 2.6 and don't have sys.getsizeof you can use this extensive module instead. Never used it though.
Comment: Please add to the disclaimer that it will not hold true for nested objects or nested dicts or dicts in lists etc.
Comment: The disclaimer and exceptions to this working cover almost all use cases making the `getsizeof` function of little value out of the box.
Comment: why is the integer 2 stored in 24 bytes?
Comment: @SaherAhwal it is not just an integer, but a full object with methods, attributes, addresses...
Comment: @ChaimG that's because every object only uses 32 bytes!! The rest are references to other objects. If you want to account for the referenced objects you have to define `__sizeof__` method for your class. The built-in `dict` python class does define it, that's why you get the correct result when using object of type `dict`.
Comment: Umm... sys.sizeof(c) is 32 even when the class instance has 50 attributes! Something seems off!   Try this: `d = {k: v for k, v in zip('ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy', range(50))}` `class C(object):
    def __init__(self, **kwargs):
        _ = {setattr(self, k, v) for k, v in kwargs.items()}` `c = C(**d)`  `sys.getsizeof(d)` 1676  `sys.getsizeof(c)` 32
Comment: For complex obj, it is not right.
Answer:
How do I determine the size of an object in Python?

The answer, "Just use sys.getsizeof", is not a complete answer.
That answer does work for builtin objects directly, but it does not account for what those objects may contain, specifically, what types, such as custom objects, tuples, lists, dicts, and sets contain. They can contain instances each other, as well as numbers, strings and other objects.
A More Complete Answer
Using 64-bit Python 3.6 from the Anaconda distribution, with sys.getsizeof, I have determined the minimum size of the following objects, and note that sets and dicts preallocate space so empty ones don't grow again until after a set amount (which may vary by implementation of the language):
Python 3:
Empty
Bytes  type        scaling notes
28     int         +4 bytes about every 30 powers of 2
37     bytes       +1 byte per additional byte
49     str         +1-4 per additional character (depending on max width)
48     tuple       +8 per additional item
64     list        +8 for each additional
224    set         5th increases to 736; 21nd, 2272; 85th, 8416; 341, 32992
240    dict        6th increases to 368; 22nd, 1184; 43rd, 2280; 86th, 4704; 171st, 9320
136    func def    does not include default args and other attrs
1056   class def   no slots
56     class inst  has a __dict__ attr, same scaling as dict above
888    class def   with slots
16     __slots__   seems to store in mutable tuple-like structure
                   first slot grows to 48, and so on.

How do you interpret this? Well say you have a set with 10 items in it. If each item is 100 bytes each, how big is the whole data structure? The set is 736 itself because it has sized up one time to 736 bytes. Then you add the size of the items, so that's 1736 bytes in total
Some caveats for function and class definitions:
Note each class definition has a proxy __dict__ (48 bytes) structure for class attrs. Each slot has a descriptor (like a property) in the class definition.
Slotted instances start out with 48 bytes on their first element, and increase by 8 each additional. Only empty slotted objects have 16 bytes, and an instance with no data makes very little sense.
Also, each function definition has code objects, maybe docstrings, and other possible attributes, even a __dict__.
Also note that we use sys.getsizeof() because we care about the marginal space usage, which includes the garbage collection overhead for the object, from the docs:

getsizeof() calls the object's __sizeof__ method and adds an
additional garbage collector overhead if the object is managed by the
garbage collector.

Also note that resizing lists (e.g. repetitively appending to them) causes them to preallocate space, similarly to sets and dicts. From the listobj.c source code:
    /* This over-allocates proportional to the list size, making room
     * for additional growth.  The over-allocation is mild, but is
     * enough to give linear-time amortized behavior over a long
     * sequence of appends() in the presence of a poorly-performing
     * system realloc().
     * The growth pattern is:  0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
     * Note: new_allocated won't overflow because the largest possible value
     *       is PY_SSIZE_T_MAX * (9 / 8) + 6 which always fits in a size_t.
     */
    new_allocated = (size_t)newsize + (newsize >> 3) + (newsize < 9 ? 3 : 6);

Historical data
Python 2.7 analysis, confirmed with guppy.hpy and sys.getsizeof:
Bytes  type        empty + scaling notes
24     int         NA
28     long        NA
37     str         + 1 byte per additional character
52     unicode     + 4 bytes per additional character
56     tuple       + 8 bytes per additional item
72     list        + 32 for first, 8 for each additional
232    set         sixth item increases to 744; 22nd, 2280; 86th, 8424
280    dict        sixth item increases to 1048; 22nd, 3352; 86th, 12568 *
120    func def    does not include default args and other attrs
64     class inst  has a __dict__ attr, same scaling as dict above
16     __slots__   class with slots has no dict, seems to store in
                    mutable tuple-like structure.
904    class def   has a proxy __dict__ structure for class attrs
104    old class   makes sense, less stuff, has real dict though.

Note that dictionaries (but not sets) got a more
compact representation in Python 3.6
I think 8 bytes per additional item to reference makes a lot of sense on a 64 bit machine. Those 8 bytes point to the place in memory the contained item is at. The 4 bytes are fixed width for unicode in Python 2, if I recall correctly, but in Python 3, str becomes a unicode of width equal to the max width of the characters.
And for more on slots, see this answer.
A More Complete Function
We want a function that searches the elements in lists, tuples, sets, dicts, obj.__dict__'s, and obj.__slots__, as well as other things we may not have yet thought of.
We want to rely on gc.get_referents to do this search because it works at the C level (making it very fast). The downside is that get_referents can return redundant members, so we need to ensure we don't double count.
Classes, modules, and functions are singletons - they exist one time in memory. We're not so interested in their size, as there's not much we can do about them - they're a part of the program. So we'll avoid counting them if they happen to be referenced.
We're going to use a blacklist of types so we don't include the entire program in our size count.
import sys
from types import ModuleType, FunctionType
from gc import get_referents

# Custom objects know their class.
# Function objects seem to know way too much, including modules.
# Exclude modules as well.
BLACKLIST = type, ModuleType, FunctionType

def getsize(obj):
    """sum size of object & members."""
    if isinstance(obj, BLACKLIST):
        raise TypeError('getsize() does not take argument of type: '+ str(type(obj)))
    seen_ids = set()
    size = 0
    objects = [obj]
    while objects:
        need_referents = []
        for obj in objects:
            if not isinstance(obj, BLACKLIST) and id(obj) not in seen_ids:
                seen_ids.add(id(obj))
                size += sys.getsizeof(obj)
                need_referents.append(obj)
        objects = get_referents(*need_referents)
    return size

To contrast this with the following whitelisted function, most objects know how to traverse themselves for the purposes of garbage collection (which is approximately what we're looking for when we want to know how expensive in memory certain objects are. This functionality is used by gc.get_referents.) However, this measure is going to be much more expansive in scope than we intended if we are not careful.
For example, functions know quite a lot about the modules they are created in.
Another point of contrast is that strings that are keys in dictionaries are usually interned so they are not duplicated. Checking for id(key) will also allow us to avoid counting duplicates, which we do in the next section. The blacklist solution skips counting keys that are strings altogether.
Whitelisted Types, Recursive visitor
To cover most of these types myself, instead of relying on the gc module, I wrote this recursive function to try to estimate the size of most Python objects, including most builtins, types in the collections module, and custom types (slotted and otherwise).
This sort of function gives much more fine-grained control over the types we're going to count for memory usage, but has the danger of leaving important types out:
import sys
from numbers import Number
from collections import deque
from collections.abc import Set, Mapping

ZERO_DEPTH_BASES = (str, bytes, Number, range, bytearray)

def getsize(obj_0):
    """Recursively iterate to sum size of object & members."""
    _seen_ids = set()
    def inner(obj):
        obj_id = id(obj)
        if obj_id in _seen_ids:
            return 0
        _seen_ids.add(obj_id)
        size = sys.getsizeof(obj)
        if isinstance(obj, ZERO_DEPTH_BASES):
            pass # bypass remaining control flow and return
        elif isinstance(obj, (tuple, list, Set, deque)):
            size += sum(inner(i) for i in obj)
        elif isinstance(obj, Mapping) or hasattr(obj, 'items'):
            size += sum(inner(k) + inner(v) for k, v in getattr(obj, 'items')())
        # Check for custom object instances - may subclass above too
        if hasattr(obj, '__dict__'):
            size += inner(vars(obj))
        if hasattr(obj, '__slots__'): # can have __slots__ with __dict__
            size += sum(inner(getattr(obj, s)) for s in obj.__slots__ if hasattr(obj, s))
        return size
    return inner(obj_0)

And I tested it rather casually (I should unittest it):
>>> getsize(['a', tuple('bcd'), Foo()])
344
>>> getsize(Foo())
16
>>> getsize(tuple('bcd'))
194
>>> getsize(['a', tuple('bcd'), Foo(), {'foo': 'bar', 'baz': 'bar'}])
752
>>> getsize({'foo': 'bar', 'baz': 'bar'})
400
>>> getsize({})
280
>>> getsize({'foo':'bar'})
360
>>> getsize('foo')
40
>>> class Bar():
...     def baz():
...         pass
>>> getsize(Bar())
352
>>> getsize(Bar().__dict__)
280
>>> sys.getsizeof(Bar())
72
>>> getsize(Bar.__dict__)
872
>>> sys.getsizeof(Bar.__dict__)
280

This implementation breaks down on class definitions and function definitions because we don't go after all of their attributes, but since they should only exist once in memory for the process, their size really doesn't matter too much.
Comment: Any custom object implemented in C that doesn't properly implement `__sizeof__` will not work with [`sys.getsizeof`](https://docs.python.org/3/library/sys.html#sys.getsizeof), and this is not well-documented because
it is considered an implementation detail (see https://bugs.python.org/issue15436). Don't expect this function to cover everything - modify it as needed to best suit your use-cases.
Comment: `str`s that contain non-ASCII characters have [more overhead](https://github.com/python/cpython/blob/b063b02eabf91bfd4edc0f3fde7ce8f0ebb392c4/Objects/unicodeobject.c#L1405), for example, `sys.getsizeof('я')` is 76 and `sys.getsizeof('')` is 80.
Comment: I bet the difference in 2 bytes is because the terminating null also takes 4 bytes in the second case
Answer: The Pympler package's asizeof module can do this.
Use as follows:
from pympler import asizeof
asizeof.asizeof(my_object)

Unlike sys.getsizeof, it works for your self-created objects. It even works with numpy.
>>> asizeof.asizeof(tuple('bcd'))
200
>>> asizeof.asizeof({'foo': 'bar', 'baz': 'bar'})
400
>>> asizeof.asizeof({})
280
>>> asizeof.asizeof({'foo':'bar'})
360
>>> asizeof.asizeof('foo')
40
>>> asizeof.asizeof(Bar())
352
>>> asizeof.asizeof(Bar().__dict__)
280
>>> A = rand(10)
>>> B = rand(10000)
>>> asizeof.asizeof(A)
176
>>> asizeof.asizeof(B)
80096

And if you need other view on live data, Pympler's

module muppy is used for on-line monitoring of a Python application
and module Class Tracker provides off-line analysis of the lifetime of
selected Python objects.
Comment: @ihavenoidea: bytes (just imagine every python object taking 280 kbytes)
Comment: @serv-inc: Let me know if you need me to test it, because otherwise my program does not appear to have a memory leak so there is no urgent need for me.
Answer: For numpy arrays, getsizeof doesn't work - for me it always returns 40 for some reason:
from pylab import *
from sys import getsizeof
A = rand(10)
B = rand(10000)

Then (in ipython):
In [64]: getsizeof(A)
Out[64]: 40

In [65]: getsizeof(B)
Out[65]: 40

Happily, though:
In [66]: A.nbytes
Out[66]: 80

In [67]: B.nbytes
Out[67]: 80000

Comment: "If you are using a numpy array (http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html) then you can use the attribute 'ndarray.nbytes' to evaluate its size in memory." http://stackoverflow.com/a/15591157/556413
Comment: >All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific. http://docs.python.org/library/sys.html#sys.getsizeof
Comment: I would guess 40 bytes is correct, however `getsizeof()` only gives you the size of the object (the header of the array), not of the data inside. Same for python containers where `sys.getsizeof([1,2,4]) == sys.getsizeof([1,123**456,4]) == 48`, while `sys.getsizeof(123**456) = 436`
Comment: It appears the `getsizeof()` function was changed at some point to return the expected value.
Answer: You can serialize the object to derive a measure that is closely related to the size of the object:
import pickle

## let o be the object whose size you want to measure
size_estimate = len(pickle.dumps(o))

If you want to measure objects that cannot be pickled (e.g. because of lambda expressions) dill or cloudpickle can be a solution.
Comment: I find this simplest and most useful, especially because I care about Python object size the most when I need to serialize it (for multiprocess etc)
Comment: Does not work when a numpy slice is hogging memory. Like in
`import numpy as np;
a = np.arange(100000000);
b = a[2:4];
del a;
len(pickle.dumps(b)) # 150, but the array is 100MB or more depending on the dtype`
Comment: Another case when this does not work: `TypeError: cannot pickle '_thread.lock' object` -- will try `dill`/`cloudpickle` as suggested!
Comment: What is the unit of measure here? bytes?
Answer: Use sys.getsizeof() if you DON'T want to include sizes of linked (nested) objects.
However, if you want to count sub-objects nested in lists, dicts, sets, tuples - and usually THIS is what you're looking for - use the recursive deep sizeof() function as shown below:
import sys
def sizeof(obj):
    size = sys.getsizeof(obj)
    if isinstance(obj, dict): return size + sum(map(sizeof, obj.keys())) + sum(map(sizeof, obj.values()))
    if isinstance(obj, (list, tuple, set, frozenset)): return size + sum(map(sizeof, obj))
    return size

You can also find this function in the nifty toolbox, together with many other useful one-liners:
https://github.com/mwojnars/nifty/blob/master/util.py
Comment: Does not work when a numpy slice is hogging memory. Like in
`import numpy as np;
a = np.arange(100000000);
b = a[2:4];
del a;
len(pickle.dumps(b)) # 150, but the array is 100MB or more depending on the dtype`
Answer: Python 3.8 (Q1 2019) will change some of the results of sys.getsizeof, as announced here by Raymond Hettinger:

Python containers are 8 bytes smaller on 64-bit builds.

tuple ()  48 -> 40
list  []  64 ->56
set()    224 -> 216
dict  {} 240 -> 232

This comes after issue 33597 and Inada Naoki (methane)'s work around Compact PyGC_Head, and PR 7043

This idea reduces PyGC_Head size to two words.
Currently, PyGC_Head takes three words; gc_prev, gc_next, and gc_refcnt.

gc_refcnt is used when collecting, for trial deletion.
gc_prev is used for tracking and untracking.

So if we can avoid tracking/untracking while trial deletion, gc_prev and gc_refcnt can share same memory space.

See commit d5c875b:

Removed one Py_ssize_t member from PyGC_Head.
  All GC tracked objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes.
Answer: This can be more complicated than it looks depending on how you want to count things.  For instance, if you have a list of ints, do you want the size of the list containing the references to the ints? (i.e. - list only, not what is contained in it), or do you want to include the actual data pointed to, in which case you need to deal with duplicate references, and how to prevent double-counting when two objects contain references to the same object.
You may want to take a look at one of the python memory profilers, such as pysizer to see if they meet your needs.
Answer: Having run into this problem many times myself, I wrote up a small function (inspired by @aaron-hall's answer) & tests that does what I would have expected sys.getsizeof to do:
https://github.com/bosswissam/pysize
If you're interested in the backstory, here it is
EDIT: Attaching the code below for easy reference. To see the most up-to-date code, please check the github link.
import sys

def get_size(obj, seen=None):
    """Recursively finds size of objects"""
    size = sys.getsizeof(obj)
    if seen is None:
        seen = set()
    obj_id = id(obj)
    if obj_id in seen:
        return 0
    # Important mark as seen *before* entering recursion to gracefully handle
    # self-referential objects
    seen.add(obj_id)
    if isinstance(obj, dict):
        size += sum([get_size(v, seen) for v in obj.values()])
        size += sum([get_size(k, seen) for k in obj.keys()])
    elif hasattr(obj, '__dict__'):
        size += get_size(obj.__dict__, seen)
    elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
        size += sum([get_size(i, seen) for i in obj])
    return size

Comment: Crashes with "TypeError: 'Int64Index' object is not callable" on pd.Series
Answer: Here is a quick script I  wrote based on the previous answers to list sizes of all variables
for i in dir():
    print (i, sys.getsizeof(eval(i)) )

Comment: It is not wrong, it is ambiguous. sys.getsizeof will always return value is needed, so there is no need to loose performance with try..except.
Comment: oh, that's a good point and I didn't think about it - the code in the form it is right now just shows how it was chronologically written - first I knew about numpy (hence nbytes), then I looked up a more generic solution. Thank you for the explanation _/\\_
Answer: Use following function to get actual size of a python object:
import sys
import gc

def actualsize(input_obj):
    memory_size = 0
    ids = set()
    objects = [input_obj]
    while objects:
        new = []
        for obj in objects:
            if id(obj) not in ids:
                ids.add(id(obj))
                memory_size += sys.getsizeof(obj)
                new.append(obj)
        objects = gc.get_referents(*new)
    return memory_size

actualsize([1, 2, [3, 4, 5, 1]])

Reference: https://towardsdatascience.com/the-strange-size-of-python-objects-in-memory-ce87bdfbb97f
Comment: This seemed to give a more meaningful answer for class instances than other answers. However, with an array of class instances, this reported almost the same size for a single item as for all items -- not sure why.
Comment: `actualsize()` for just the simplest NamedTuple you can think of gives 19+ MB(!). Any idea what the function is counting here?
Comment: Can you give an example NamedTuple
Comment: @AmanGupta `from collections import namedtuple; nt = namedtuple("nt", ["a", "b"]); print(f"{actualsize(nt(3, 'Hello')):,}") # 19,264,817` seems to count the module code, too...
Comment: It probably goes quite deep into references of all libraries used etc. I got also insane sizes for simple objects.
`actualsize(namedtuple("a", "a b c")(1, 2, 3))` or `actualsize(Path())`
Answer: If you don't need the exact size of the object but roughly to know how big it is, one quick (and dirty) way is to let the program run, sleep for an extended period of time, and check the memory usage (ex: Mac's activity monitor) by this particular python process. This would be effective when you are trying to find the size of one single large object in a python process. For example, I recently wanted to check the memory usage of a new data structure and compare it with that of Python's set data structure. First I wrote the elements (words from a large public domain book) to a set, then checked the size of the process, and then did the same thing with the other data structure. I found out the Python process with a set is taking twice as much memory as the new data structure. Again, you wouldn't be able to exactly say the memory used by the process is equal to the size of the object. As the size of the object gets large, this becomes close as the memory consumed by the rest of the process becomes negligible compared to the size of the object you are trying to monitor.
Comment: The question asks how to do it *in python*, not just finding memory usage *of* python objects, and using a Mac's activity monitor or any other similar software isn't programmatically using python. That being said, checking memory usage of python processes in this way generally is a good way to make sure nothing has gone wrong...
Comment: @TomWyllie, Thanks, but downvoting this answer carries the negative connotation that the answer itself is wrong and accomplishes nothing. The method I mention might not be implemented in Python, but it is a handy way to get a rough estimate of a size of a Python object. I knew I am not answering the exact question, however, the method could be useful for someone else to get a similar result.
Answer: If performance is not an Issue, the easiest solution is to pickle and measure:
import pickle

data = ...
len(pickle.dumps(data))

Comment: @pippo1980 - Why no upvotes?  Because [this solution was already posted](https://stackoverflow.com/a/59228005/6340496) two years prior. Therefore the original answer is (rightfully) getting the votes.
Comment: does this work ? why not any upvote to this ?
Comment: usually I upvote every solution that works. Shouldnt I ?
Answer: I use this trick... May won't be accurate on small objects, but I think it's much more accurate for a complex object (like pygame surface) rather than sys.getsizeof()
import pygame as pg
import os
import psutil
import time

process = psutil.Process(os.getpid())
pg.init()
vocab = ['hello', 'me', 'you', 'she', 'he', 'they', 'we',
         'should', 'why?', 'necessarily', 'do', 'that']

font = pg.font.SysFont("monospace", 100, True)

dct = {}

newMem = process.memory_info().rss  # don't mind this line
Str = f'store ' + f'Nothing \tsurface use about '.expandtabs(15) + \
      f'0\t bytes'.expandtabs(9)  # don't mind this assignment too

usedMem = process.memory_info().rss

for word in vocab:
    dct[word] = font.render(word, True, pg.Color("#000000"))

    time.sleep(0.1)  # wait a moment

    # get total used memory of this script:
    newMem = process.memory_info().rss
    Str = f'store ' + f'{word}\tsurface use about '.expandtabs(15) + \
          f'{newMem - usedMem}\t bytes'.expandtabs(9)

    print(Str)
    usedMem = newMem

On my windows 10, python 3.7.3, the output is:
store hello          surface use about 225280    bytes
store me             surface use about 61440     bytes
store you            surface use about 94208     bytes
store she            surface use about 81920     bytes
store he             surface use about 53248     bytes
store they           surface use about 114688    bytes
store we             surface use about 57344     bytes
store should         surface use about 172032    bytes
store why?           surface use about 110592    bytes
store necessarily    surface use about 311296    bytes
store do             surface use about 57344     bytes
store that           surface use about 110592    bytes

Answer: This might not be the most relevant answer, but I was interested only in object storage and retrieval. So dumping the object as pickle and checking the pickle's size was sufficient
Answer: import io
import torch
import sys

def get_size(obj):
    buffer = io.BytesIO()
    torch.save(obj, buffer)
    return sys.getsizeof(buffer)

# Let's test by creating some unusual object

obj = []
import types
import numpy
for i in range(5):
    namespace = types.SimpleNamespace()
    namespace.text = 'hi stack overflow'
    namespace.array= numpy.arange(100000)
    namespace.torchy=torch.randn((2,5,6,7,7,3,4))
    obj.append(namespace)

print(get_size(obj))

Answer: You can make use of getSizeof() as mentioned below to determine the size of an object
import sys
str1 = "one"
int_element=5
print("Memory size of '"+str1+"' = "+str(sys.getsizeof(str1))+ " bytes")
print("Memory size of '"+ str(int_element)+"' = "+str(sys.getsizeof(int_element))+ " bytes")


Term for Single-Word Epigraph?

Question: The novel Once an Eagle is divided into five 'books.' Each 'book' is titled by a single word, such as "Wheat" or "Chaparral," which serves to suggest the theme. These words/titles cannot properly be called epigraphs because they are not full quotations; what is the technical term for a one-word 'epigraph'?
Comment: Why do you think that "epigraph" is not valid?  The use of quotations in this sense is only a convention, not a rule.
Comment: I don't think you'd use 'epigraph' for the title of the chapter itself. That said, if you take an epigraph and edit it down to one word, I don't think its epigraph status disappears.
Answer: The division that you're talking about is sometimes referred to as a part. Unless I'm mistaken, there is no more accurate (or "technical") term for it.
Typically books have chapters. Within each chapter can be scenes or sections.
A "part" is composed of multiple chapters—organized by some significant theme or event.
Parts can be labelled "Book One" or "Part One", or they can have more descriptive titles. They act as logical divisions.
In your case, these "part labels" are single words.
You are, however, correct that these single words would not typically be considered epigraphs. An epigraph is a phrase or quotation, and normally has an attributed source. While epigraphs can be used to mark divisions in books, I have never seen one that is only a single word.
Perhaps in the same way that we have chapter titles, what you're referring to could be called division titles. (I would say "part titles," but that doesn't sound right.)
I don't know if there is a universally accepted name for this or not.

Term for Single-Word Epigraph?


modify wsdl port name or soap address location for an axis webservice

Question: This issue is with axis2 webservice. The generated wsdl contains the below port and address details:
<wsdl:service name="ServiceName">
    <wsdl:port name="ServiceNameHttpSoap11Endpoint" binding="ns:ServiceNameSoap11Binding">
    <soap:address location="http://ipaddress/webServiceProject/services/ServiceName.ServiceNameHttpSoap11Endpoint/" />
    </wsdl:port>
</wsdl:service>

My requirement is to edit the address location to something simple(with out having the ServiceNameHttpSoap11Endpoint) Is there any setting to customize the generated wsdl ? All I am doing is right click on the project in eclipse and selecting "create webservice".
Answer: You can use your service endpoint as
http://ipaddress/webServiceProject/services/ServiceName

which is also right.But in wsdl,service endpoint ends with wsdl port..Both are right..


How can I delete extended event files from within Managed Instance?

Question: Simplifying a few details, I have a recurring process on SQL Server 2019 which runs every 10 minutes and does the following:

Reads data from extended event file targets using sys.fn_xe_file_target_read_file
Processes the data and saves it to a table in SQL Server
Stops and starts the event session to remove all data from the extended event file targets.

In this way, I can process all of the data that has accumulated since the last time it ran. I am trying to make this process work with the Managed Instance platform. Unfortunately, stopping and starting the event session does not clear out the xel files on the Managed Instance platform:

This is a problem because my recurring process will continue to process the same data over and over. It also means that the temporary xel data takes up way more storage than before.
Is there a way to delete an .xel file using T-SQL on the Managed Instance platform? xp_cmdshell is not supported. I even tried the undocumented sys.xp_delete_files procedure but that didn't seem to work either.
I could use Azure lifecycle management policies if I have no better option.  However, as far as I can tell, it could delete files before they were processed if there was some kind of error in my T-SQL process.  I'd prefer to explicitly remove the processed xel files as part of my automated system.
Answer: As a workaround, you may process data using the last timestamp already inserted in your SQL table by adding a condition in the WHERE clause. To minimize storage, you can set a lower maximum rollover file in the extended event.


Does distortion change with focus?

Question: I'm interested in writing some software to eventually replace the current photogrammetry system I use at work. Distortion correction (among other calibrations) is an important factor in getting high accuracy measurements across the whole sample volume. With a lens at a fixed focal length and fixed focus, do the distortion correction factors change slightly as you move the subject in and out of the focal plane?
Comment: It's hard to tell what you are asking.  Distortion and defocus are different parameters, and you can have a variation in each across the image plane at any distance (best focus or not).  It's likely that astigmatism and coma will do more to degrade your measurements (as you go out of focus) than will a putative change in distortion.
Comment: @CarlWitthoft take a look at the answer I posted for (hopefully) a little better idea of where I'm coming from.
Answer: In short, yes the focus distance has an impact on calibration parameters. For further information on that, refer to this paper by D. C. Brown on Close-Range Calibration. Generally, it is advised to have the camera focused at infinity when capturing photographs for calibration purposes. To do that, you simply have to calculate the hyperfocal distance for your camera. There is an Android app that has many preloaded camera setups called Hyperfocal that does just that.
Comment: Yes, but I haven't uploaded it yet. I have a website to showcase it though. Visit www.imagecor.eu and send me a mail through the contact form.
Comment: I haven't gotten all the way through it yet, but this paper looks to be just about exactly what I was looking for. Thanks!
Comment: I have recently created a software package that performs calibration using the chessboard method and also with a calibration field. It also has a feature for distortion correction. If you are interested I could send it to you.
Comment: That would be awesome! This project seems to have fallen a bit to the wayside for me as other projects come in that are higher priority, but I'd love to take a look to stash it away in the back of my brain. Do you have a github?
Answer: The distortion will change as a function of object distance unless the lens is image space telecentric and has no distortion to begin with.  This is because for a nonzero chief ray angle, the image will enlarge as the object draws closer -- this is referred to as "focus breathing."  This in combination with the variation in aberrations that affect distortion (notably, coma) with object distance will lead to changes in the measured or perceived distortion as a function of distance.
You may also encounter a failure of the mapping function of the lens you use if the object is sufficiently near.  E.g. a rectilinear ultra wide angle lens looks "ok" at a great distance, but very distorted at a near distance.  The lens is not distorted, the center of the FoV is simply much closer to the lens.  This is a failure of the mapping function.
Answer: I think I may have found a solution that implies there is indeed no relation of distortion and focus. This relies on the fact that a lens system can be accurately modeled by Zernike polynomials (I am not sure what the assumptions of this model are with respect to lens/sensor systems, and how they differ from reality).
The first eight terms of the polynomial can be used to describe common lens imperfections:

Tilt: α1 × ρ cos(θ); α2 × ρ sin(θ)
Defocus: α3 × (2ρ2 - 1)
Astigmatism: α4 × ρ2 cos(2θ); α5 × ρ2 sin(2θ)
Coma: α6 × (3ρ2 - 2) ρ cos(θ); α7 × (3ρ2 - 2) ρ sin(θ)
Spherical Aberration: α8 × (6ρ4 - 6ρ2 + 1)

As you can see, none of these terms (and indeed the infinite form summation) include a term for displacement from the aperture (only polar position on the image plane: ρ, θ).
I would appreciate any comments anyone has on the validity of this model in realistic applications.
Comment: It appears everything in article you linked to refers to a _single_ lens (i.e., single piece of glass). The geometry of a single piece of glass cannot change, so the polynomial coefficients are fixed. For a real-world camera lens that moves one or more glass elements (or groups of elements) to focus, the relationships of the modeled parameters of each glass element changes with respect to the other elements. Therefore, I strongly infer that the coefficients are really coefficient _functions_ of focus position of the lens (and for zoom lenses, a function of zoom as well).
Comment: Also, as a suggestion, there's probably a better chance for good answers/info from the optics-minded contributors over at Physics.SE. I know there are a couple optics wonks here, but there are probably more at PSE, and such topics are more, well, topical, there. =)
Comment: @scottbb what you say about multi-element lenses is true in general, but the OP is asking about a fixed-focus system. It has multiple elements but since they are not moveable, the single-element formulas hold (albeit not other ones such as chromatic distortions)  BTW  I **am** an "optics wonk" :-)
Comment: @CarlWitthoft I knew you were an optics wonk. Didn't mean to slight you... =)
Comment: @CarlWitthoft &scottbb thanks for the comments, I am accustomed to having to re-calibrate every time the lenses are re-focused (they lock in place with a set screw). As for chromatic aberration, I would tend towards using a monochromatic filter instead of trying to correct in software.
Comment: You should not use zernike polynomials to describe field-dependent behavior, as they have no notion of field dependence.  Rho and theta refer to the position of a point in the pupil of the lens, not a position in the image plane.
Answer: Moving a subject in or out of the focal plane only defocuses, does not distort.
The distortion I believe you are referring to is relative size to distance based on the fixed focal length of the lens.
While there may be no relationship between distortion and being out of focus in respect to one's position to the focal plane, do you not need to know where, if the subject you are measuring, is in front of or behind the focal plane?
If you are trying to come up with a formula to be able to tell how tall a person is based on items in the image and the focal length of your lens, the wrong lens will give you compression as another factor to deal with.
And your formulas are not just relegated to lens imperfections.
Tilt is as much based on how level the photographer holds his lens to the subject. How can you tell the difference?
Defocus is either you have the wrong focal point, or the subject is not in the focal plane. That the photographer has as much to do with as the lens.
Your question is just a bit too ambiguous to give you an answer. I just disproved several of your formulas as they must include the photographer factor.
Comment: I appreciate your response, but I think you missed the point of what I was asking. The equations are not "wrong" but they do not account for things like wavelength and diffraction. The photographer - subject relation is not really important, as it is simply modeled as wave front error (which could be converted into a coordinate system if a particular wavelength was chosen). Ultimately, I'm likely going to implement a statistical calibration approach instead of an analytical one, but the validity of this model would determine how many terms I need for the statistical model as well.
Comment: Just for a reference of why I'm doing all this, it's not unheard of in the optical measurement world to achieve a positional accuracy of greater than 1/50th of a pixel. lenses can be made nearly perfectly (ground to an accuracy of tens to hundreds of nm) but those are prohibitively expensive, and only used in special physics experiments. With proper calibration, off the shelf lenses can be used to also get very high accuracy (I currently use a proprietary software system that gets 1/20th pixel accuracy with ~$500 lenses)

Does distortion change with focus?


Will the university know I've submitted this assignment at my previous university?

Question: I was studying at a university that shut down during Covid. I decided to move home and continue my studies with a different university. Some of my already completed units I got RPL for, some I did not. I have an assignment at my new university that is basically the same as an assignment I did at my previous university. If I submit this assignment to my new university, is there any way they will be able to tell that I've already used it before at a previous university?
Comment: "*I am considering committing academic misconduct. What are the chances that I will get caught?*" Why should we help you with such a question? The only reasonable answer is "Don't commit misconduct."
Answer: If you submit exactly the same thing that will likely be considered self-plagiarism. If you still remember how to do it and solve it without resorting to the previous homework you will still be fine. In most cases going over previous notes (your own notes) will not constitute any honor code violation, but the only one that can tell you if that is ok or not is the instructor for that class, as that is not explicitly dealt with in any university's honor code.
All that aside, your intent clearly is to do something you think is wrong and not get caught, so it is clearly wrong and you know it.
Comment: When I was teaching, I always took the position, with respect to undergraduate summative assessments, that it's only self-plagiarism/misconduct if the student has previously _received credit(s) for_ the same work.  If OP's instructor takes the same position, it matters whether the assignment was from one of the units for which OP received RPL, or from one of the units for which they didn't.  But either way, you're right that it's important that OP discusses the situation with their instructor before going ahead.


Parity of Bloch states at TRIM points

Question: There is an argument presented in Fu and Kane's paper on inversion symmetric topological insulator which I have not yet convinced myself. Just below Eq.(3.6), the authors said that because of inversion symmetry: $[\mathcal{H},P]=0$, the Bloch state $\lvert \psi_{n,\Gamma_i} \rangle$ is a parity eigenstate, where $\Gamma_i$ is some time-reversal invariant momentum (TRIM) point. And then together with time reversal symmetry, members of the Kramers pair have the same parity, as claimed below Eq.(3.8).
My question is how do we know that $\lvert \psi_{n,\Gamma_i}\rangle$ is a parity eigenstate? To me this does not follow immediately from the commutation of the Hamiltonian and the inversion operator because the spectrum is degenerate at the TRIM points due to Kramers degeneracy. So it might be some non-trivial mixing of the Kramers states that diagonalise $\mathcal{H}$ and $P$ simultaneously. I also cannot convince myself that members of a Kramer pair have the same parity.
I would greatly appreciate it if someone can give a detailed explanation on the above points!
Answer: The time reverse operator takes $k\rightarrow-k$, and the inversion operator also does it. So a time-reversal-invariant momentum (TRIM) point is also inversion-invariant momentum point.

Parity of Bloch states at TRIM points


unpolite or impolite

Question: can one say "unpolite"? As in the following sentence: "it's hard for me to be unpolite." I was in class today and my teacher asked me to give him an example of an infinite sentence and that came out of my mouth just because, but my teacher corrected me. And told me to say "impolite" instead, but I found acouple of threads on the internet with opposed ideas. So please help me with this one.
Comment: Welcome to EL&U. Questions should demonstrate some research effort, for example, by quoting dictionary definitions— the ODO definition for *[unpolite](http://www.oxforddictionaries.com/us/definition/american_english/unpolite)* says *impolite is now more usual in this sense*, and there is no entry at all in most learners' dictionaries. This suggests that *unpolite* is, at least, very rare. If you believe the other "threads on the Internet" are reliable, you should include them as well. Our sister site for [English Language Learners](http://ell.stackexchange.com/tour) may interest you.
Answer: In modern English, the correct term is "impolite".
However, Google Ngrams shows that two hundred years ago, it was more common to say "unpolite".
Both in- (im-) and un- are used for different adjectives, I don't think there is a rule for which one to choose. Sometimes it changes even for adjectives and nouns that have the same root, for instance: unstable but instability.

unpolite or impolite


Itunes connect change from last week

Question: In my iTunes connect developer profile, I see a change from last week, and just below it says a change next to the number of units sold. What is this "change"? Is this how many people uninstalled the app?
Answer: No, its the difference between number of downloads last week and number of downloads this week.

Itunes connect change from last week


Link label is cut off at the buttom c#

Question: In my C# winform application I have a link label.
when the text in the link label is localize to chinese the text is cut off at the buttom by the line of the link label.
Any idea?
Answer: East Asian machines tend to run with a larger system font size to make characters more legible.  The setting of Form.AutoScaleMode matters, so does the Form's Font vs the control's Font.  Ensure that your form scales properly.
Answer: It could be the font you are using for the link label. Try changing the font or setting different size.
I don't think you've posted enough information. You could post a screenshot.

Link label is cut off at the buttom c#


What is a good alternative to Unified Shader for Shadows?

Question: Most shadow systems I have seen use a unified shader system for shadowing techniques, resulting in an uber shader for the projects.
What alternatives do you find work well or is the unified shader the best approach?
Answer: I'm assuming your question is about shadow map-based techniques.
Generally choosing uber shaders is a higher-level decision than shadows, so shadows usually follow whatever method engine uses for rendering.
For example, you might choose using deferred rendering which requires far less permutations than traditional approach, then applying shadows will be added once to the deferred light shader and rendering shadomwap will be essentially the same path that generates G-Buffers.
Another thing I think I heard people considered is to just generate shadowmaps on SPUs without any shaders.
So decide on your method for rendering the scene and use it for shadows as well.
Comment: Deferred shadows can be implemented whether you use forward or deferred rendering. So this answer didn't really make any sense in my opinion.
Answer: From what I see, you have three alternatives to uber-shaders:

Hand-code every shader. Obviously, this is easy if you just have a few shaders and similar lighting conditions everywhere (which might actually be the case on embedded devices). However, it quickly becomes unmanageable with even a few inputs (number of lights, shadows, different materials).
Deferred rendering. Effectively splits up the complexity of uber-shaders into several rendering passes. It's very nice design-wise but the memory and bandwidth requirements are high. Variations include "Light pre-pass" rendering, which does just the lighting in separate passed and gives you complete lighting information in your final compositing shader (which makes this very flexible!).
A shader "build-system". It'll assemble shader-permutations from smaller modular shader-fragments. The whole idea is very similar to uber-shaders, but the more modular design can make it possible to get away with a lot less permutations (since not all options in the uber-shader are orthogonal to each other). It's a pain to build such a system, and there are quite a few pitfalls - but if you get it right, it is quite a powerful tool to have if you don't want something deferred.

In the end, it depends on the specifics of your project. The bigger the project gets, the more I would steer away from hand-coded shaders or uber-shaders and pick something more modular like light pre-pass or a shader build-system. The trend is definitely going towards deferred rendering systems though.
Comment: What even is an "uber-shader"?
Comment: @DeadMG: it's typically a single shader with lots of `#ifdef`s in it that is compiled in all its permutations. The engine then selects the right shader object for a given material.


SHAKE-128/256 or SHA3-256/512

Question: Would it be better to use SHAKE-128/256 or SHA3-256/512? In what situation should I chose one over the other?
Answer:
And in which case would it be more interesting to use one or another?

So SHA3-$n$ offers $n$ bits of security against preimage and second-preimage attacks and $n/2$ bits of security against collision attacks.
On the other side SHAKE-$n$ offers at $n$ bits of security against preimage and second-preimage attacks and also $n$ bits of security against collision attacks (assuming the digest is at least $2n$ bits long). So when to use which?

When you are forced to use "an approved hash function", you use SHA3, because SHAKE doesn't qualify.
When you need a really long hash output (or an XOF in general), you use SHAKE.
When you really need more than 256 bits of security against preimage or second-preimage attacks you use SHA3.
When you want to be compatible with more other systems, you probably want to use SHA3.
When speed matters to you (and you still want to use SHA3 / SHAKE) and you are happy with an all-arond $n$-bit security level (for $n\in\{128,256\}$), you use SHAKE.

This last point follows from the fact that the higher preimage resistance in SHA3 is paid for with lower rate (=number of new bits processed per internal permutation invocation) which is usually higher in SHAKE than in SHA3 (SHAKE256 has the same as SHA3-256).
Answer: You should generally just use SHAKE128, but you should make sure that within your application, you don't use the SHAKE128 hash (to any length) of the same data for two different purposes.  For example, prefix each message you hash with an unambiguous description of the purpose for which you are hashing it: $\operatorname{SHAKE128-256}(\text{'file hash:'} \mathbin\| m)$ and $\operatorname{SHAKE128-512}(\text{'username hash:'} \mathbin\| u)$.
The main reason for (e.g.) SHA3-256 and SHA3-512 is to provide a mindless upgrade path from SHA-256 and SHA-512 that won't hurt security in the event that you happened to use SHA-256 and SHA-512 hashes of the same string and assumed the hashes to be independent.  In contrast, SHAKE128-256 is a prefix of SHAKE128-512 and therefore very much not independent.
Otherwise, SHA3-256 was overdesigned out of paranoia and political reasons—and SHA3-512 even moreso—and is consequently substantially more expensive than SHAKE128 for no meaningful improvement in security.  SHAKE128 is conjectured to provide up to the standard 128-bit security level for preimage resistance and collision resistance against all adversaries, classical or quantum.  Of course, for 128-bit preimage resistance you need to use at least a 128-bit output, and for 128-bit collision resistance you need to use at least a 256-bit output.
For an additional hedge against modest cryptanalytic advances, like for use with edwards448 instead of edwards25519, you might use SHAKE256.
Comment: Given that SHAKE128 has 256 bits of capacity, I would've guessed it had up to 256 bits of preimage resistance. Why is it only 128? Is the situation something like "it's probably 256 but easier to prove 128", or is there some specific reason why it definitely can't be 256?
Comment: @JackO'Connor Because it's based on a permutation, you can go forwards and backwards along the chain of permutation calls. I think this lets you do a meet in the middle attack to find a preimage with $O(2^{c/2})$ Keccak permutation queries for capacity $c$.

SHAKE-128/256 or SHA3-256/512


Contactor's Coil Current

Question: YuCo YC-CN402-24V CN-PBC402-24V DEFINITE PURPOSE CONTACTOR with a Packard PF42440 Control Transformer Class II Foot Mount 40VA 24V to activate the 2vac coil.  The circuit is a 220v 20amp motor.  My question is how much current draw does it take to open that 24vac coil on the contactor?  Will it take all the current from the transformer to drive the coil?  If it does not take all the current can you split the current out of the transformer and use it for say driving the controller (Arduino). Thank You for your help.
Answer: It looks like the coil needs a maximum inrush of 32VA at 60 Hz, so you have some power left over to drive a controller. The holding current is much less, so if you have a big enough filter capacitor on your Arduino power supply to last through the inrush, you can use more average power.
In the future, please provide your own links to the relevant data.
Comment: Thanks for your reply.  Very helpful I do not think it is enough to supply the rest of the project.
Answer: It depends on the power you consume on your Arduino system.
The datasheet on your link shows:

The maximum likely VA is 35 @ 50 Hz and the coil will consume only 7 VA when closed.
If the Arduino is NOT controlling the contactor start....

If you bridge rectify the output of the Control transformer then you need to be careful of the value of any filter capacitors used.
If the value is too high then you could cause the contactor to bounce at turn-on.
It may be advisable to include a series resistance after any bridge resistor to minimize inrush current for the Arduino supply, though if all you are powering is an MCU this is probably not going to be an issue.

If you are using the Arduino to turn on the contactor.....ensure your Arduino power supply has enough supply carry through to miss a couple of cycles when you turn on the Control transformer.
Comment: Very helpful.  It looks like I need another power supply for the Arduino and other parts of the project.  Now I can see where you got that information from...  Very Helpful

Contactor's Coil Current


How do I tame and ride the undead horses?

Question: So the 15.0 update came out for minecraft pocket edition. Well along with horses there are also the zombie horse and skeleton horse. Is it possible to tame these? If so how?
Answer: Basically, if you spawn one using a spawn egg for example, it won't work. However, they do spawn naturally, but only during a thunderstorm. In these situations, they are referred to as "Trap Skeleton Horses".
To be able to ride them, they need to be struck by lightning, which will cause them to split into 4-5 mounted skeletons. Fortunately, all you need to do is walk within 10 blocks of a lone skeleton horse, to trigger the trap (they will automatically be struck by lightning when this occurs). Kill the skeletons, and the horse will then be ride-able, and you can then tame it by giving it a saddle.
Source
Zombie horses however cannot be ridden if spawned by the player unless the following command is used (Java Edition only):
<code>/summon minecraft:zombie_horse ~ ~ ~ {Tame:1b}
</code>
Source
Answer: Here is tutorial of how to tame and ride a horse, put saddle or armor on horse and get off it. Anyway, I feel much easier to tame horse in Minecraft minecraft pocket edition than in Minecraft PC.
Step 1: Spawn a horse with horse spawn egg.
Step 2: Tame a Horse with Gold Apple, Gold Carrots
Step 3: Ride a Horse by taping it with Empty Hand
Step 4: Put a horse armor and saddle on horse in MCPE 0.15
Step 5: Get off horse in MCPE 0.15
<code>    Method 1: Use Sneak (double tap the center button on left side control)
    Method 2: Ride the horse and jump into water, double tap the right   button and fly high away from horse. ( this silly method is figured out by myself before haven't got the first way)
</code>
For all details and HD image instructions you can visit here.
Answer: The skeleton horses only spawn if a horse is struck by lightning. You can't ride them if you use a spawn egg. To get on the skeleton horse, you have to be holding a golden carrot, then tame the horse and put a saddle on. The zombie horses don't spawn in minecraft pocket edition unless the player spawns them manually.
Answer: A skeleton horse will be tamed, and ridable, if you hold a hay bale to it. However, I think this is only possible if it was spawned.
Comment: This is absolutely, positively, 100% wrong.  Skeleton horses can not be fed or bred, as per the official Minecraft wiki.
Answer: Undead horses can spawn naturally, you don't have to use eggs. They just need to be struck by lightning.
If you kill the skeletons that are riding the horse you can ride it.
Answer: Once a skeleton was riding a skeleton horse, I killed the skeleton and rode the skeleton horse, So you can probably do that to.
Answer: Depends on which type of undead horse you are referring to. Zombie horses do not spawn naturally in PE, at least not yet, and I dont believe you can tame them after manually spawning them. Skeleton horses, however, spawn naturally from "skeleton traps", which are a seemingly normal horse walking around during a storm. But when you get close to it, lightning will strike it, turning it into 3-4 skeleton horses with skeletons riding on them. The skeletons have enchanted armor, but if you kill them you can tame the skeleton horses they ride on.