Netcat UDP File Transfer?

Question: Is there any way to send a file (picture or video) using Netcat and UDP. It defaults as TCP, but I would like to send using UDP. I tried simply adding -u to the nc command, but that didn't work. Here are the two commands I'm using:
cat File.jpg | nc -u -l 777
nc -u 192.168.x.x 777 | pv -b > newfile.jpg

I used my IP address for x.x, and the corresponding file on my PC. I am also using Ubuntu.
Thanks for any assistance!
Comment: @Oliver: This is exactly the kind of answer that is of no practical use. I understand the point you try to make, but Mulaz gave the commands that were asked about. Whether or when to use TCP/UDP is the requester's decision, not the point of this post.
Answer: Try it like this:
nc -u -l 7777 > newfile.jpg #on the destination machine
cat file.jpg | nc -u 192.168.x.x 7777 #on the source machine

Usually you want the machine getting the file to "listen" (run that first), and when it's listening, send the data over udp. UDP does not have a 'handshake' sequence, and packets are sent immediately, even if noone is listening*.
*sometimes you get an ICMP packet, that the port is closed (unreachable), but you cannot depend on that (firewalls etc.)
Comment: Just to say it explicitly: UDP has absolutely no "reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level." ([Wikipedia](http://en.wikipedia.org/wiki/User_Datagram_Protocol))
Answer: I think this question must be answered as follows: Yes, there is a way of sending a file with Netcat over UDP. However, it is not possible to reliably receive this file on the destination host.
If you want to have a usable file on the destination host, look for another solution.
Comment: The file will be recieved correctly 99+% of the time. Packet error/loss rates on a local network are very low. I know JPEG is a bad example, but sometimes, with some data, you don't need 100%, especially if you send it often (sensors, etc.).
Comment: The question was not about a local network, nor about lossy data. It was about a normal file for which netcat and udp is not the way to go.
Answer: Using the TCP option does not guarantee that your file will be received intact.
TCP only provides 16 bits of error protection. That means that 1 in 65,536
transmission errors will get through.
To safely transmit files between systems you should calculate a hash of the entire
file before sending and validate it after reception.
If you are doing that, sending via UDP is totally valid. You want to have a
very low probability of transmission errors, however. Do not attempt this over
a busy WiFI network, or to a computer on the other side of the continent.
But within a building through a wired network you will encounter very few errors.
Comment: Please note that this is a very old question from 2012. It is generally best to avoid adding to old threads in order to keep the front page clear for recent queries.

Netcat UDP File Transfer?


Validação no Laravel

Question: Estou usando um Form Request Validation para fazer a validação de um formulário, porém quando deixo um campo do tiporequired em branco nenhum erro é gerado.
Como faço para gerar um erro quando a validação falhar ?
class SaleRequest extends FormRequest
{
   public function authorize()
   {
       return true;
   }
   public function rules()
   {
        return [
            'vendor_id' => 'numeric|required',
            'price'     => 'numeric|required',
            'name'      => 'string|required',
        ];
   }
}

Rota:
Route::post('/api/list/new/sale', 'SalesController@insert');

Controller:
public function insert(SaleRequest $request)
{
    $vendorInformation = $this->sale->insert($request->all());

    return response()->json($vendorInformation);
}

Model:
public function insert($request)
{
     $request['comission'] = $request['price'] * 0.085;
     $sale = $this->create($request);
     return $this->informationVendor($sale->attributes['id']);
}

public function informationVendor($idSale)
{
    return $this->join('vendors', 'vendors.id', '=', 'sales.vendor_id')
                ->where('sales.id', $idSale)
                ->select('vendors.name', 'vendors.email',
                         'sales.name', 'sales.price', 'sales.comission')
                ->get();
    }
}

Comment: qual é a versão do teu laravel ?
Comment: 5.4, não tem view, estou retornando um json direto do controller
Comment: editei a pergunta
Comment: @DavidSantos você manda esses dados via ajax? e quer um retorno se tem problemas com validação?
Comment: eu estou usando o postman para fazer as requisições, queria retornar algum erro caso a validação falhasse
Answer: No método do controller, não utilize com FormRequest, porque, no seu caso não funcionará, então, faça como exemplo abaixo:
Adicione o namespace abaixo que é op  FACADE responsável pelo Validator:
use Illuminate\Support\Facades\Validator;

Código alterado:
public function insert(Request $request)
{
    $validator = Validator::make(
        $request->all(),
        [
            'vendor_id' => 'required|numeric',
            'price'     => 'required|numeric',
            'name'      => 'required|string',
        ]);

    if ($validator->fails())
    {
        return response()
            ->json($validator->errors());
    }
    return response()
        ->json($this->sale->insert($request));
}

Observação: required sempre é a primeira validação.

Após essa modificação você terá resposta assim:

quando o model não for satisfatória, e quando tiver tudo correto receberá as informações assim:

Validação no Laravel


Popular select de forma dinamica

Question: Tenho uma consulta que retorna um array onde eu quero popular um select de forma dinâmica, mas pelo código abaixo ele da com undefined
for(var i = 0; i <= cidades.length; i++){
            var html = "";
            html += "<option>" + cidades[i] + "</option>";
            document.getElementById("cidade").append(html);
        }

Answer: O elemento "cidade" é um select por isso e adicionar html a ele como faria num elemento div talvez não seja a melhor opção, a criar os elementos option e adicionar seria mais legível:
for(var i = 0; i <= cidades.length; i++){
    var selectCidade = document.getElementById("cidade");
    var option   = document.createElement("option");
    option.value = cidades[i];
    option.text  = cidades[i];
    selectCidade.appendChild(option);
}

Answer: Seu for está percorrendo uma vez a mais, e também acredito que o método append não vá funcionar em elementos do tipo select, tente modificar o innerHTML dele.

Segue abaixo um exemplo:

for(var i = 0; i < cidades.length; i++)
{
    var html = '<option>'+cidades[i]+'</option>';
    document.getElementById('cidade').innerHTML += html;
}

Outra maneira legal de percorrer o vetor é usando o forEach, segue exemplo:

cidades.forEach(function (cidade) {
    var html = '<option>'+cidade+'</option>';
    document.getElementById('cidade').innerHTML += html;
});

Popular select de forma dinamica


Nested React Native Navigation doesn't show up

Question: i'm currently working on a React Native App, it has two Main Screens, the main navigator is a Tab Navigator. The second main screen has its own NativeStack Navigator.
My Problem is, that the Second Navigator doesn't show anything. I just get a empty screen.
Second Screen Code:
import {DataTable, Header, Screen} from '../../components';
import {
  NativeStackNavigationProp,
  createNativeStackNavigator,
} from '@react-navigation/native-stack';
import {ScrollView, StyleSheet, View, ViewStyle} from 'react-native';

import {EditorCreate} from '../Editor/Create';
import React from 'react';
import {useDatabase} from '../../data';
import {useNavigation} from '@react-navigation/native';

type TProps = NativeStackNavigationProp<{}>;
const ReportStack = createNativeStackNavigator();

interface IStyle {
  container: ViewStyle;
  header: ViewStyle;
  dataList: ViewStyle;
  dataControls: ViewStyle;
}

/**
 * @description Report Bildschirm
 * @author OliverKarger
 * @param {IProps} props
 * @return {React.FC}
 */
export function ReportScreen(props: TProps) {
  const data = useDatabase({query: 'SELECT * FROM ENTRIES'}).data;
  const navHook = useNavigation();
  const style = StyleSheet.create<IStyle>({
    container: {
      flex: 1,
      flexDirection: 'column',
      justifyContent: 'center',
      alignItems: 'center',
    },
    header: {
      flex: 1,
    },
    dataList: {
      flex: 4,
      // backgroundColor: 'red',
      width: '100%',
      height: '85%',
    },
    dataControls: {
      flex: 1,
      // backgroundColor: 'green',
      flexDirection: 'row',
    },
  });

  /**
   * @description Verarbeitet den "Edit Button" Klick
   * @author OliverKarger
   * @param {any} itemId Item Index
   */
  function editItemButton(itemId: any) {
    navHook.navigate('Editor', {action: 'edit', itemId: itemId});
  }

  /**
   * @description Report Area Funktion
   * @author OliverKarger
   * @return {React.FC}
   */
  function reportArea(): JSX.Element {
    return (
      <View style={style.dataList}>
        <ScrollView>
          <DataTable
            editItemButton={editItemButton}
            data={data}
            style={{flex: 1}}
          />
        </ScrollView>
      </View>
    );
  }
  return (
    <Screen style={style.container}>

      <ReportStack.Navigator initialRouteName='create'>
        <ReportStack.Screen name='reportarea' component={reportArea} />
        <ReportStack.Screen name='create' component={EditorCreate} />
      </ReportStack.Navigator>
    </Screen>
  );
}

Code of the Main Navigator:
import {EditorScreen, HomeScreen, ReportScreen} from './screens';

import {Header} from './components';
import Icon from 'react-native-vector-icons/AntDesign';
import {NavigationContainer} from '@react-navigation/native';
import React from 'react';
import {SafeAreaView} from 'react-native-safe-area-context';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {createNativeStackNavigator} from '@react-navigation/native-stack';

// import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';

// import {createNativeStackNavigator} from '@react-navigation/native-stack';

const Tab = createBottomTabNavigator();

/**
 * @description Haupt Klasse, enthält primären App Code
 * @return {React.FC}
 */
export default function App() {

  Icon.loadFont();
  return (
    <SafeAreaView style={{flex: 1, marginTop: '15%'}}>
      <NavigationContainer>
        <Tab.Navigator
          screenOptions={({route}) => ({
            tabBarIcon: ({focused, color, size}) => {
              const iconName: string = '';
              if (route.name === 'Home') {
                if (focused) {
                  return <Icon name='home' size={28} />;
                } else {
                  return <Icon name='user' size={28} />;
                }
              }
              if (route.name === 'Report') {
                if (focused) {
                  return <Icon name='folderopen' size={28} />;
                } else {
                  return <Icon name='folder1' size={28} />;
                }
              }
              return <Icon name={iconName} size={28} />;
            },
            headerShown: false,
          })}
          initialRouteName='Home'>
          <Tab.Screen name='Home' component={HomeScreen} />
          <Tab.Screen
            name='Report'
            options={{title: 'Übersicht'}}
            component={ReportScreen}
          />
        </Tab.Navigator>
      </NavigationContainer>
    </SafeAreaView>
  );
}

Can anyone help me with this?
Greetings,
Oliver
Answer: For anyone with the same problems, see: https://github.com/react-navigation/react-navigation/issues/3333#issuecomment-359740246
The problem was that the parent container had alignItems: 'center' as a style attribute assigned, which was causing the issue.


Image is not showing in django template but other tag is working

Question: I am trying to show up my image in django template. But the image is not showing. There is a headline tag which is working fine. I don't know where I am stuck. I searched it here and got a lot of solution, but none of this are not solving my issue.
Here is my views.py:
from django.shortcuts import render
from .models import Post
from django.utils import timezone

# Create your views here.
def home(request):
    posts = Post.objects.order_by('id')

    return render(request, 'home.html')

Here is my urls.py:
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

from Picture import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.home, name='home')
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

And this is home.html:
{% load static %}

    <title>Home Page</title>
    <meta charset='utf-8'>

{{ posts.title }}

Images are in the media directory. Please help me to fix my problem.
Comment: @Sharif, I think you should help us help you. If you paste your code and make us go from one site to other it's kind of unfare!... Please copy the important parts of your code in your question. Then you'll probably receive answers more quickly!.
Comment: Is it only your image not showing or everything else?
Comment: @BidhanMajhi only image not showing
Answer: I see two problems with your code

return render(request, 'home.html') does not have posts context parameter
In your template file posts object is likely to be a queryset, you need to loop through it to render its properties

def home(request):
    posts = Post.objects.order_by('id')
    return render(request, 'home.html', {"posts":posts})

Comment: I have changes the template and view file. But still the image are not showing.
Template file is:
`
 {% for post in posts %}
  {{ post.title }}

 {% endfor %}
`


awkward stretchy fingering

Question: In bar 4 http://jonaslefvert.com/wp-content/uploads/2016/03/The-Piano-The-Heart-Asks-Pleasure-First.pdf
there is a chord arpeggiated across these frets x35503 (capo on 5)
here is a video of Jonas Lefvert playing it

I find it really really hard to reach and hold all those notes at once (I can do it, but it's not easy at all and I can't effortlessly transition into it, it would be impossible to play it in the song)
How come Jonas Lefvert can play that so smoothly and easily?
How can I do it too/what should I do instead? (maybe there's an alternative way to arrange that bar so that I can avoid a fingering I can't reach easily)
Comment: Practice, practice, practice....  In the cirque du soleil you'll find people who can sit on their own heads.  It doesn't happen overnight, you just have to keep pushing.
Comment: "How come Jonas Lefvert can play that so smoothly"  1000 - 2000 hours practice per year for 10, 20 years
Answer: With enough practice, it's doable in that position, even if you don't have huge hands or very long fingers. You could practice it first in an even higher position, and then work your way down to the correct position.
As a last resort, you could exchange fingers 1 and 2, i.e., use the second finger on the A string and the first on the high E string. This is a bit unconventional, but the end justifies the means ...
Comment: When I swap them my second and third finger are too close to the ends of their frets
Comment: @theonlygusti: You have to twist your hand accordingly. For the original fingering you turn your wrist clockwise, for the alternative fingering anti-clockwise.
Answer: This answer won't probably please you too much, but I think there is only one way: Do it. Then do it again. Then again. Then again. Then again. And so on.
The left hand just needs to get used to the fact that it has to stretch sometimes. For example: when I was a child just starting with the guitar, the standard G major chord shape was a total nightmare for me. I couldn't put the fingers across the whole fretboard, or if I could, I muted all the strings in between. But eventually the hand just got used to the fact that it has to play this thing, and after some time it posed no problem at all. And if you're anything like me, you will probably remember a similar episode from when you were going through the absolute basics.
To continue: many years passed, I switched to classical guitar, and more than 10 years after these first steps, I was learning Torroba's Sonatina (a famous piece of classical guitar repertoire). There is one particular stretch (x632xx in your notation, no capo) that just stunned me. When I saw it first, I just thought "WTF? This is unplayable!!" Then I tried it a lot of times. When I got the rest of the movement right and this awful stretch was the last thing standing, I just went through the whole movement over and over again, always trying to get that stretch as fast as I can. That resulted in big pauses in that place, and then the pauses grew shorter and shorter, and now I just play it seamlessly and don't give it a second thought.
So — just do it over and over again, the hand gets used to it. Play it a lot in the context (with a couple of bars around the problematic moment), and allow yourself a pause to get it right. The pauses will eventually vanish. (However some people will oppose this method, saying that you will instead learn the piece with the pause and never play it right. And that probably can happen, though it never happened to me — so maybe take this with a grain of salt.)
(BUT 1) don't go forcibly through any pain and 2) be sure that you treat 1-2 very hard places like this. If you allow yourself pauses all over the place, then just go and pick something easier!)
P. S.: As correctly noted in the other answer, the chord is perfectly playable. (It's playable even if you remove the capo and shift it 5 frets down.) So although there are various ways to work around very hard places, I would recommend you not to use them. (After all, if you don't take any challenges, you never improve!)

awkward stretchy fingering


IPTABLES: routing VPN users through transparent Squid

Question: I'm hoping someone can help me out - I've been tearing my hair out over this!
I have pptpd and squid set up.  I want give these users access to the internet, but would like to send http traffic through a squid proxy.
Hopefully this rough diagram will give you an idea of what I'm trying to achieve:
VPN users connect to pptpd (via eth0)
    \ | /
      |
      |
     / \
 http   everything else
   |     |
   |     |
   |     |
squid    |
   |     |
    \   /
     \ /
      |
     NAT
      |
  internet  (via eth0)

If I set up the following iptables rule, users can connect to the internet:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

I can also connect to squid directly and it works as expected.
Now, I was hoping another simple rule would redirect all http traffic through squid:
iptables -t nat -A PREROUTING -i ppp+ -p tcp --dport 80 -j REDIRECT --to-port 3128

But this doesn't seem to work (I'm also hoping ppp+ is the correct formatting for a wildcard).  Http traffic is never redirected and bypasses the proxy.
Can anyone suggest how to get this working?
I don't really know much about this stuff I'm afraid.  I would also love some recommendations for ways in which I can debug the system, e.g. which log files to look at, tcpdump commands etc.  I find the iptables documentation extremely bewildering!
Thanks!
Answer: Your rule is correct, you need to check if it is actually being matched.
iptables -t nat -vnL

Comment: Apologies, it was in fact working!  I was just being stupid.


using curl get string and find specific value from string

Question: In this code, the value of $new_el[0] should be changed from what we get in the server response. I want the code to function such that if the value that comes from the server is  $new_el[0]=0; then the value of $new_el[0]="CJ"; and if the value that comes from the server is $new_el[0]=1; then the value of $new_el[0]=01; So basically, a 0 is add before every single digit, such as 01,02,03 (except for the case of $new_el[0] = 0).
  function curlUsingGet($url, $data)
   {

if(empty($url) OR empty($data))
{
    return 'Error: invalid Url or Data';
}

$fields_string = '';
foreach($data as $key=>$value) { $fields_string .= $key.'='.urlencode($value).'&'; }
rtrim($fields_string,'&');

$urlStringData = $url.'?'.$fields_string;
$_SESSION['urlStringData']=$urlStringData;
 $cookie= "cookie.txt";
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,0);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_COOKIESESSION,true);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_FRESH_CONNECT,true);
curl_setopt($ch, CURLOPT_URL,$urlStringData);

$return = curl_exec($ch);

$arrel = explode('|',$return);

foreach($arrel as $val)
{

$new_el=explode('~',$val);

  echo $new_el[0];
  echo $new_el[1];

}

curl_close($ch);
}

$data = array('u' =>$_SESSION['councel']);
echo curlUsingGet('http://"url":8080/causelist/CauseListData',$data);

Comment: Do you have a specific question?
Answer: You can pad the number with 0's using sprintf. Try something like this as a starting point.
$new_el[0] = ($new_el[0] == 0) ? 'CJ' : sprintf("%02d", $new_el[0]);


How to read cookies of an application from a rails gem

Question: I wrote a gem which will read the cookies of an application that installs my gem. But, I am not able to do that because when I try to add the line cookies[:name], it is throwing the exception undefined method "cookies".
How to achieve this? Your help is appreciated.
Comment: You can only access `cookies` in the controller or view.  You need to add more info about your problem, eg where you are trying to access `cookies`.
Comment: I am trying to access the browser cookies from the gem
Comment: Cookies are only available when building a response or after receiving a request: ultimately you are just reading request headers and setting response headers. Outside of the context of the controller (which receives requests and makes responses), cookies are therefore not available.  If your gem has modules which are to be included in the controller then they may be able to access them.  But if it is effectively more "model" logic then it won't be able to access the cookies.
Answer: First of all, applications don't store cookies, only browsers do. That said, you can access those cookies from your controllers. See the documentation on cookies here: http://guides.rubyonrails.org/action_controller_overview.html#cookies
Your question is kind of vague. You might have to share some code to get a quality answer.


how many 2s and 3s sum to make 15, if there are can only be 6 2s and 3s

Question: i was watching a basketball game. a player had scored 15 points. he did this with exactly 6 shots. the shots could only be of 2 or 3 points. i worked out intuitively that he had to shoot 3 3 point shots and 3 2 point shots to get 15 points.
but what would the proper approach be? is there a correct method for this type of thing?
Comment: $x+y=6$ and $3x+2y = 15$
Comment: linear equations
Answer: Your first paragraph represents a typical algebraic problem in which you are required to translate word problems from English into mathematical expressions and equations. In the first two sentences, you are given a constraint. The constraint is that the basketball player must score $15$ points with $6$ shots. The shots can take two distinct values - either the basketball player scores $2$ points or the basketball player scores $3$ points.
To rewrite this information into algebraic equations, we can define two variables. Let
$$x=\text{number of 2 point shots}$$
$$y=\text{number of 3 point shots}$$
from our constraint we know that the total number of shots is $6$. Therefore
$$x+y=6$$
and as you are also given that the basketball player scored $15$ points you may conclude this point total is a linear combination of the number of two point shots and the number of three point shots. As a two point shot has a point total of $2$ and a three point shot has a point total of $3$, we see that our second equation is
$$3x+2y = 15$$
We can then rewrite the first equation as $y=6-x$. Substituting this into the second equation forms
$$3x+2(6-x) = 15\implies x+12=15 \implies x=3$$
therefore
$$3+y=6 \implies y=3$$
so we may conclude that the basketball player took three $2$ point shots and three $3$ point shots in order to score $15$ points.
Comment: 5 three point shots is an alternate solution if you say within means in less than or equal to.
Comment: thank-you for this, very helpful. and i did mean 6 exact shots. out of curiosity how would the line `x+y=6` change if the constraint was now within 6 shots. would it be `x+y<=6` but how would you then do the substitution/algebraic manipulations?
Comment: Then you would need to solve
$$x+y <= 6\tag{1}$$
$$2x+3y = 15\tag{2}$$
I would first rewrite equation $(2)$ as $y=\dfrac13(15-2x)$. Inserting this new equation into $(1)$ and simplifying produces $x \le 3$. So, we know that $0\le x \le 3$. We could also go back to equation $(2)$ and solve for $x$. This produces $x = -\dfrac32 (y - 5)$. Substituting this into $(1)$ and simplifying produces $y \ge 3$. So, we know that $3\le y \le 5$ (since $3\times 5= 15$). From here, I would test the values of $x$ where $0\le x \le 3$ and $y$ where $3\le y \le 5$.


Is continuity characteristic required for two equations to be equal

Question: The function below is discontinuous:
$$
f(x)=\frac{x^2-9}{x-3}
$$
But when it is further simplified, it becomes continuous:
$$
g(x)=x+3
$$
First question, is $f(x) = g(x)$ ? Second question, if presented with $f(x)$, is it mathematically incorrect to further simplify it?
Comment: Your function is not dicontinuous. It's of course continuous on the definition domain, i.e. on $\mathbb R-\{3\}$. If you define $f$ as $$f(x)=\begin{cases}\frac{x^2-9}{x-3}&x\neq 3\\ 6&x=3\end{cases},$$ then $f$ is continuous on $\mathbb R$, and obviously, $f(x)=g(x)$ on $\mathbb R$.
Answer: Short answer: The function $g$ is a continuous extension of $f$.
I will assume that the domain $D$ satisfies $3\in D$. The functions are not equal at $3$, $f(3)\neq g(3)$, since $f(3)$ is not defined. However $f$ has a removable discontinuity. In this case look at the Riemann extension theorem:

Let $D\subset \mathbb C$ be an open subset of the complex plane, $a\in D$ a point of $D$ and $f(a)$ holomorphic function defined on the set $D\setminus \{a\}$. The following are equivalent:

$f$ is holomorphically extendable over $a$.
$f$ is continuously extendable over $a$
There exists a neighborhood of $a$ on which $f$ is bounded.
$\lim\limits_{z\to a}(z - a) f(z) = 0$

We will trivially prove that our function meets the fourth condition:
$$\lim\limits_{x\to 3}\,(x - 3) \frac{x^2-9}{x-3}=\lim\limits_{x\to 3}x^2-9=3^2-9=0.$$
Now by the Riemann extension theorem we can conclude that $f$ is continuously (even holomorphically) extendable over $3$. And this extension is $g(x)=x+3$.
Comment: Thank you. All posted answers are very helpful and correct answers. I am choosing this one as the most correct as it introduces the concept of Riemann's theorem on how to further explore the subject. Mind blown.
Answer: If the domain is the set of real numbers, no, $f(x) \neq g(x)$. Even though $f$ simplifies to $g$, $f$ is a rational function, and $g$ is a linear function. Because $(x - 3)$ is a factor on both numerator and denominator, $x = 3$ does not belong on the domain of $f$, and it does on the domain of $g$.
If you are graphing $f$ and $g$, they will look almost the same, but for $f$, $x = 3$ is a hole.
This is called a removable discontinuity. See this page from WolframAlpha for more information.
Comment: Simplifying $f$ means that we are assuming that $x - 3 \neq 0$, because of the fact that we can't divide by zero. In this case, it is incorrect to simplify $f$ because the domain is the set of real numbers, which includes $3$. However, if you are to take the limit of $f$ as $x$ approaches $3$, then yes, you can simplify it to solve for the limit.
Comment: This answer is consistent to my recent findings with my `TI NSpire CX CAS II` graphing calculator there is indeed a hole. Your statements is also what the `TC7 by Leithold` on page 8. To my 2nd question, is it then mathematically incorrect to simplify `f(x)` further?
Answer: First question. For which $x$? We have something like
$$f : \mathbb R\setminus \{3\} \to \mathbb R\quad\mbox{and}\quad g:\mathbb R\to \mathbb R $$
If you ask if $f(x) = g(x)$ for every $x\in\mathbb R$, then that is false, because $f(3)$ is not defined. You can define $f(3)$ such that the extension is continuous. Just because there is a canonical way to extend $f$, does not mean you can't define $f(3) = 1000$, for instance.
Second question. Not incorrect. By definition of $f$ the quantity $x-3$ is always non-zero. Thus we can simplify.
Title question. Yes, two functions are equal if and only if they have the same domain $X$, same codomain and $f(x) = g(x)$ for every $x\in X$. Thus, if one of them is continuous, so must the other.
The functions $f$ and $g$ are equivalent, because they are equal almost everywhere. But this equivalence need not maintain continuity.
Answer: for the first question :
$\frac{x^2-9}{x-3}$=$x+3$
$x^2-9$ = $(x+3)(x-3)$
$x^2-9$= $x^2-9$
$f(x)$=$g(x)$ $∀ x≠ 3$
Comment: Thanks. The part which confuses me here, is that, `the act of simplification` is being prohibited because it seems there is a need `to retain` or preserve the discontinuity in `f(x)`, which is lost when it is simplified in `g(x)`. Now, I can arbitrarily and easily sprinkle any equation for it to have a denominator of `x-123` and this makes the equation unequal..


Show that $1-\Phi(x)$ is approximately $\varphi(x)/x$ for large $x$ (standard-normal random variable)

Question: Demonstrate that, for a standard normal random variable:
$$1-\Phi(x) \approx \frac{\varphi(x)}x$$
for large values of $x$.
Comment: See http://stats.stackexchange.com/search?tab=votes&q=mills%20ratio for more.
Answer: $1-\Phi(x)=\int_x^\infty \phi(t)\,dt$
$$=\int_x^\infty t^{-1}t\phi(t)\,dt$$
$u = t^{-1} ,  dv =t\phi(t)$  (since $\phi^{'}(t) =t\phi(t)$, $v=-\phi(t)$)
$$=-t^{-1}\phi(t)|_{t=x}^\infty - \int_x^\infty t^{-2}\phi(t)\,dt $$
$$=x^{-1}\phi(x) - \int_x^\infty t^{-2}\phi(t)\,dt $$

So, $1-\Phi(x)=\frac{\phi(x)}{x} - \int_x^\infty t^{-2} \phi(t) \, dt < \frac{\phi(x)} x$  UPPER BOUND

Continuing with integration by parts,
$1-\Phi(x)=\phi(x)/x - \int_x^\infty t^{-2}\phi(t)\,dt$
$$=\phi(x)/x - \int_x^\infty t^{-3}t\phi(t)\,dt$$
$u=t^{-3}, dv = t\phi(t)$
$$=\phi(x)/x - \left[ -t^{-3}\phi(t)|_{t=x}^{\infty}- \int_x^\infty 3\cdot t^{-4} \phi(t) \, dt\right]$$
$$=\phi(x)/x - \left[ x^{-3}\phi(x) - 3\int_x^\infty t^{-4} \phi(t) \, dt\right]$$
$$=\phi(x)/x - x^{-3}\phi(x) + 3\int_x^\infty t^{-4}\phi(t) \, dt$$

So, $1-\Phi(x)=\frac{\phi(x)}{x} - \frac{\phi(x)}{x^3} + 3\int_x^\infty t^{-4} \phi(t) \, dt > \frac{\phi(x)}{x} - \frac{\phi(x)}{x^3}$  LOWER BOUND

Thus,
$$\frac{\phi(x)} x - \frac{\phi(x)}{x^3} < 1 - \Phi(x) < \frac{\phi(x)} x$$
$$\frac{\phi(x)} x \left( 1 - \frac{\phi(x)}{x^2} \right) < 1 - \Phi(x) < \frac{\phi(x)} x$$
$$\frac{\phi(x)} x ( 1 - o(x)) < 1 - \Phi(x) < \frac{\phi(x)} x$$
Therefore, by sandwich thrm, $1 - \Phi(x) \approx \frac{\phi(x)}{x}$ for large $x$.
Answer: Note that
$$x \left(1-\Phi(x) \right) \to 0, \quad \text{as}\quad x \to \infty$$
because the expectation exists. Applying L'Hopital's rule twice, we then get
\begin{align} \lim_{x\to\infty} \frac{x \left(1-\Phi(x) \right)}{\phi(x)} &= \lim_{x\to\infty} \frac{ 1-\Phi(x) - x \phi(x)}{-x\phi(x)} \\ &= 1 - \lim_{x\to \infty}\frac{1-\Phi(x)}{x \phi(x)} \\ & = 1 - \lim_{x \to \infty} \frac{-\phi(x)}{ \phi(x) -x^2 \phi(x)} \\ & = 1 + \lim_{x\to \infty} \frac{1}{1-x^2} \\ & =1  \end{align}
where we have used that $\phi^{\prime} (x) = -x \phi(x)$. Hence
$$1-\Phi(x)  \sim \frac{\phi(x)}{x}$$
(their ratio goes to 1 for large values of $x$)


Digest value mismatch

Question: I'm using xades4j to crate a XAdES-T enveloped signature for an XML file. When I'm verifying the signed XML I get an error saying "Digest value computed does not match the digest value within the ds:Reference" where the reference points to the element of Type="http://uri.etsi.org/01903#SignedProperties". The digest value of the root XML element itself is OK.
Has anybody faced with such a problem?
The only thing I could detect is that the signing time is not in the Zulu format but looks like this: 2015-12-14T22:12:12.302+01:00. Is there a way to change its format in the signature?
<ds:Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#xmldsig-795a7c1b-9b15-4d5f-b363-4cb106ca238b-signedprops">
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<ds:DigestValue>iJu8ShMAGXPF1tmQveXzHkrmpFgfUR1ByH6en+2eIhU=</ds:DigestValue>
...
<xades:SignedProperties Id="xmldsig-795a7c1b-9b15-4d5f-b363-4cb106ca238b-signedprops"><xades:SignedSignatureProperties><xades:SigningTime>2015-12-14T22:12:12.302+01:00</xades:SigningTime>
...

Answer: Problems solved:

You can change the timezone of the signing time by as follows:
    XadesSigner signer = new XadesTSigningProfile(keyingDataProvider)
                            .withSignaturePropertiesProvider(new SignaturePropertiesProvider()
    {
        public void provideProperties(SignaturePropertiesCollector signedPropsCol)
        {
            signedPropsCol.setSigningTime(new SigningTimeProperty(new GregorianCalendar(TimeZone.getTimeZone("Zulu"))));
        }
    })...

The digest mismatch was caused by not setting namespace awareness while reading the XML file:
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);

Digest value mismatch


Usando array javascript dentro $("tr:contains('"+array+"')")

Question: Tenho 3 funções, para fazer o filtro de intervalo de datas num intervalo de 2.
É assim, eu tenho uma data de inicio e outra de fim, e dentro dessas duas datas ele procura numa table dentro de suas trs e tds as tais datas que estarão nesse intervalo.
As funções usadas para fazer esse intervalo (que é gurdado num array):
<code>// prototype of dates
Date.prototype.addDays = function(days) {
    var dat = new Date(this.valueOf())
    dat.setDate(dat.getDate() + days);
    return dat;
}

//GET DATES INTERVAL FUNCTION
function getDates(startDate, stopDate) {
    var dateArray = new Array();
    var currentDate = startDate;
    while (currentDate <= stopDate) {
        dateArray.push( new Date (currentDate) )
        currentDate = currentDate.addDays(1);
    }
    return dateArray;
}
</code>
E aqui onde ocorre o change que disparada essas funções e dentro dela eu quero que procure esse intervalo de datas que eu preciso:
<code>$("#start").keydown(function(event) {

        var d1 = new Date($(this).val());
        var d2 = new Date($("#end").val());

        console.log(getDates(d1,d2));
    });

    $("#end").keydown(function(event) {

        var d1 = new Date($("#start").val());
        var d2 = new Date($(this).val());

        console.log(getDates(d1,d2));
    });
</code>
Comment: Qual é sua pergunta?
Comment: olá @FabioWilliamConceição, pode compartilhar conosco como resolveu? assim no futuro alguém pode se ajudado com sua pergunta.
Comment: Já resolvi, obrigado.
Comment: Postei a solução
Answer: Solução:
<code>//GET DATES INTERVAL FUNCTION
function getDates(startDate, stopDate) {
var dateArray = new Array();

var currentDate = startDate;

while (currentDate <= stopDate) {

  var newDate = currentDate;

  var res = newDate.toString().split('-');

  res = res[0].toString().split(' ');
  res = res[2] + '/' + monthToNumber(res[1]) + '/' + res[3];

  dateArray.push( res );

  currentDate = currentDate.addDays(1);

}

return dateArray;
}

$("#start").keydown(function(event) {

    var d1 = new Date($(this).val());

    var d2 = new Date($("#end").val());

    console.log(getDates(d1,d2));

});

$("#end").keydown(function(event) {

    var d1 = new Date($("#start").val());
    var d2 = new Date($(this).val());

    console.log(getDates(d1,d2));

});
</code>


R: Análise espacial com spatstat, barra lateral não não mostra valores corretos

Question: estou tentando criar um mapa com o pacote spatstat do R de forma que a barra lateral mostre os valores da terceira (de preferência) ou quarta coluna do meu data frame e que as cores tmb sejam reflexo dessa terceira (ou quarta coluna) escolhida.
Meu script:
#dados

x=c(6.839887, 6.671494, 6.651083, 6.655289, 6.591903, 6.653641, 6.661709, 6.671664, 6.660044, 6.624659, 6.648162, 6.536877, 6.654134, 6.674678,6.618935, 6.677705, 6.643918, 6.644119, 6.670517, 6.583619, 6.649991, 6.647649, 6.656308, 6.645772, 6.648740, 6.643103, 6.652199, 6.666641,6.633400, 6.621282, 6.635427, 6.646127, 6.630862, 6.657919, 6.671616, 6.622935, 6.648225, 6.676911, 6.640234, 6.719334, 6.653202, 6.656747,6.724692, 6.639747, 6.630575, 6.657916, 6.618957, 6.640006, 6.645280, 6.614058, 6.576136, 6.631994, 6.617391, 6.782351, 6.620072, 6.661061,6.597216, 6.648755, 6.618436, 6.659507, 6.653993, 6.663255, 6.630893, 6.656322, 6.617265, 6.649022, 6.629346, 6.595224, 6.540263, 6.623435,6.652709, 6.608565, 6.618335, 6.645100, 6.790914, 6.643620, 6.462808, 6.680115, 6.716004, 6.668781, 6.765199, 6.674251, 6.647542, 6.724564,6.724556)

y=c(17.16749, 17.16727, 17.16678, 17.16673, 17.16813, 17.16663, 17.16652, 17.16636, 17.16629, 17.16856, 17.16521, 17.16519, 17.17002, 17.16465,17.17015, 17.16407, 17.16356, 17.17122, 17.16334, 17.17152, 17.16282, 17.16278, 17.16272, 17.17257, 17.16198, 17.17279, 17.16169, 17.16161,17.16146, 17.17352, 17.17389, 17.16076, 17.17420, 17.16046, 17.15917, 17.17571, 17.15895, 17.15881, 17.15860, 17.15827, 17.15797, 17.15776,17.17761, 17.15664, 17.15622, 17.15610, 17.15571, 17.15561, 17.15527,17.15514, 17.15494, 17.15447, 17.15438, 17.18041, 17.18053, 17.15402,17.18090, 17.15384, 17.18121, 17.15355, 17.15352, 17.15349, 17.18213,17.15242, 17.15201, 17.14978, 17.18591, 17.18688, 17.18707, 17.18761,17.14712, 17.18788, 17.18794, 17.14619, 17.18868, 17.14588, 17.14511,17.14471, 17.14440, 17.14430, 17.19116, 17.19140, 17.14222, 17.14123,17.33627)

z=c(32.23228,526.46061, -1300.03539, -376.04329, 139.67322,-913.24800,  -526.46061, 354.55511, 483.48424, 161.16141, 182.64960, 419.0196, 75.20866, -225.62598, -1536.40546, -397.53148, -1106.64169,  -440.50786, 118.18504,-290.09054, -1471.94089, 440.50786,-848.78343, -1385.98814, -676.87793, -1622.35821, -1450.45271,75.20866, -1557.89365, 161.16141, 376.04329, 354.55511, -32.23228,-1171.10626,-75.20866, 547.94880, -805.80706, 870.27162, -698.36612,-32.23228, -2331.46842,  -182.64960, 75.20866, -719.85431,-1837.24009,913.24800, -1106.64169, 698.36612, 483.48424, -676.87793, -3019.09045, 891.75981, 1106.64169, 333.06692, -913.24800,333.06692, 934.73619, 354.55511, 75.20866, -891.75981, -247.11416, -1966.16922, 139.67322, -784.31887, -569.43699, -118.18504,-440.50786, 397.53148, -655.38974, 139.67322, 53.72047, -633.90155,-633.90155, 419.01967, -547.94880, 75.20866, 569.43699, 290.09054, -376.04329, 547.94880, 75.20866, -10.74409, 182.64960,-397.53148, -479.53833 )

w=c(96326.91, 96769.46, 95127.94, 95960.41, 96423.22, 95476.93, 95825.18,96615.67, 96731.03, 96442.47, 96461.73, 96673.36, 96365.44, 96095.53,94914.31, 95941.10, 95302.53, 95902.47, 96403.96, 96037.64, 94972.60,96692.58, 95535.03, 95050.29, 95689.84, 94836.56, 94992.03, 96365.44,94894.87, 96442.47, 96634.90, 96615.67, 96269.09, 95244.36, 96230.54,96788.68, 95573.74, 97076.62, 95670.50, 96269.09, 94193.69, 96134.12,96365.44, 95651.15, 94642.01, 97114.98, 95302.53, 96923.12, 96731.03,95689.84, 93567.91, 97095.80, 97287.46, 96596.43, 95476.93, 96596.43,97134.15, 96615.67, 96365.44, 95496.30, 96076.24, 94525.17, 96423.22,95593.10, 95786.52, 96191.98, 95902.47, 96654.13, 95709.18, 96423.22,96346.17, 95728.52, 95728.52, 96673.36, 95805.85, 96365.44, 96807.89,96557.96, 95960.41, 96788.68, 96365.44, 96288.37, 96461.73,95941.10, 99451.20)

shap.lo=data.frame(x,y,z,w)

library(spatstat)
shap.lo.win <- owin(range(shap.lo[,1]), range(shap.lo[,2]))
centroid.owin(shap.lo.win) ; area.owin(shap.lo.win)

shap.lo.ppp <- as.ppp(shap.lo[,c(1,2,3)], shap.lo.win) # fazendo um objeto ppp

plot(density(shap.lo.ppp,0.02), col=topo.colors(25), main='', xlab='x',
     ylab='y')

points(x, y)

O resultado é a imagem abaixo:

Gostaria de saber dos amigos pq a barra lateral mostra valores diferentes daqueles mostrados na terceira coluna do meu data frame, ou seja, além de não exibir nenhum valor negativo mostra valores muito maiores do que aqueles contidos na terceira coluna.
É possível fazer isso, isto é, fazer com que as cores e a barra lateral representem a terceira ou a quarta coluna do data frame ?
Agradeço a ajuda de todos!
Comment: Com esse código, a quarta coluna deve ser difícil, `as.ppp(shap.lo[,c(1,2,3)], etc)` só usa as três primeiras colunas. (E já agora, `shap.lo[, 1:3]` é a mesma coisa e é mais simples e legível.)
Comment: também n vai amigo... perceba que no exemplo utilizo a terceira coluna e os valores são muito acima
Comment: Se calhar não. O que está a utilizar é a densidade, não os dados. Experimente `dns <- density(shap.lo.ppp,0.02); str(dns)` para ver o que está no gráfico.
Comment: Os valores que tem estão no intervalo `range(dns$v)`.
Comment: ahh, entendi. então não existem maneira de fazer com que essas cores e barra lateral mostre os valores da terceira ou quarta coluna ?
Comment: Não, creio que não. Nunca usei esse pacote mas se quer a densidade então os valores serão sempre diferentes.
Answer: Má Notícia
A barra lateral está mostrando os dados corretos. A função
plot(density(shap.lo.ppp,0.02), col=topo.colors(25), main='', xlab='x',
  ylab='y')

está plotando a densidade gaussiana estimada para shap.lo.ppp. Por definição, uma função densidade não possui valores negativos. Além disso, a integral dela sobre o domínio considerado deve ser igual a 1. Por isso, para que o volume desta superfície que aparece no gráfico seja iguala 1, é necessário que alguns pontos sejam picos bem altos, maiores do que 20000.
Esta é a razão para a tua escala começar em zero e terminar em um valor bem acima do esperado por ti.
Boa Notícia
Felizmente, é possível enganar o R para ele plotar exatamente o que tu deseja. Em primeiro lugar, vou estimar a densidade destes pontos do teu problema:
densidade <- density(shap.lo.ppp, 0.02)

Com isto feito, vou calcular o mínimo e o máximo de v, o objeto que possui os valores da densidade estimada:
min(densidade$v)
[1] 1.826526e-12
max(densidade$v)
[1] 23782.84

Ou seja, são zero e mais de 20000, como suspeitávamos. Os valores mínimos e máximos da escala que te interessam são dados por
min(shap.lo.ppp$marks)
[1] -3019.09
max(shap.lo.ppp$marks)
[1] 1106.642

Se definirmos que o mínimo (0) da densidade vale -3019.09 e seu máximo (23782.84) vale 1106.642, basta fazer uma interpolação linear nos valores intermediários de densidade$v para transformar a escala naquela que queremos. Escrevi uma função para fazer isto automaticamente:
conversao_densidade <- function(densidade, shap.lo){
  # razao entre as amplitudes
  razao     <- (max(densidade$v)-min(densidade$v))/(max(shap.lo$z)-min(shap.lo$z))

  # deslocamento para o valor minimo
  conversao <- densidade$v/razao+min(shap.lo$z)

  # resultado
  return(conversao)
}

Agora é só substituir densidade$v pelos valores interpolados e fazer um novo gráfico, desta vez com a escala desejada:
densidade$v <- conversao_densidade(densidade, shap.lo)

plot(densidade, col=topo.colors(25), main='', xlab='x',
 ylab='y')

Comment: Obrigado Marcos, realmente a barra lateral agora mostra os valores da coluna que eu pretendia, muito agradecido. Porém ainda há um desacordo entre os valores de `shap.lo$z` e as cores correspondentes. Por exemplo, o ponto
 `x =6.6334 ; y=17.16146  ; z = -1557.894 ; w=94894.87`
localiza-se no gráfico entre as cores amarelas e a bege, isto é, cores que indicam valores mais positivos ( [figura](https://ibb.co/khgD9H) ), sendo que o valor de `z = -1557.894`. Alguma sugestão de como solucionar ?
Comment: Isto não pode ser feito através da densidade. Como escrevi acima, a função `density ` vai te dar a _densidade gaussiana estimada_ para `shap.lo.ppp`. Portanto, a altura de alguns pontos vai ser aproximada por esta estimativa. Não é um problema que precisa ser solucionado.


Convexity of linear regression

Question: I know that linear regression leads to a convex optimization problem. I'd like to visually show this with a simple example. Assume that there are two parameters (x and y) and a single data point <1, 1> with 2 as the y value (no intercept term. Then the cost function becomes
$$ (x+y-2)^2 $$
However if you plot this function you will get the figure

which contains more than one minimal point.
Where is the problem in this example?
Thanks
Answer: 2 parameters and a single data point is not strictly convex because the rank of the matrix of observations and predictors is deficient. Indeed, as you observe, there is a line of many "equally good" solutions, and this is because for any choice of $x$ there is a corresponding $y$ which achieves the minimum: how many points satisfy $x+y=2$?
Add more observations than predictors and the problem is (strictly) convex.
Comment: 2 parameters and a single data point is convex, but not strictly convex, and the global minimum is not unique. It is not "not convex".
Comment: @MarkL.Stone Yes, thanks, it always trips me up when "X" and "not X" don't quite exactly behave the way I might expect.
Comment: "more observations than predictors" exactly, thanks
Comment: i.e., it is weakly convex
Answer: $$(x+y-2)^2=0$$
$$x+y=2$$
$$y=2-x$$
You can pick any $x$, and get a corresponding $y$, i.e. there's no unique solution. With two unknowns and one observation, there's not going to be a unique solution

Convexity of linear regression


String obtained from ResultSet does not match normally defined String of the same content

Question: I have a simulation for a hospital management system. Accompanying that is an Azure SQL server to store log information and the user access levels within the system (referred to as variable access in the authorize() method.)
I connect to the database server, use a prepared statement to find a specific record in my employee table, and retrieve a specific column which, in this specific instance, is a string containing Doctor.
In my main() method I save the return statement of the authorize function as String auth, which I use to compare to another string Doctor in an if statement. I even have the system print what is contained in auth, which always returns "Doctor". Yet the if statement is never executed.
How can I resolve this?
public static void main(String args[]) throws SQLException
{
    connect();
    String auth = (authorize(1083, "pass"));
    System.out.println("The authentication string is: " + auth);
    System.out.println("\nTesting to see if authentication String matches: Doctor");
    if(auth.toString().equals("Doctor"))
    {
        System.out.println("Authentication string matches!");
    }
    else System.out.println("Authenication String does not match!");
    close();
}

public static void connect()
{
    //buffer.connect();
    try
    {
        String server = "jdbc:sqlserver://hospital-mangement.database.windows.net:1433;database=Hospital-Mangement;user=********;password=********;encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
        con = DriverManager.getConnection(server);
        if (con != null) {
            System.out.println("Database connection is successful!");
        }

    } catch (Exception e) {
        error = e.toString();
    }
}

public static String authorize(int ID, String pass) throws SQLException
{
    //connect();
    ResultSet user = null;
    String access = null;
    try
    {
        PreparedStatement stmt = con.prepareStatement("SELECT * FROM Employee WHERE ID = ? AND Password = ?");

        stmt.setInt(1, ID);
        stmt.setString(2, pass);
        user = stmt.executeQuery();
        user.next();
        access = user.getString("Access_Level");
        return access;

    } catch (Exception e) {
        error = e.toString();
    }

    //close();

    return null;
}

Output that I get:
Comment: Maybe whitespace characters? Try auth.toString().Length
Comment: Good tip, I just found it out as you commented. But, doing that would have revealed the issue as well.
Answer: Found out why this was occurring. The Azure server database appended spaces to the end of the strings that I wasn't initially aware of.
Comment: Azure doesn't just add spaces for the fun of it. Probably those spaces are actually stored in the database.
Comment: Probably a fixed length string data type then, unless it's just that particular entry
Comment: I believe it is that. I set a particular length for these variables in the table creation statement. So perhaps Azure is filling up the rest of the unused character length with spaces?


Memory usage behavior of a process after performing free

Question: I have an application for which I am performing memory usage analysis. I am loading the application with some data and the application is such that it caches(stores in form of some hashtables and other data structure, lets say some records) information out of this pumped data. For each record stored in memory, the application allocates memory using malloc/calloc. After certain time, around 80% of these records time out and application frees the memory it had allocated for these records. To keep a check on the memory usage of the application, in the background I ran a script to capture the output of top as well as "free -m" and plotted a graph to see the memory usage of the system as follows. The graph shows the trend seen in the values printed by "free -m" under the row "-/+ buffers/cache" with columns used and free. I was expecting the graph of used to be increasing in the beginning and then decrease as the application frees the memory. But this is not the actual scenario. The RES in output of top also does not decrease. Can some one help me understand the memory dynamics for an application as seen under Linux.
Answer: malloc is a library call. If it has no memory in its own memory pool, it will ask the kernel to associate more memory to the process.
malloc for small buffers will use memory from its own pool and free will return the memory to this pool, without actually releasing it to the system, unless the pool becomes too large.
malloc for large buffers is implemented in a completely different way, will call the kernel and will hence be slower, but when freeing such a buffer, it will be released immediately.
http://linux.die.net/man/3/malloc
Read the notes there.
Answer: If you are certain you do not have a memory leak, this could be due to your allocator holding on to freed memory. There can be multiple reasons for this:

Your allocator may be anticipating that the memory you have freed will be needed again in the future. This is an attempt to reduce the runtime overhead of allocating memory by removing the need for a system call to satisfy the next allocation request.
You may be suffering from memory fragmentation. This means the freed memory resides on pages that still contain objects that have not been freed, so these pages cannot be released back to the system. This makes it appear that your program is occupying more memory than is represented by the memory occupied by the objects still in use.

To see if you are suffering the latter rather than the former, try to allocate an object about half the total size of what was freed back when the 80% was released. If your program grows in size by that amount, it means your freed memory is fragmented.


bit to bit xor with same input vector in vhdl

Question: I want to do bit by bit xor with same input vector like:
input(0) xor input(2) xor input(3) up to input(187).
The answer I get is like:
output(0) downto output (94)
This means I have to do xor successively. If I have 10 input bits, the last answer I get is 5 bit output. Its very difficult and not a good approach to write the whole vector.
Does anyone knows how to write a efficient code of this in vhdl?
I have a idea how to do it. First extract even index bits, then odd index bits and do xor but no luck please help me.
Comment: Can you give some sample data and expected outputs? I'm not sure why `input(1)` is skipped in your example and yet inputs 0,2 and 3 are involved together. And why the result is 95 outputs. Maybe simplify the example and (again) give inputs and expected outputs.
Comment: @sharth - if it's what Garp's suggesting, there are so many fencepost errors *and* typographical errors that if you can devine the original intent, go into fortune telling.
Comment: I guess he means parallel 2-input XOR gates for a long vector input
Comment: @Damien_The_Unbeliever: I imagine that `input(1)` being skipped is a typo.
Comment: Having re-read the question a few more times (it really does need work) - are you trying to compute *parity*?
Comment: See [this previous question](http://stackoverflow.com/questions/20296276/and-all-elements-of-an-n-bit-array-in-vhdl)?
Comment: first i want to extract the values that are on odd index than those that are on even index so if i have std_logic_vector(9 downto 0) it means i have 10 indexes first i want to extract 5 even index values than 5 odd index values than do xor.
Comment: @hassananwar: You're going to need to do what Damien asked 21 hours ago. It's difficult to understand exactly what you are asking for, and a great way to help us understand is to use __examples__.
Answer: It sounds like you need either a generate statement or a for loop.
Concurrent Statement
lots_of_xor: for i in 0 to 94 generate
    output(i) <= input(2*i + 0) xor input(2*i + 1);
end generate;

Sequential Statement
for i in 0 to 94 loop
    output(i) <= input(2*i + 0) xor input(2*i + 1);
end loop;

Notes
In either version, we can replace 94 with output'length as well.
Comment: first i want to extract the values that are on odd index than those that are on even index so if i have std_logic_vector(9 downto 0) it means i have 10 indexes first i want to extract 5 even index values than 5 odd index values than do xor.


Using Nakayama's Lemma to prove isomorphism theorem for finitely generated free modules

Question: Suppose $R \neq 0$ is a commutative ring with $1$. The following is well known:

(Isomorphism Theorem for Finitely Generated Free Modules) [FGFM] $R^{n}\cong R^{m}$ as
  $R$-modules if and only if $n=m$.

One proof of this result (if I recall correctly) was somehow based on the idea that we can quotient out by a maximal ideal of $R$ (whose existence is guaranteed by Zorn's Lemma), and reduce the situation to that of vector spaces. However, I am interested in different approach. Recall

(Nakayama's Lemma) Suppose $M$ is a finitely generated $R$-module, and
  $M=IM$ where $I$ is an ideal contained in Jacobson radical of $R$. Then, $M=0$.

My question is:

Can we prove FGFM using Nakayama's Lemma?

My main motivation in asking this question is two-fold:
1) to see the power and usefulness of Nakayama's Lemma, and
2) to see a nice and short proof of FGFM that does not involve reducing the problem to a result from linear algebra.
I appreciate any input :)
Comment: I think the first move is yours: where do you expect to begin with Nakayama's lemma? Presumably you have something in mind to apply it to. (Or did you just say: "Nakayama's lemma: I like it! Let's try to prove random theorem X with it..."
Comment: @rschwieb: Well, it was probably closer to "Nakayama's lemma: I like it! But let's try to see if we can deduce this particular theorem". I had a hunch that Nakayama would be powerful enough, and I was right :)
Comment: Well what I was getting at is that the connection seemed rather whimsical. For example, you could also say "Can we prove this with the axiom of choice?" Indeed the axiom is *powerful* but that doesn't mean it proves everything. In that case, you would be met with a lot more skepticism. In this case, there turned out to be a connection, but it doesn't have to be that way all the time.
Comment: And yes, I guess that using the Zorn's lemma argument along with bases of vector spaces would be using the axiom of choice (twice) to prove it. But you get the idea. You could say "prove this with the four color theorem" and your question would be closed. I just wondered why you thought there would be a connection.
Comment: @rschwieb Good point. To answer the question of why I thought there would be connection, I will go with intuition and sheer luck. Also, I like to see lemmas in action. I would love to ask a question titled "What are your favourite applications of Nakayama's Lemma?", though not sure if this would be well-received by the community.
Comment: OK, intuition and sheer luck it is :) If I were you, I would try out your "favorite applications" question. There are certainly worse questions sticking around. The worst that could happen is that it gets closed, but you have nothing to lose. Personally, I wouldn't vote to close unless it is a duplicate. Be sure to check the site for a similar question first!
Comment: As for 2), there are lots of proofs which do not use linear algebra over fields, but prove it directly. For example, when $n<m$, then $0 = \Lambda^m R^n$ is not isomorphic to $R \cong \Lambda^m R^m$, hence $R^n$ is not isomorphic to $R^m$.
Comment: I just wanted to say that you can do it directly without using the special case of fields.
Comment: @MartinBrandenburg Dear Martin, thanks for your comment. Unfortunately, I don't have any knowledge of multi-linear algebra. Hoping to learn soon!
Comment: See http://www.math.uconn.edu/~kconrad/blurbs/linmultialg/extmod.pdf for instance.
Answer: Here's one idea. Use the following consequence of Nakayama:

If $M$ is a finitely generated $R$-module and $f\colon M\to M$ is a surjective module homomorphism, then $f$ is an isomorphism.
Proof: View $M$ as an $R[x]$-module, where the action of $x$ on $M$ is given by $f$. By assumption $xM = M$. The proof of Nakayama's lemma then gives that there is some element $P(x)\in R[x]$ such that $(1 - P(x)x)M = 0$. Then for any $m\in M$, $$0 = (1 - P(x)x)m = m - P(f)(f(m))\implies m = P(f)(f(m)).$$ This shows that $P(f)$ is an inverse of $f$.

To use this to prove FGFM, do the following. Suppose $n\geq m$, and that $R^n\cong R^m$. First, fix a basis $e_1,\ldots, e_n$ of $R^n$, and identify $R^m$ with the submodule of $R^n$ generated by $e_1,\ldots, e_m$, so $R^m\subseteq R^n$. Let $\pi\colon R^n\to R^m$ be the projection map. Since by assumption $R^n\cong R^m$, there is some isomorphism $f\colon R^m\to R^n$. But then $\pi\circ f\colon R^m\to R^m$ is surjective, and hence by the result above, is also an isomorphism. However, since $f$ is surjective, the only way that $\pi\circ f$ can be an isomorphism is if $\pi$ is injective. This of course only happens when $n = m$.
Comment: @Prism The result about a f.g. module over a commutative ring is attributed to Vasconcelos. It is also true that a surjective endomorphism of a Noetherian module is injective. You can read about these two things [at this solution](http://math.stackexchange.com/a/239445/29335).
Comment: Yeah, that's one way to do it :) +1 for overcoming my negativity about the connection between the two.
Comment: This is so cute! Thank you very much. I wasn't aware of the particular consequence of Nakayama's Lemma you used above. Do you have a reference for it? Perhaps it appeared as an exercise in some textbook?
Comment: I am going to wait for some time before accepting this as answer, so that it gathers more upvotes, as it surely deserves.
Comment: @rschwieb: That's perfect! Georges's answer in that thread lead to original article by Vasconcelos who proves other cool stuff. Thanks a lot. :)
Comment: @rschwieb: Didn't know the attribution. Interesting answer you link to!
Comment: Sorry for commenting on such an old post! Yet I'm wondering how we can deduce that $\pi$ is injective from the fact that $\pi \circ f$ is an isomorphism and $f$ is surjective? It seems that it is the composition $f \circ \pi$ that we should consider? And in the last sentence, the *of course* part might be not that trivial (at least for me). It is an exercise in A&M, and the discussion on https://mathoverflow.net/questions/136/atiyah-macdonald-exercise-2-11/47846#47846 may be useful. Thank you for your great answer. That really helps a lot!


Como capturar uma exceção de uma função que esta dentro de um try catch?

Question: Tenho esse método assíncrono:
async printForNetwork( device ) {
    try {
        const options = {encoding: "860"};
        const printer = new Printer(device, options);

        device.open( err => {
            if (err)
                return err; // preciso lançar a exception desse erro

            printer.align('CT');
            printer.size(1, 2);
            printer.text('Teste');
            printer.close();
        });

    } catch (e) {
        throw e;
    }
}

Preciso lancar uma exceção caso o atributo err em device.open para tratá-la no catch.
mas se eu fizer um throw dentro de device.open a exceção nao esta sendo capturada.
Comment: Rafael, você não pode fazer o throw e tratar a exceção ao consumir o método, consumindo com then/catch?
Comment: Esse `try catch` não tem sentido, se você apenas vai lanças a exceção, sem nenhum tratamento, não precisa dele
Answer: Talvez isso resolva o seu problema:
async function printForNetwork( device ) {
try {
    // ...

    await Promise.resolve(device.open( err => {
        if (err)
          throw err;

        // ...
    }));

} catch (e) {
    throw e;
}

}


Is it possible to append or merge one or more XFA form-based PDF files together with iText?

Question: I have one PDF file that has an embedded form that is based on XFA (XML) forms.  The first PDF has a table which holds a list of people.  If that table overflows, the subsequent list of people are handled by an addendum page which is also a PDF (XFA based form).  Is it possible to merge all XFA-based PDFs into one PDF using iText?
Comment: I don't know of any software that can "concatenate" interactive PDF forms. The two alternatives I know are (1) flatten the XFA forms (removing all interactivity) and concatenate the contents the same way you concatenate ordinary PDF files, or (2) put the separate XFA forms inside a PDF package (aka portable collection or portfolio).
Answer: @BrunoLowagie Thanks for your response.   Actually, I managed to get iText to concatenate PDF interactive forms to create a custom PDF packet.  Let me explain how I did this.
From using Adobe Acrobat XI Pro, I learned that when the XFA PDF is loaded, I cannot edit the form if I go to Tools->Edit (it gives me the usual warning that this PDF was created by LiveCycle Designer), but when I go to Pages->Extract, then select all pages to be extracted, the whole XFA-based PDF is extracted and converted over to an AcroForms based PDF.  So if I had 25 fields in the XFA-based PDF, it had successfully converted all 25 fields into AcroForm fields. Somehow Adobe Acrobat had to determine the variable names based on the XML structure.  (i.e. xpath)  //form1/Page1/variable1 was converted to acro field name: form1[0].Page1[0].variable1[0].  All visible (editable form) fields were present and aligned (pixel-perfect) as usual.
If I had flattened the XFA PDF, I would again need to place the form fields back on each page, which would be tedious.  By using Pages->Extract->All Pages, it converts everything for me (no flattening needed - flattening which strips all fields also; also no XFA worker lib needed).
However, my PDF packet is static and I would like to repeat the addendum page in case data overflows from the 2nd page.  I know I could have modified the initial XFA to handle this overflow, but the client wants to use the exact page look for the addendum, with headers/footers intact.
I found that I can achieve this by extracting the addendum page separately via Adobe Acrobat Pro->Pages->Extract->(Select Addendum Page), then it was converted to a PDF form w/AcroForm intact.
I took the original PDF packet and attempted to concatenated the addendum PDF page. So for the moment, the main packet has AcroForm fields and the Addendum PDF page also has AcroForm fields.
When I used PdfCopy or PdfConcatenate to do the concatenation, I noticed that I lost all form fields when I called form.getFields()
When I used the (deprecated) PdfCopyFields to do the concatenation, all AcroForm fields were intact.  (Exactly what I needed!)  I also tested the PdfCopyFields where some fields were filled/saved and the PdfCopyFields still worked & carried over the prefilled values over.  I looked at the reason why PdfCopyFields was marked for deprecation, saying that we can either merge accessible files and lose the forms or merge the forms or lose the accessibility (tagged PDFs).  What if I don't care about tagged PDFs or accessibility?....and still need PDFCopyFields to carry over the form fields intact. So far I'm forced to keep using the PDFCopyFields since it does exactly what I need for PDF concatenation with Interactive Form Fields.  Is it possible to update PDFCopy to have an option to copy over the fields if PDFCopyFields is going away?


Flutter - How do I correctly handle go_router, with redirects and context.pop()

Question: I'm using go_router and trying to handle auth using redirects, so if a user isn't logged in they go to the inviteCode screen. This all works well.
My flow is:
invite screen -> home -> profile
The profile screen has a log out button on it.
My problem is that when the user logs out they return to the inviteCode screen correctly, but if they press the android back button, they end up at the home screen which should only be access when authenticated. (Note the same happens if I add a button with context.pop() onto that original screen)
Here's my GoRouter config
    /// Forwards diagnostic messages to the dart:developer log() API.
    debugLogDiagnostics: true,
    errorBuilder: (context, state) => ErrorPage(state),
    initialLocation: '/',
    redirect: (BuildContext context, GoRouterState state) {
      User user = context.read(userStateProvider);
      if (!user.isLoggedIn) {
        return '/welcome/inviteCode';
      } else {
        return null;
      }
    },

    routes: <RouteBase>[
      GoRoute(
        path: '/',
        builder: (BuildContext context, GoRouterState state) {
          return const HomeScreen();
        },
        routes: <RouteBase>[
          GoRoute(
            path: 'profile',
            builder: (BuildContext context, GoRouterState state) {
              return const ProfileScreen();
            },
          ),
          GoRoute(
            path: 'welcome/inviteCode',
            builder: (BuildContext context, GoRouterState state) {
              return const InviteCodeScreen();
            },
          )
        ],
      ),
    ],
  );

Does anyone know what I should be doing to stop this happening. It feels like a pretty common usage pattern that I'd imagine lots of other apps use with it, but I'm finding the documentation hard to follow/outdated
Comment: So, you don't want the user to be able to go back once it's logged? I don't understand what do you need exactly
Comment: If you log in, go to your profile and log out, I don't want the back button / pop to take you back to the home (ie logged in) main page when you are logged out
Answer: That is the expected behavior based on your routes hierarchy structure. GoRouter uses declarative routing (aka Flutter Navigator 2.0). Navigating to a destination using declarative routing will replace the current stack of "screens" with the stack of "screens" configured to be displayed for the destination route.
On your routes configuration the route with path "welcome/inviteCode" is a child of the route of "/". When you navigate using "go" to "/welcome/inviteCode" it will build the stack of routes bellow:
|- HomeScreen
|  |- InviteCodeScreen

Which means that if you "pop back" from that InviteCodeScreen screen it will show the HomeScreen screen, since it's the page that is "bellow" it in the stack of routes.
If you want you InviteCodeScreen to be a root route, you shall move it up in the routes configuration hierarchy and put it at the same level as HomeScreen:
routes: <RouteBase>[
      GoRoute(
        path: '/',
        builder: (BuildContext context, GoRouterState state) {
          return const HomeScreen();
        },
        routes: <RouteBase>[
          GoRoute(
            path: 'profile',
            builder: (BuildContext context, GoRouterState state) {
              return const ProfileScreen();
            },
          ),
        ],
      ),
      GoRoute(
            path: '/welcome/inviteCode',
            builder: (BuildContext context, GoRouterState state) {
              return const InviteCodeScreen();
            },
          )
    ],

IMPORTANT: The path is now /welcome/inviteCode instead of just welcome/inviteCode since it is no longer a child route of /
Comment: Indeed this key concept is not very clear in the official docs.
Comment: Perfect, thanks for the answer, it really helped me understand some fundamentals that I don't feel the documentation makes clear


how to bind the data from database to the dropdown?

Question: Suppose in .aspx page their is dropdown in which i want to bind two coloumn in that dropdown.for example :-
in database their two column of First_name ,Last_name .I want these two columns value come in a single dropdown using C#.
How to do that? Please tell me.
Answer: If you are using the sql query , try this:
select First_name  + ' ' + Last_name   from table

Then you need to bind it in the Dropdown as normally.
dropdown1.DataSource = datatable;
dropdown1.DataBind();

Comment: SIR it gives error that datatable does not exit in current context.
Comment: @Shalni - that may be because u just copied anishmarokey's code as is in your application. Unless your own objects were named exactly the same, it would give you the error that you are seeing. anishmarokey's suggestion is absolutely spot on but you need to map the object names "table" "datatable" "dropdown1" to whatever you are calling them in your code or else post your actual code atleast
Answer: An alternative to doing it in code would be to drop a SQL data source on the page and configure in the following way.
<asp:sqldatasource id="SqlDataSource1" runat="server"
connectionstring="<%$ ConnectionStrings:MyDatabase %>"
selectcommand="SELECT [ID], [First_name] + ' ' + [Last_name] AS [FullName] FROM [tPerson]"></asp:sqldatasource>

And then your dropdown list control:
<asp:dropdownlist id="ddlPeople" runat="server" datasourceid="SqlDataSource1"
    datatextfield="FullName" datavaluefield="ID" />

This would all go in the asp.net page.


How to interpret / metric Lasso regression coefficients

Question: Edited Question, since it was a duplicate
I used Matlab to make a lasso model for my data that has 41 predictors and 1 response variable, and perhaps I used more variables that I need too or maybe some variables are not meaningful since some regression coefficients are 0.
For the non 0 coefficients, I got some that are 0.2, 0.8, 2.7, etc.
I understood that I can interpret that the higher the regression coefficient higher the importance for that respective variable, is there a Metric or a Rule of thumb that say if a regression coefficient is 10/50/100 times lower than the highest regression coefficient we can "reject" or "not consider" that variable, when implementing the model online? or since it gave a non zero value I should stick with that variable no matter what?
Comment: This issue of feature importance is tricky and is discussed extensively on this site. [This page](https://stats.stackexchange.com/q/202221/28500) has extensive discussion and links to further discussion. As does [this page](https://stats.stackexchange.com/q/202277/28500). Please look over those pages and their links and edit your question to specify any specific statistical issues that are still unclear to you. Also, please edit your question to spell out the meanings of "RR" and "EN" as not all readers will know what you mean by them.
Comment: It's not good, in statistics, to make universal rules for model building. You have to *think* about what you are doing. But you shouldn't reject a variable just because it is non-significant or has a low value.

Model building requires thought.
Comment: I know of no such rule.
Comment: @PeterFlom so if it gave a coefficient > 0, I should stick with that variable, no matter the value?
Answer: You have to think carefully about "importance" of selected predictors and what "p-values" really mean in LASSO.
Predictor importance
Demonstrations of LASSO can be based on a simulated data set with a small number of predictors associated with outcome and a large number that are not. In that context it works well to find the truly important predictors.
But in real-world applications, with multiple predictors that are correlated with each other, the choice of "important" predictors will vary from sample to sample from the same population. The variability in "importance" among predictors you saw among re-samples of your data, and that forms the basis of the stability selection method recommended in the answer by @Edgar, should lead to some questions about what "importance" of individual predictors means when there are multiple correlated predictors related to outcome.
Even when LASSO returns a value of 0 for a predictor's coefficient (as it is designed to do), that doesn't mean it's "not meaningful"; it just means that it didn't add enough to the model to matter for your particular sample and sample size. The predictors that were selected might be important within your particular data sample, but that doesn't mean they are the most important in any fundamental sense in the overall population and they certainly can't be interpreted to have causal effects on outcome.
Your particular approach based on ranking of coefficient values is potentially dangerous, depending on how it is done. Predictors are typically standardized before LASSO so that differences in measurement scales don't differentially affect the penalization of the coefficients. But some software then re-scales the coefficients to the original measurement scales. So at the least you have to be careful about whether  you are ranking coefficients for standardized or for re-scaled predictors. You don't want the importance of a predictor having a length value to differ depending on whether you measured it in millimeters or miles.
LASSO p-values
In many applications, the most important issue with LASSO is how well the model works for prediction. A strength of LASSO is that, even with its potentially unstable selection among correlated predictors, models can work quite well in practice for prediction. In that context, p-values for individual coefficients are of little interest.
It's when you are interested in inference that p-values matter. This is a very difficult problem in LASSO or in any modeling approach that uses outcomes to select predictors. The usual assumptions for estimating p-values in standard regression models no longer hold when you have used the outcomes to select predictors. There has been some work on this in recent years, introduced for example in Chapters 16 and 20 of Computer Age Statistical Inference. Under some assumptions it is possible to estimate p-values, but I think that it's safe to say this is still an area of active research interest. Unless you are willing to get into these issues in depth, it might be best to stay away from p-values for individual coefficients in LASSO.
Comment: About the correlation of predictors: Meinshausen/Bühlmann claim that the subsetting of the sample helps with letting features "shine" even if there correlated with more prominent features for the whole sample. Also, they add a randomized scaling to features in every run because of possibly correlated features, which I didn't explain here.
Comment: @Edgar I agree that, insofar as it makes sense to evaluate importance among predictors in LASSO, the stability selection method is a promising approach. My reason for providing this answer is my fear that the OP or others who come upon this page might not have thought through what feature importance means in practice with multiple correlated predictors.
Comment: Can I ask what is that parameter that you told that should be at least 0.6? is the lasso tuning parameter? or something I should calculate after the model is built?
Answer: If you want to assess the importance of features in the lasso framework, you can use stability selection by Meinshausen/Bühlmann. This means basically that you repeat your lasso $B$ times on a random subset of your data and in every run you check which features are in the top $L$ chosen features. In the end you give a score to every feature how often it was selected in the top $L$ over $B$ runs. The cited paper shows that stability selection is much more stable than simple lasso.
Comment: Yes I run lasso 30 runs, and for each run, I order the absolute value of the regression in a ranking of 1 to 41 (41 predictors) to map it, but I was not certain if it is a good methodology. Not sure if I can perform the calculation of the p-value for the regression coefficients for LAsso
Comment: $B=30$ is probably too low, $B=100$ or even $=500$ should be better. The size of the subsample should be around half of the observations, if you don't have many observations you can choose to subsample some more. $L=5$ is the most common choice, this makes lasso run quite fast.
Comment: Maybe you should intensify your understanding of lasso first before you study more complicated methods that improve on lasso.
Comment: You don't have $p$-values this way, but the stability score should give you a good measure of how important the features are (Meinshausen and Bühlmann say that values above 0.6 are good indicators).

Feel free to mark the answer of your choice as a solution to your problem!
Comment: BTW you should definitely not order by the size of the regression coefficients (as @EdM pointed out, too). You should order by the entrance of features into the model with Lasso (Lasso adds features one by one, with stability selection, you stop after $L=5$ and go on to the next run).
Comment: thanks for the inputs, will try to understand if the stability is something I can analyze in matlab from their built-in functions. thanks
Comment: the parameter that must be at least 0.6 is the π_thr?  or λ (responsible for the regularization factor)?
Comment: $\pi_{thr}$ is the threshold for the stability score. $\alpha$ is the randomization level (in every run you scale features randomly to smaller values, with $\alpha=1$ meaning no randomization and smaller values meaning more randomization). $\lambda$ is the penalty parameter of the lasso regression that determines how many features are included in the model (smaller $\lambda$ meaning more features). As such, $\alpha$ needs to be specified in the beginning, $\lambda$ is a sequence of values that's either provided by you or determined by the implementation, $\pi_{thr}$ is assessed in the end.
Comment: ok, in the paper you provided I didn't get how to perform the π_thr calculation for the model i obtained
Comment: You don't necessarily need to calculate this parameter. Citing the paper: "The threshold value πthr is a tuning parameter whose influence is very small. For sensible values in the range of, say, πthr ∈ (0.6, 0.9), results tend to be very similar."
Comment: now I am confused. So when you told earlier to give a score when X1 is selected for lasso under the 100 runes, you mean a score system of my choosing?
Comment: No. I repeat myself: lasso chooses features one after the other along a decreasing sequence of lambda values. With stability selection, you only consider the first L chosen features (q in the paper). This you do B times. The score for feature x1 is then #{times x1 was in first L features}/B.
Comment: Ok, I don't want to improve lasso. Just wanted something so I could say Variable X1 is important X2 is not, X3 is, etc. I guess i will just make the absolute value of regressors, since its the standard way from the literature for my report, since they were obtianed with standardize data. but thanks for your inputs
Comment: This only works properly if your features aren't correlated, which they most certainly are. Can you give me a reference where it is stated in the literature that it's ok to take the absolute value of the coefficients?


Compact form for the solution of the equation $x^{k+1} =c$, where $c\in\mathbb{R}^+$, $k\in\mathbb{N}$

Question: As an exercise of my mathclass, I need to evaluate the solution of the equation
$$x^{k+1} =c,$$
where $c\in\mathbb{R}, c\ge 0$ and $k\in\mathbb{N}$.
I proceed in this way.
If $k=0$, thus it is just a linear equation and $x=c$ is the only solution.
If $k=1$ it is a quadratic equation $x^2 =c$, which solutions are $x=\pm\sqrt{c}$.
I am in trouble about the cases for $k\ge 2$. I mean, I have to distinguish the cases for $k$ even and odd?
It is possible to find a solution that encloses all the cases for $k$?
Thank you in advance!
Comment: What type of answer are you looking for? It would just be $\sqrt[k+1]{c}$ for odd $k$ and $\pm\sqrt[k+1]{c}$ for even $k$.
Comment: @UNOwen Shouldnt it be the opposite?
Answer: You can use n-th roots of unity:
$$x^n = c \implies x = \sqrt[n]{c} \cdot \sqrt[n]{1}$$
where $\sqrt[n]{1} = e^{i\frac{2k\pi}{n}}$ for $k=0,1,2,...,n-1$ are exactly the n-th roots of unity.
Comment: You can always consider only the real nth roots of unity, namely 1 for odd $n$ and $\pm 1$ for even $n$.
Comment: gibster, I need just real solutions.
Comment: This is a real solution! :)
Comment: @daw I expected something a solution like the comment of UNOwen. It sounds i bit strange to me to involve the $n$-roots of unity.
Comment: @gibster sorry, I missed your comment. So it should be $x=c^{1/(k+1)}$ if $k$ is even and $x=\pm c^{1/(k+1)}$ if $k$ is odd, isn't it?
Comment: yes, since you have a +1.


Is the following inequality true for points in $\mathbb{R}^2$?

Question: For distinct points $(x_1,y_1)$, $(x_2,y_2)$, $(x_3,y_3)$ and $(x_4,y_4)$ in $\mathbb{R}^2$, is the following true?
$$
\big|||(x_1,y_1)-(x_2,y_2)||_2 - ||(x_3,y_3) - (x_4,y_4)||_2\big| \geq
\min \{\big||x_1-x_2|-|x_3-x_4|\big|,
        \big||y_1-y_2|-|y_3-y_4|\big|\},
$$
where $||\cdot||_2$ is the standard Euclidean norm on $\mathbb{R}^2$ and $|\cdot|$ is the standard Euclidean norm on $\mathbb{R}$. I have tried to solve by brute force way but did not get success. I have also tried to get any counter examples but for the points I took, the inequality was satisfied.
Any help in this regard will be much appreciated. Thanks a lot.
Answer: No: a counterexample is $(x_1,y_1)=(0,0)$ and $(x_2,y_2)=(1,0)$ and $(x_3,y_3)=(0,0)$ and $(x_4,y_4)=(0,1)$.
Comment: I am sorry to mention that all the four points are distinct. Please provide me another counterexample.
Comment: That's really not important, since either pair of points can be shifted. Change to $(x_3,y_3)=(900,900)$ and $(x_4,y_4)=(900,901)$ and the counterexample remains the same.
Comment: Thank you very much


UL não segue fluxo normal da pagina

Question: Estou tendo um problema no desenvolvimento de uma pagina especifica do meu site, onde por algum motivo uma Ul está saindo do "fluxo normal", usando as ferramentas de desenvolvedor do chrome deu para verificar que ele sai do body como na imagem abaixo:

Basicamente quero tentar arrumar isso pra fazer o Ul retornar ao fluxo normal, porque qualquer coisa após o Ul aparece por cima da Ul como se ela não estivesse ali.

Codigo HTML da pagina
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edgar Müeller - Home</title>
<link href="estilo/estilo.css" rel="stylesheet" type="text/css" />
<link href="estilo/obras.css" rel="stylesheet" type="text/css" />

<input type="checkbox" id="chec">

Home

Obras +

3D Pavement Art

Evolution

The Caves

The Ark

FAQ

Sobre

Estilo das obras

Contato +

        <form action="?valid=1" id="form1" name="form1" method="post">

Nome*:

<input type="text" name="nome" required placeholder="Nome completo">

E-mail*:

<input type="email" name="email" required placeholder="E-mail para contato">

Empresa:

<input type="text" name="empresa" placeholder="Empresa representada">

Posição:

<input type="text" name="posicao" placeholder="Seu cargo">

Mensagem*:

<textarea name="mensagem" cols="40" rows="8" required placeholder="Sua mensagem"></textarea>

        <input type="submit" value="Enviar" id="enviar">
        </form>

3D PAVEMENT ART

The Crevasse

The Crevasse

The Crevasse

The Crevasse

The Crevasse

The Crevasse

CSS (estilo.css) - nem tudo desse CSS está sendo usado nessa pagina, já que ele é um "geral" pra outras paginas que estão funcionando
/* Formatação padrão */
* {
    margin: 0;
    padding: 0;
}

a {
    text-decoration: none;
    color: black;
}

body {
    font-family: "Agency FB", Arial, SansSerif;
    font-size: 1.4em;
    background-color: #ddd;
    background-image: url("../imagens/The_Crevasse_003.jpg");
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
}

ul {
    list-style: none;
}
footer{
    position: fixed;
    bottom:0;
    left:0;
}

.caixas{
        float: left;
        width: 200px;
        height: 200px;
        border: 10px ridge rgb(100,100,100);
        background-size: cover;
    }
    .caixas{
        border: 10px ridge rgb(200,200,200);
    }

.psobre{
    font-size:1em;
    transition: 0.6s;
}

.psobre:hover{
    font-size:1.2em;
    transition: 0.6s;
}

footer{
    background-color:#bbb;
    width:100%;
    height:50px;
}
/* Inicio do css icone do menu hamburguer */
.container {
    display: inline-block;
    cursor: pointer;
}

.bar1,
.bar2,
.bar3 {
    width: 35px;
    height: 5px;
    background-color: #ddd;
    margin: 6px 0;
    transition: 0.4s;
}

.change .bar1 {
    -webkit-transform: rotate(-45deg) translate(-9px, 6px);
    transform: rotate(-45deg) translate(-9px, 6px);
    background-color: #ddd;
}

.change .bar2 {
    opacity: 0;
}

.change .bar3 {
    -webkit-transform: rotate(45deg) translate(-8px, -8px);
    transform: rotate(45deg) translate(-8px, -8px);
    background-color: #ddd;
}

/* Fim do css do icone do menu hamburguer */

/* Inicio Menu hamburguer */

#chec {
    display: none;
    /* esconde o checkbox */
}

#chec:checked ~ #principal {
    transform: translateX(100%);
    /* Faz o menu aparecer e reaparecer */
}

#chec:checked ~ .bg {
    display: block;
}

#teste{
    height: 120vh;
}

#principal {
    background-color: rgba(110, 110, 110, 0.7);
    /* cor do fundo do menu */
    width: 200px;
    height: 100vh;
    /* unidade base do viewport, pega 100% da pagina */
    left: -200px;
    position: absolute;
    transition: all .4s;
    /* Faz a transição/animação do menu */
}

#obras {
    background-color: rgba(110, 110, 110, 0.7);
    /* cor do fundo do sub-menu */
    height: 100vh;
    /* unidade base do viewport, pega 100% da pagina */
    left: -100%;
    transition: all .4s;
    position: relative;
    /* Faz a transição/animação do menu */
}
#contato {
    background-color: rgba(110, 110, 110, 0.7);
    /* cor do fundo do sub-menu */
    height: 100vh;
    /* unidade base do viewport, pega 100% da pagina */
    left: -100%;
    transition: all .4s;
    position: relative;
    /* Faz a transição/animação do menu */
}

a:not(.ateste) {
    display: block;
    padding: 20px 5px;
    color: white;
}

a:hover:not(.ateste) {
    /* hover do menu */
    background-color: rgb(176, 224, 230);
    color: black;
}
.a {
    display: block;
    padding: 20px 5px;
    color: white;
}

.a:hover {
    /* hover do menu */
    background-color: rgb(176, 224, 230);
    color: black;
}

label {
    padding: 1px;
    margin: 14px;
    position: absolute;
    z-index: 1;
}

ul:not(.ultable) {
    top: 70px;
    position: absolute;
    width: 100%
}

ul li span {
    float: right;
}

.bg {
    width: 100%;
    height: 100vh;
    left: 0;
    top: 0;
    position: fixed;
    background-color: rgba(0, 0, 0, .4);
    display: none;
}
.bg2 { /* escurece a home para destaque */
    position: fixed;
    width: 100%;
    height: 100vh;
    left: 0;
    top: 0;
    position: fixed;
    background-color: rgba(0, 0, 0, .3);
    display: block;
}
#all{
    position: sticky;
    top:0;
    z-index:10;
}

#sub10 #obras {
    top: -70px;
    position: absolute;
    width: 170px;
    pointer-events: none;
}

#sub10:hover #obras {
    left: 100%;
    pointer-events: initial
}

#sub10 {
    overflow: hidden;
    height: 66px;
}

#sub11 #contato {
    top: -70px;
    position: absolute;
    width: 170px;
    pointer-events: none;
}

#sub11:hover #contato {
    left: 100%;
    pointer-events: initial;
    width: 350px;
}

#sub11 {
    overflow: hidden;
    height: 66px;
}

/* inicio do form */
#form1{
    top:90px;
    position: relative;
    left:25px;
    opacity:0;
    transition: all .4s;
}
#sub11:hover #contato #form1{opacity:1;}

.white{
    color: #fff;
}

#enviar{
    font-family: "Agency FB", Arial, SansSerif;
    font-size:1em;
    position:relative;
    top: 50px;
    left:110px;
    background-color: rgb(176, 224, 230);
    color: black;
    padding: 15px;
    padding-right:20px;
    padding-left:20px;
    -webkit-border-radius: 25px;
    border-radius: 25px;
    border: 2px solid #3F8E99;
    transition: all .4s;
    cursor: pointer;
}
#enviar:hover{
    background-color: #3F8E99;
    border-color: rgb(176, 224, 230);
    color: white;
    transition: all .4s;
}

/* fim do form */

/* Fim Menu hamburguer */

/* CSS do conteudo */
#espaco{
    position:relative;
    height: 55px;
}
.conteudo{
    text-align: justify;
    position: relative;
    left: 10%;
    width: 80%;
    -moz-column-count: 2;
    -moz-column-gap: 50px;
    -webkit-column-count: 2;
    -webkit-column-gap: 50px;
    column-count: 2;
    column-gap: 50px;
}
.conteudo2{
    text-align: justify;
    position: relative;
    left: 10%;
    width: 80%;
}
.conteudo p{
    margin-bottom:20px;
}
.titulo{
    margin-bottom: 20px;
    font-size:1.3em;
}

.moldura{
    border: 10px ridge rgb(100,100,100);
}

.estiloimg1{
    width:450px;
    height:auto;
}

.img100{
    width:100%;
    height:auto;
}
/*
#mueller{
    bottom:340px;
    height:auto;
    position: relative;
    opacity:0;
    transition: all .4s;
}
#mueller:hover{
    opacity:1;
    transition: all .4s;
}
*/
/* Inicio do CSS do slide show */
    * {box-sizing:border-box}

/* caixa do Slideshow */
.slideshow-container {
  max-width: 56%;
  position: relative;
  margin: auto;
  border:  7px solid #777;
}

/* Esconde as imagens por padrão*/
.mySlides {
  display: none;
}

/* botão "proximo" e "anterior" */
.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* posição do botão "proximo" */
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

/* Ao passar o mouse, adicione uma cor de fundo preto com um pouco de transparência */
.prev:hover, .next:hover {
  background-color: rgba(50,50,50,0.8);
}

/* texto da legenda */
.text {
  color: #f2f2f2;
  font-size: 0.65em;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* texto dos numeros (1/3 etc) */
.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

/* Os circulos */
.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active, .dot:hover {
  background-color: #717171;
}

/* animação de transição */
.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {opacity: .4}
  to {opacity: 1}
}

@keyframes fade {
  from {opacity: .4}
  to {opacity: 1}
}
/* mudança de cor da legenda */
.legenda{
    color: #111;
}
/* Fim do css do slide show */

/* Inicio do CSS da pag sobre */

.foto{
    background-repeat: no-repeat;
        background-size:cover;
    border: 10px ridge rgb(100,100,100);
    width:180px;
    height:188px;
    background-image: url("../imagens/mueller/Edgar_Mueller.jpg");
    transition: all .4s;
    webkit-transition: all 0.4s;
    -moz-transition: all 0.4s;
    -ms-transition: all 0.4s;
    -o-transition: all 0.4ss;
}
.foto:hover{
    background-repeat: no-repeat;
    background-size:cover;
    border: 10px ridge rgb(100,100,100);
    width:180px;
    height:188px;
    background-image: url("../imagens/mueller/Edgar_Mueller_vetor.fw.png");
    transition: all .4s;
    webkit-transition: all 0.4s;
    -moz-transition: all 0.4s;
    -ms-transition: all 0.4s;
    -o-transition: all 0.4s;
}

/* Fim do CSS da pag sobre */

CSS (obras.css)
/* teste */

    .relative{
        position:relative !important;
    }

.ultable{
    position: relative !important;
    width: 55%;
    height:auto;
    margin-left: auto;
    margin-right: auto;
}

.ProjectLink{
    position:relative !important;
}

    .ProjectLinkContainer .ultable,.ProjectLink{
    position:relative !important;
    list-style: none;
    display: inline;
    float:left;
}

.ateste{
    display:block;
    transition: all 0.4s;
    border-radius: 100%;
    background-image: radial-gradient(rgba(255,255,255,0),rgba(255,255,255,0));
}

.ateste:hover{
    position:relative;
    background-image: radial-gradient(rgba(255,255,255,1),rgba(255,255,255,0));
    border-radius: 100%;
    transition: all 0.4s;
}

    /* teste */

Answer: Cara sem ofensas, eu não sei onde vc estudou, ou se pegou algum material muito antigo como referencia, mas estou aqui te dando uma dica ok! Esquece que float existe. Float não é para construir layout.
Repare na imagem abaixo veja que eu primeiro coloco uma borda no body, ai vc vai ver que tem conteúdo para fora, esse conteúdo que vaza é o conteúdo que está com float. Para corrigir isso eu coloquei overflow:auto no pai, assim o pai reconhece o tamanho dos filhos, mesmo que eles estejam com float. Mas isso é um "hake", não vejo como uma prática, vc pode fazer outras gambiarras do tipo ClearFix. Mas o ideal mesmo é que abandone o float e use o flex.
Resposta: Então para corrigir o problema basta colocar overflow:auto no CSS da

Comment: Pode começar por aqui: https://developer.mozilla.org/pt-BR/docs/Web/CSS/CSS_Flexible_Box_Layout/Conceitos_Basicos_do_Flexbox existe uma infinidade de material sobre isso, tenho certeza que um dia vc vai voltar e agradecer pela dica, float é coisa de década de 90 :D, concentre seus estudos em FlexBox e Grid Layout (Grid https://developer.mozilla.org/pt-BR/docs/Web/CSS/CSS_Grid_Layout/Basic_Concepts_of_Grid_Layout)
Comment: Boa, @hugocsl. Realmente esses float só atrapalham. O float na verdade é para flutuar o elemento para os lados, correto ? Você disse que não é correto usar o float para layout. Então para que utilizamos os floats ?
Comment: Grid é vida xD.
Comment: @JucianoVictor grid vale ouro, o problema é que ele tem muitas variáveis e o povo acaba complicando algo simples, mas realmente grid+flex é melhor que bacon
Comment: @ThiaguinhoEmbasamento float é uma herança maldita desse época http://prntscr.com/pqmam9 repare onde sinalizei com a seta, float é para colocar um elemento "flutuando" e o que está flutuando não está ocupando espaço no "chão". ou seija o que vem abaixo acaba não respeitando o boxmodel do elemento que está com float. Mas tecnicamente, o float é para fazer o flow do conteúdo "contornar" o element, é um recurso tipográfico e não de layout, é para ajustar texto e não blocos de conteúdo. Como tudo a tecnologia tb avança no CSS/HTML, e hj temos o grid e flex que resolve isso de forma muito melhor!
Comment: Valeu cara, mas deixa eu perguntar, o que seria esse flex que você citou?

UL não segue fluxo normal da pagina


How do you determine the best fingering for arpeggios on the piano?

Question: I'm learning Reverie by Debussy. I always hesitate when fingering arpeggios. I can figure it out, but I always feel like there's a better way which I'm not thinking of. Does anyone have any tips for doing this?
Answer: These arpeggios are very irregular, which does not help your case.  If you're not convinced that your ideas for fingering are the best for you, I'd suggest getting a few different editions of the music and seeing what the editors suggest.  IMSLP has 2 editions freely available online here; the score submitted by Feldmahler has suggested fingerings.
These suggested fingerings are just that--a suggestion.  Unfortunately, you'll have to find what's most comfortable for yourself, but these are a good starting point.  When you work out fingerings, you need to balance the comfort of the fingering with how accurately you'll hit the notes and the control you'll have over your playing.  Experimentation will tell you what works best for you.
Good luck!
Answer: Just as there are standard fingerings for scales on piano, there are standard fingerings for arpeggios.  Charts for these fingerings seem less popular than for scales, probably because they are less "interesting."  One source explaining, rather than giving sheet music for, arpeggio fingerings can be found here.
Even if the arpeggios in, say, Debussy do not exactly correspond with major or minor arpeggios, drilling yourself on arpeggios as you would drill yourself on scales can help in overcoming hesitation.  The patterns for arpeggios will seem more natural if you practice arpeggios in isolation.  Then, it will not matter so much what piece you are playing.