问:
kernelspec is not installed and Jupyter-notebook not found, though pip says it is
I am trying to run a python script from vs code. A month ago, the environment was working perfectly, but today nope won't run. go figure.
Any and all attempts to install or update packages, e.g. python.exe -m pip install -U jupyter --user, returns "Requirement already satisfied".
Checking jupyter version says its not found.

```<code>python -m jupyter notebook --version
Traceback (most recent call last):
  File "C:\Users\dayneo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
    exec(code, run_globals)
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter.py", line 10, in <module>
    run_module('jupyter_core')
  File "C:\Users\dayneo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "C:\Users\dayneo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter_core\__main__.py", line 3, in <module>
    main()
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter_core\command.py", line 247, in main
    command = _jupyter_abspath(subcommand)
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter_core\command.py", line 133, in _jupyter_abspath
    raise Exception(
Exception: Jupyter command `jupyter-notebook` not found.
</code>```

Trying to install it, says its already there.

```<code>pip install -U jupyter
Requirement already up-to-date: jupyter in c:\users\dayneo\appdata\roaming\python\python38\site-packages (1.0.0)
Requirement already satisfied, skipping upgrade: nbconvert in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (5.6.1)
Requirement already satisfied, skipping upgrade: qtconsole in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (4.6.0)
Requirement already satisfied, skipping upgrade: ipywidgets in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (7.5.1)
Requirement already satisfied, skipping upgrade: jupyter-console in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (6.1.0)
Requirement already satisfied, skipping upgrade: ipykernel in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (5.1.4)
Requirement already satisfied, skipping upgrade: notebook in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (6.0.3)
Requirement already satisfied, skipping upgrade: entrypoints>=0.2.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.3)
Requirement already satisfied, skipping upgrade: testpath in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.4.4)
Requirement already satisfied, skipping upgrade: jinja2>=2.4 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (2.11.0)
Requirement already satisfied, skipping upgrade: traitlets>=4.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (4.3.3)
Requirement already satisfied, skipping upgrade: jupyter-core in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (4.6.1)
Requirement already satisfied, skipping upgrade: bleach in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (3.1.0)
Requirement already satisfied, skipping upgrade: defusedxml in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.6.0)
Requirement already satisfied, skipping upgrade: mistune<2,>=0.8.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.8.4)
Requirement already satisfied, skipping upgrade: pandocfilters>=1.4.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (1.4.2)
Requirement already satisfied, skipping upgrade: nbformat>=4.4 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (5.0.4)
Requirement already satisfied, skipping upgrade: pygments in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (2.5.2)
Requirement already satisfied, skipping upgrade: jupyter-client>=4.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from qtconsole->jupyter) (5.3.4)
Requirement already satisfied, skipping upgrade: ipython-genutils in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from qtconsole->jupyter) (0.2.0)
Requirement already satisfied, skipping upgrade: ipython>=4.0.0; python_version >= "3.3" in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipywidgets->jupyter) (7.11.1)
Requirement already satisfied, skipping upgrade: widgetsnbextension~=3.5.0 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipywidgets->jupyter)
(3.5.1)
Requirement already satisfied, skipping upgrade: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter-console->jupyter) (3.0.3)
Requirement already satisfied, skipping upgrade: tornado>=4.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipykernel->jupyter) (6.0.3)
Requirement already satisfied, skipping upgrade: Send2Trash in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (1.5.0)
Requirement already satisfied, skipping upgrade: prometheus-client in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (0.7.1)
Requirement already satisfied, skipping upgrade: pyzmq>=17 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (18.1.1)
Requirement already satisfied, skipping upgrade: terminado>=0.8.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (0.8.3)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jinja2>=2.4->nbconvert->jupyter) (1.1.1)
Requirement already satisfied, skipping upgrade: decorator in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from traitlets>=4.2->nbconvert->jupyter) (4.4.1)
Requirement already satisfied, skipping upgrade: six in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from traitlets>=4.2->nbconvert->jupyter) (1.13.0)
Requirement already satisfied, skipping upgrade: pywin32>=1.0; sys_platform == "win32" in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from jupyter-core->nbconvert->jupyter) (227)
Requirement already satisfied, skipping upgrade: webencodings in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from bleach->nbconvert->jupyter) (0.5.1)
Requirement already satisfied, skipping upgrade: jsonschema!=2.5.0,>=2.4 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from nbformat>=4.4->nbconvert->jupyter) (3.2.0)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter-client>=4.1->qtconsole->jupyter) (2.8.1)
Requirement already satisfied, skipping upgrade: pickleshare in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.7.5)
Requirement already satisfied, skipping upgrade: backcall in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.1.0)
Requirement already satisfied, skipping upgrade: colorama; sys_platform == "win32" in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.4.3)
Requirement already satisfied, skipping upgrade: jedi>=0.10 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.16.0)
Requirement already satisfied, skipping upgrade: setuptools>=18.5 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from ipython>=4.0.0;
python_version >= "3.3"->ipywidgets->jupyter) (41.2.0)
Requirement already satisfied, skipping upgrade: wcwidth in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->jupyter-console->jupyter) (0.1.8)
Requirement already satisfied, skipping upgrade: pywinpty>=0.5; os_name == "nt" in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from terminado>=0.8.1->notebook->jupyter) (0.5.7)
Requirement already satisfied, skipping upgrade: pyrsistent>=0.14.0 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4->nbconvert->jupyter) (0.15.6)
Requirement already satisfied, skipping upgrade: attrs>=17.4.0 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4->nbconvert->jupyter) (19.3.0)
Requirement already satisfied, skipping upgrade: parso>=0.5.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jedi>=0.10->ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.6.0)
</code>```

How do you proceed from here?

答:
Had the same problem. Had to manually add path:

C:\Users\XXX\AppData\Roaming\Python\Python36\Scripts

then I restarted my IDE to make sure Path has refreshed.

Body:
I am trying to run a python script from vs code. A month ago, the environment was working perfectly, but today nope won't run. go figure.
Any and all attempts to install or update packages, e.g. python.exe -m pip install -U jupyter --user, returns "Requirement already satisfied".
Checking jupyter version says its not found.

python -m jupyter notebook --version
Traceback (most recent call last):
  File "C:\Users\dayneo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
    exec(code, run_globals)
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter.py", line 10, in <module>
    run_module('jupyter_core')
  File "C:\Users\dayneo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 208, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "C:\Users\dayneo\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter_core\__main__.py", line 3, in <module>
    main()
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter_core\command.py", line 247, in main
    command = _jupyter_abspath(subcommand)
  File "C:\Users\dayneo\AppData\Roaming\Python\Python38\site-packages\jupyter_core\command.py", line 133, in _jupyter_abspath
    raise Exception(
Exception: Jupyter command `jupyter-notebook` not found.

Trying to install it, says its already there.

pip install -U jupyter
Requirement already up-to-date: jupyter in c:\users\dayneo\appdata\roaming\python\python38\site-packages (1.0.0)
Requirement already satisfied, skipping upgrade: nbconvert in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (5.6.1)
Requirement already satisfied, skipping upgrade: qtconsole in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (4.6.0)
Requirement already satisfied, skipping upgrade: ipywidgets in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (7.5.1)
Requirement already satisfied, skipping upgrade: jupyter-console in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (6.1.0)
Requirement already satisfied, skipping upgrade: ipykernel in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (5.1.4)
Requirement already satisfied, skipping upgrade: notebook in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter) (6.0.3)
Requirement already satisfied, skipping upgrade: entrypoints>=0.2.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.3)
Requirement already satisfied, skipping upgrade: testpath in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.4.4)
Requirement already satisfied, skipping upgrade: jinja2>=2.4 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (2.11.0)
Requirement already satisfied, skipping upgrade: traitlets>=4.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (4.3.3)
Requirement already satisfied, skipping upgrade: jupyter-core in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (4.6.1)
Requirement already satisfied, skipping upgrade: bleach in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (3.1.0)
Requirement already satisfied, skipping upgrade: defusedxml in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.6.0)
Requirement already satisfied, skipping upgrade: mistune<2,>=0.8.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (0.8.4)
Requirement already satisfied, skipping upgrade: pandocfilters>=1.4.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (1.4.2)
Requirement already satisfied, skipping upgrade: nbformat>=4.4 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (5.0.4)
Requirement already satisfied, skipping upgrade: pygments in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from nbconvert->jupyter) (2.5.2)
Requirement already satisfied, skipping upgrade: jupyter-client>=4.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from qtconsole->jupyter) (5.3.4)
Requirement already satisfied, skipping upgrade: ipython-genutils in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from qtconsole->jupyter) (0.2.0)
Requirement already satisfied, skipping upgrade: ipython>=4.0.0; python_version >= "3.3" in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipywidgets->jupyter) (7.11.1)
Requirement already satisfied, skipping upgrade: widgetsnbextension~=3.5.0 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipywidgets->jupyter)
(3.5.1)
Requirement already satisfied, skipping upgrade: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter-console->jupyter) (3.0.3)
Requirement already satisfied, skipping upgrade: tornado>=4.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipykernel->jupyter) (6.0.3)
Requirement already satisfied, skipping upgrade: Send2Trash in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (1.5.0)
Requirement already satisfied, skipping upgrade: prometheus-client in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (0.7.1)
Requirement already satisfied, skipping upgrade: pyzmq>=17 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (18.1.1)
Requirement already satisfied, skipping upgrade: terminado>=0.8.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from notebook->jupyter) (0.8.3)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jinja2>=2.4->nbconvert->jupyter) (1.1.1)
Requirement already satisfied, skipping upgrade: decorator in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from traitlets>=4.2->nbconvert->jupyter) (4.4.1)
Requirement already satisfied, skipping upgrade: six in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from traitlets>=4.2->nbconvert->jupyter) (1.13.0)
Requirement already satisfied, skipping upgrade: pywin32>=1.0; sys_platform == "win32" in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from jupyter-core->nbconvert->jupyter) (227)
Requirement already satisfied, skipping upgrade: webencodings in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from bleach->nbconvert->jupyter) (0.5.1)
Requirement already satisfied, skipping upgrade: jsonschema!=2.5.0,>=2.4 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from nbformat>=4.4->nbconvert->jupyter) (3.2.0)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jupyter-client>=4.1->qtconsole->jupyter) (2.8.1)
Requirement already satisfied, skipping upgrade: pickleshare in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.7.5)
Requirement already satisfied, skipping upgrade: backcall in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.1.0)
Requirement already satisfied, skipping upgrade: colorama; sys_platform == "win32" in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.4.3)
Requirement already satisfied, skipping upgrade: jedi>=0.10 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.16.0)
Requirement already satisfied, skipping upgrade: setuptools>=18.5 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from ipython>=4.0.0;
python_version >= "3.3"->ipywidgets->jupyter) (41.2.0)
Requirement already satisfied, skipping upgrade: wcwidth in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->jupyter-console->jupyter) (0.1.8)
Requirement already satisfied, skipping upgrade: pywinpty>=0.5; os_name == "nt" in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from terminado>=0.8.1->notebook->jupyter) (0.5.7)
Requirement already satisfied, skipping upgrade: pyrsistent>=0.14.0 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4->nbconvert->jupyter) (0.15.6)
Requirement already satisfied, skipping upgrade: attrs>=17.4.0 in c:\users\dayneo\appdata\local\programs\python\python38-32\lib\site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4->nbconvert->jupyter) (19.3.0)
Requirement already satisfied, skipping upgrade: parso>=0.5.2 in c:\users\dayneo\appdata\roaming\python\python38\site-packages (from jedi>=0.10->ipython>=4.0.0; python_version >= "3.3"->ipywidgets->jupyter) (0.6.0)

How do you proceed from here?


来源: stackexchange

问:
How can I post an array on ngModel?
I want to get data from a not exactly number of inputs on the right way in Angular 8 :

HTML

```<code><input  type="text" class="form-control">
<input  type="text" class="form-control">
<input  type="text" class="form-control">
</code>```

And I expect that fall in here:

TS

```<code>contato = { nome: '', tipo: '', fone: '', celular: '', email: '', skype: '', **prod: []** }
</code>```

I have tried something like :

```<code><input [(ngModel)]="contato.prod" type="text" class="form-control">
<input [(ngModel)]="contato.prod" type="text" class="form-control">
<input [(ngModel)]="contato.prod" type="text" class="form-control">
</code>```

No results

答:
Im not sure what are you trying to do, but if you want one input for every prod, you can use something like this using the *ngFor:</p>

```<code>@Component({
  selector: "app-example",
  template: `
    <input [(ngModel)]="contato.nome" type="text" class="form-control" />
    <input *ngFor="let prod of contato.prod; let i = index;" [(ngModel)]="contato.prod[i]" type="text" class="form-control" />
  `,
  styles: []
})
export class ExampleComponent {
  contato = { nome: "", prod: ["A", "B", "C"] };
}
</code>```

ContentLicense: CC BY-SA 4.0

Title: How can I post an array on ngModel?

Body:
I want to get data from a not exactly number of inputs on the right way in Angular 8 :

HTML

<input  type="text" class="form-control">
<input  type="text" class="form-control">
<input  type="text" class="form-control">

And I expect that fall in here:

TS

contato = { nome: '', tipo: '', fone: '', celular: '', email: '', skype: '', **prod: []** }

I have tried something like :

<input [(ngModel)]="contato.prod" type="text" class="form-control">
<input [(ngModel)]="contato.prod" type="text" class="form-control">
<input [(ngModel)]="contato.prod" type="text" class="form-control">

No results

Body:
Im not sure what are you trying to do, but if you want one input for every prod, you can use something like this using the *ngFor:

@Component({
  selector: "app-example",
  template: `
    <input [(ngModel)]="contato.nome" type="text" class="form-control" />
    <input *ngFor="let prod of contato.prod; let i = index;" [(ngModel)]="contato.prod[i]" type="text" class="form-control" />
  `,
  styles: []
})
export class ExampleComponent {
  contato = { nome: "", prod: ["A", "B", "C"] };
}


问:
Edit request (Add the correct join left) in oracle
i have a query, it works fine but i want to add another column!

```<code>SELECT
 typ.name as Silo_name,
 tr.DEVID,
 tr.name as dev_name
 FROM
   HANGINGTHREAD_SILO ev
   LEFT JOIN SILO typ
       ON ev.ID_SILO = typ.id
   LEFT JOIN IOT_DEVICES  tr
       ON ev.DEVICES_ID = tr.id
</code>```

But I want to add another column maximum temperature, the data for this column is in the table TEMPR_SILO.
And here's a query that I use to find the data I need for each tr.DEVID.

```<code>select MAX(to_char(TEMP,'99.99')) from TEMPR_SILO where ID_TRANS in (select max(ID_TRANS) from TEMPR_SILO)   and NAME in (select NAME from SILO_SENSOR where DEVICES_ID = tr.DEVID)
</code>```

I tried it this way, but I got the error

"ORA-20999: Failed to parse SQL query!
 ORA-06550: line 17, column 3: ORA-00933: SQL command not properly ended"

```<code>SELECT
 typ.name as Silo_name,
 tr.DEVID,
 tr.name as dev_name
 ,max(ts.TEMP)  AS "Lowest salary"
 FROM
   HANGINGTHREAD_SILO ev
   LEFT JOIN SILO typ
       ON ev.ID_SILO = typ.id
   LEFT JOIN IOT_DEVICES  tr
       ON ev.DEVICES_ID = tr.id
   LEFT JOIN  TEMPR_SILO  ts
     ON ts.name  in (select NAME from SILO_SENSOR where DEVICES_ID = tr.DEVID)
     and  ts.ID_TRANS in(select max(ID_TRANS) from TEMPR_SILO)
GROUP BY
 ev.id,
 typ.name as Silo_name,
 tr.DEVID,
 tr.name as dev_name ;
</code>```

答:
Here's my option and it works)

for MAX
SELECT
 typ.name as Silo_name,
 tr.DEVID,
 ts.temp as max_temp,
 tr.name as dev_name
 FROM
   HANGINGTHREAD_SILO ev
   LEFT JOIN SILO typ
       ON ev.ID_SILO = typ.id
   LEFT JOIN IOT_DEVICES  tr
       ON ev.DEVICES_ID = tr.id
   LEFT JOIN  SILO_SENSOR er
   ON er.DEVICES_ID =  tr.DEVID
   LEFT JOIN  TEMPR_SILO  ts
    ON ts.NAME = er.name
   LEFT JOIN  TEMPR_SILO  ns
    ON  ns.NAME = er.name
where ts.temp in (select max(TEMP) from TEMPR_SILO
                    where ID_TRANS in (select max(ID_TRANS) from TEMPR_SILO)
                    and NAME in (select NAME from SILO_SENSOR where DEVICES_ID = tr.DEVID))

group by
 typ.name ,
 tr.DEVID,
 ts.temp,
 tr.name```

Body:
i have a query, it works fine but i want to add another column!

SELECT
 typ.name as Silo_name,
 tr.DEVID,
 tr.name as dev_name
 FROM
   HANGINGTHREAD_SILO ev
   LEFT JOIN SILO typ
       ON ev.ID_SILO = typ.id
   LEFT JOIN IOT_DEVICES  tr
       ON ev.DEVICES_ID = tr.id

But I want to add another column maximum temperature, the data for this column is in the table TEMPR_SILO.
And here's a query that I use to find the data I need for each tr.DEVID.

select MAX(to_char(TEMP,'99.99')) from TEMPR_SILO where ID_TRANS in (select max(ID_TRANS) from TEMPR_SILO)   and NAME in (select NAME from SILO_SENSOR where DEVICES_ID = tr.DEVID)

I tried it this way, but I got the error

"ORA-20999: Failed to parse SQL query!
 ORA-06550: line 17, column 3: ORA-00933: SQL command not properly ended"

SELECT
 typ.name as Silo_name,
 tr.DEVID,
 tr.name as dev_name
 ,max(ts.TEMP)  AS "Lowest salary"
 FROM
   HANGINGTHREAD_SILO ev
   LEFT JOIN SILO typ
       ON ev.ID_SILO = typ.id
   LEFT JOIN IOT_DEVICES  tr
       ON ev.DEVICES_ID = tr.id
   LEFT JOIN  TEMPR_SILO  ts
     ON ts.name  in (select NAME from SILO_SENSOR where DEVICES_ID = tr.DEVID)
     and  ts.ID_TRANS in(select max(ID_TRANS) from TEMPR_SILO)
GROUP BY
 ev.id,
 typ.name as Silo_name,
 tr.DEVID,
 tr.name as dev_name ;


问:
How to get the key value from the String of JSON in swift
I have a JSON string value how to get the key value from the json using swift code?

```<code>{
 "user":{  "id":"74d93200-2ed2-437c-976f-83710eaea923","firstName":"dev","lastName":"che", "username":"dev_che"}}
</code>```

From this how to get the "username" value using swift code?

答:
first define User struct

```<code>struct UserModel: Codable {
    let user: User?
}

struct User: Codable {
    let id, firstName, lastName, username: String?
}
</code>```

then decode your model from json

let userData =
            "{\"user\":{\"id\":\"74d93200-2ed2-437c-976f-83710eaea923\",\"firstName\":\"dev\",\"lastName\":\"che\", \"username\":\"dev_che\"}}"
        let data = userData.data(using: .utf8)!
        let userModel = try? JSONDecoder().decode(UserModel.self, from: data)

```

<p>then you can use it this way :</p>

<pre class="lang-swift prettyprint-override"><code>
userModel.username
</code>```

Body:
I have a JSON string value how to get the key value from the json using swift code?

{
 "user":{  "id":"74d93200-2ed2-437c-976f-83710eaea923","firstName":"dev","lastName":"che", "username":"dev_che"}}

From this how to get the "username" value using swift code?

Body:
first define User struct

struct UserModel: Codable {
    let user: User?
}

struct User: Codable {
    let id, firstName, lastName, username: String?
}

then decode your model from json

let userData =
            "{\"user\":{\"id\":\"74d93200-2ed2-437c-976f-83710eaea923\",\"firstName\":\"dev\",\"lastName\":\"che\", \"username\":\"dev_che\"}}"
        let data = userData.data(using: .utf8)!
        let userModel = try? JSONDecoder().decode(UserModel.self, from: data)

then you can use it this way :

userModel.username


问:
Data from Realtime Firebase is displaying in console but not in html page
Component.ts

plats is the root node of my Firebase database,I want to display every child of my root node in
angular page.The data is displayed in console but not in angular page. Thank you for your helps in
advance.

```<code>    itemValue = '';
    name: string;
    plats: Observable<any[]>;
    itemRef: AngularFireObject<any>;

    constructor(public db: AngularFireDatabase)
    {
    this.itemRef = db.object('plats');
    this.itemRef.snapshotChanges().subscribe(action => {
    const data = action.payload.val();
    console.log(action.payload.val());
    return { ...data };
    });

 }
</code>```

component.html

```<code>    <div class="container">
      <table>
        <tr>
          <th>Community</th>
        </tr>
       <tr *ngFor="let item of plats | async">
          <td>{{item}}</td>
      </tr>
     </table>
   </div>
</code>```

答:
```<code><tr *ngFor="let item of plats">
  <td>{{item}}</td>
</tr>
</code>```

in your code here you want to access the value of key element. just access it like {{item.key}}. hope this will work.

Body:
Component.ts

plats is the root node of my Firebase database,I want to display every child of my root node in
angular page.The data is displayed in console but not in angular page. Thank you for your helps in
advance.

    itemValue = '';
    name: string;
    plats: Observable<any[]>;
    itemRef: AngularFireObject<any>;

    constructor(public db: AngularFireDatabase)
    {
    this.itemRef = db.object('plats');
    this.itemRef.snapshotChanges().subscribe(action => {
    const data = action.payload.val();
    console.log(action.payload.val());
    return { ...data };
    });

 }

component.html

          Community

          {{item}}

Body:
<tr *ngFor="let item of plats">
  <td>{{item}}</td>
</tr>

in your code here you want to access the value of key element. just access it like {{item.key}}. hope this will work.


问:
Explain PostgreSQL stored procedures
I just can't quite get a grasp on them (working with PostgreSQL as of today). Working with version 9.0.4 on Windows, using pgAdmin III.
I have a relatively long experience with MS SQL Server functions and SPs.
As I've understood so far, there is no direct analogue to MSSQL SP-s in PostgreSQL (however Functions looks just the same). But you can create procedures in other languages which can be built into postgres. So far I was able to produce following:

```<code>CREATE OR REPLACE FUNCTION GetProduct()
    RETURNS refcursor AS

$BODY$
DECLARE pr_cur refcursor;

BEGIN
    OPEN pr_cur FOR
        SELECT * FROM "Product";
    RETURN pr_cur;
END;
$BODY$

LANGUAGE plpgsql VOLATILE
    COST 100;
</code>```

And use it like this (using Npgsql library):

```<code>NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=*;Password=*;Database=Warehouse;");
conn.Open();
NpgsqlTransaction t = conn.BeginTransaction();

NpgsqlCommand command = new NpgsqlCommand("GetProduct", conn);
command.CommandType = CommandType.StoredProcedure;
NpgsqlDataAdapter da = new NpgsqlDataAdapter(command);

DataSet myDS = new DataSet();
da.Fill(myDS);

t.Commit();
conn.Close();

myDS.WriteXml("out.xml");
</code>```

It works but I don't understand completely how. First I have not found refcursor in return types of Create function dialog of pgAdmin (is it a synonim to something else?). Second, I still can't manage to get row output in pgAdmin from function:

```<code>SELECT * FROM GetProduct();
</code>```

works not as expected :).
Third: does this "function" works same way as SPs of SQL Server (compiled, executes faster, etc.)? Or still this is just some workaround to get almost same behaviour?

And last but not least - any good tutorial for ones migration from SQL Server?

UPDATE:

Investigating problem further it's seems like indeed, there is direct equivalent for MSSQL SPs in pgSQL, but you can use functions instead. So one more question now, is it reasonable to use pgSQL functions instead of SPs? As I understand it now, my query return some kind of firehose cursor to result. I've almost never used cursors in MSSQL and know that it's not recommended to do that as it's very inefficient? Or is it some other kind of cursor we dealing here?

答:
You can write a function like this.

```<code>create function GetProduct()
returns setof Product as
  'select * from "Product";'
language 'sql';
</code>```

And you can get its results like this.

```<code>select * from GetProduct();
</code>```

If your function doesn't return any data, call it like this.

```<code>select procedure_name(arg1, arg2)
</code>```

ContentLicense: CC BY-SA 3.0

Title: Explain PostgreSQL stored procedures

Body:
I just can't quite get a grasp on them (working with PostgreSQL as of today). Working with version 9.0.4 on Windows, using pgAdmin III.
I have a relatively long experience with MS SQL Server functions and SPs.
As I've understood so far, there is no direct analogue to MSSQL SP-s in PostgreSQL (however Functions looks just the same). But you can create procedures in other languages which can be built into postgres. So far I was able to produce following:

CREATE OR REPLACE FUNCTION GetProduct()
    RETURNS refcursor AS

$BODY$
DECLARE pr_cur refcursor;

BEGIN
    OPEN pr_cur FOR
        SELECT * FROM "Product";
    RETURN pr_cur;
END;
$BODY$

LANGUAGE plpgsql VOLATILE
    COST 100;

And use it like this (using Npgsql library):

NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=*;Password=*;Database=Warehouse;");
conn.Open();
NpgsqlTransaction t = conn.BeginTransaction();

NpgsqlCommand command = new NpgsqlCommand("GetProduct", conn);
command.CommandType = CommandType.StoredProcedure;
NpgsqlDataAdapter da = new NpgsqlDataAdapter(command);

DataSet myDS = new DataSet();
da.Fill(myDS);

t.Commit();
conn.Close();

myDS.WriteXml("out.xml");

It works but I don't understand completely how. First I have not found refcursor in return types of Create function dialog of pgAdmin (is it a synonim to something else?). Second, I still can't manage to get row output in pgAdmin from function:

SELECT * FROM GetProduct();

works not as expected :).
Third: does this "function" works same way as SPs of SQL Server (compiled, executes faster, etc.)? Or still this is just some workaround to get almost same behaviour?

And last but not least - any good tutorial for ones migration from SQL Server?

UPDATE:

Investigating problem further it's seems like indeed, there is direct equivalent for MSSQL SPs in pgSQL, but you can use functions instead. So one more question now, is it reasonable to use pgSQL functions instead of SPs? As I understand it now, my query return some kind of firehose cursor to result. I've almost never used cursors in MSSQL and know that it's not recommended to do that as it's very inefficient? Or is it some other kind of cursor we dealing here?

Body:
You can write a function like this.

create function GetProduct()
returns setof Product as
  'select * from "Product";'
language 'sql';

And you can get its results like this.

select * from GetProduct();

If your function doesn't return any data, call it like this.

select procedure_name(arg1, arg2)


问:
Changing getter value using state value in Vuex
I have this getter that get the value of one item in the state:

```<code>boxdata: state => {
      return state.boxchart.data
    },
</code>```

Now I have another item in state that I use to change the value of getter

Currently I do this when component is mounted but it seems that the data sometimes loads but sometimes does not:

```<code>computed: {
      ...mapGetters(["boxdata"]),
      ...mapState(['reference_fc'])
    },

mounted() {
 this.boxdata[0].chartOptions.series[0].data[0]=this.reference_fc.NSR.values
}
</code>```

So I wonder how can I ensure that the boxdata getter is already updated on the first time that the component loads?

答:
You shouldn't mutate data using getters. You should use mutations.

Getters are only to get derived state based on store state. see here

In your store :

mutations: {
  setBoxdata(state, value) {
     state.boxchart.data[0].chartOptions.series[0].data[0] = value;
  }
}
```

<p>In your component : </p>

<pre class="lang-js prettyprint-override"><code>computed: {
  ...mapMutations("setBoxdata")
},
mounted() {
  this.setBoxData(this.reference_fc.NSR.values);
}
</code>```

Body:
I have this getter that get the value of one item in the state:

boxdata: state => {
      return state.boxchart.data
    },

Now I have another item in state that I use to change the value of getter

Currently I do this when component is mounted but it seems that the data sometimes loads but sometimes does not:

computed: {
      ...mapGetters(["boxdata"]),
      ...mapState(['reference_fc'])
    },

mounted() {
 this.boxdata[0].chartOptions.series[0].data[0]=this.reference_fc.NSR.values
}

So I wonder how can I ensure that the boxdata getter is already updated on the first time that the component loads?

Body:
You shouldn't mutate data using getters. You should use mutations.

Getters are only to get derived state based on store state. see here

In your store :

mutations: {
  setBoxdata(state, value) {
     state.boxchart.data[0].chartOptions.series[0].data[0] = value;
  }
}

In your component :

computed: {
  ...mapMutations("setBoxdata")
},
mounted() {
  this.setBoxData(this.reference_fc.NSR.values);
}


问:
How to make start with / contains work with EF and SQL Text column storing JSON
I have table with nvarchar (max) column storing json like one below,

{"status":"Archieved","oldCategories":{"name":"LONG Life -
  Milk","products":{"tagPrice1Notes":"800 Times
  Said","columnType2":"","columnType3":"someValue3","columnType4":"someValue4","columnType5":"someValue5","columnType6":"someValue6","columnType7":"someValue7"}},"moreProperties":.... so on

Now I need to get all columns where value starts with above string, however I am getting 0 rows back, here is what I am trying,

```<code> var matchMe = (
                "{'status':'Archieved'" +
                "','oldCategories': {'name': '" + someObject.Name +
                "','products': {'tagPrice1Notes': '" + someObject.C1 +
                "','columnType2': '" + someObject.C2 +
                "','columnType3': '" + someObject.C3 +
                "','columnType4': '" + someObject.C4 +
                "','columnType5': '" + someObject.C5 +
                "','columnType6': '" + someObject.C6 +
                "','columnType7': '" + someObject.C7 +
                "'}}"
                );
dbContext.CategoriesProducts.Where(x => x.MyJsonDetailsColumn.ToUpper().Trim().Contains(matchMe.ToUpper().Trim()))
.ToList();
</code>```

This is a temporary fix and we will do a refactor later on.

答: Your example code will basically read all the data back to your client (the ToUpper/Trim parts will mean this is a client side check), so why not just read all the data, deserialise it into an object and perform a proper comparison of the fields you need to?</p>

Body:
I have table with nvarchar (max) column storing json like one below,

{"status":"Archieved","oldCategories":{"name":"LONG Life -
  Milk","products":{"tagPrice1Notes":"800 Times
  Said","columnType2":"","columnType3":"someValue3","columnType4":"someValue4","columnType5":"someValue5","columnType6":"someValue6","columnType7":"someValue7"}},"moreProperties":.... so on

Now I need to get all columns where value starts with above string, however I am getting 0 rows back, here is what I am trying,

 var matchMe = (
                "{'status':'Archieved'" +
                "','oldCategories': {'name': '" + someObject.Name +
                "','products': {'tagPrice1Notes': '" + someObject.C1 +
                "','columnType2': '" + someObject.C2 +
                "','columnType3': '" + someObject.C3 +
                "','columnType4': '" + someObject.C4 +
                "','columnType5': '" + someObject.C5 +
                "','columnType6': '" + someObject.C6 +
                "','columnType7': '" + someObject.C7 +
                "'}}"
                );
dbContext.CategoriesProducts.Where(x => x.MyJsonDetailsColumn.ToUpper().Trim().Contains(matchMe.ToUpper().Trim()))
.ToList();

This is a temporary fix and we will do a refactor later on.


问:
Update value of a column c# winforms applicaiton
I'm trying to update a column value with a where clause but it triggers an error

"Must declare the scalar variable "@datestring"

My problematical part of the application is this:

```<code>private void button2_Click(object sender, EventArgs e)
        {
            string value = "";
            string connetionString = "Data Source=LENOVO-PC\\CDVI_CENTAUR;Integrated Security=True";
            string sql = null;

            value = listBox1.GetItemText(listBox1.SelectedItem);
            var datestring = dateTimePicker1.Value.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            var FirstName = value.Split(' ')[0];
            var LastName = value.Split(' ')[1];
            using (System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(connetionString))
            {
                try
                {
                    cnn.Open();
                    using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE [Centaur3Main].[dbo].[Users]  SET [UDText12b] = @datestring WHERE FirstName = @FirstName and LastName = @LastName ", cnn))
                    {
                        // Create and set the parameters values
                        cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName;
                        cmd.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = LastName;

                        cmd.ExecuteNonQuery();

                    }
                }

            }
</code>```

The value of the datestring is from a datetimepicker and it has a value. So I don't understand how to fix this error.`
Can you please help me. I know it is a newbie caused error but I cannot figure it out. /I'm still a junior by the way/. Tried different things and solutions from the internet but still cannot figure the solution workaround.
Can you please give me a solution about my problem.

答:
That's cause you are not passing any parameter for @datestring as the error clearly says. You need to pass that parameter as well like

```<code>cmd.Parameters.Add("@datestring", SqlDbType.DateTime).Value = datestring;
</code>```

Body:
I'm trying to update a column value with a where clause but it triggers an error

"Must declare the scalar variable "@datestring"

My problematical part of the application is this:

private void button2_Click(object sender, EventArgs e)
        {
            string value = "";
            string connetionString = "Data Source=LENOVO-PC\\CDVI_CENTAUR;Integrated Security=True";
            string sql = null;

            value = listBox1.GetItemText(listBox1.SelectedItem);
            var datestring = dateTimePicker1.Value.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

            var FirstName = value.Split(' ')[0];
            var LastName = value.Split(' ')[1];
            using (System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(connetionString))
            {
                try
                {
                    cnn.Open();
                    using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE [Centaur3Main].[dbo].[Users]  SET [UDText12b] = @datestring WHERE FirstName = @FirstName and LastName = @LastName ", cnn))
                    {
                        // Create and set the parameters values
                        cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName;
                        cmd.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = LastName;

                        cmd.ExecuteNonQuery();

                    }
                }

            }

The value of the datestring is from a datetimepicker and it has a value. So I don't understand how to fix this error.`
Can you please help me. I know it is a newbie caused error but I cannot figure it out. /I'm still a junior by the way/. Tried different things and solutions from the internet but still cannot figure the solution workaround.
Can you please give me a solution about my problem.

Body:
That's cause you are not passing any parameter for @datestring as the error clearly says. You need to pass that parameter as well like

cmd.Parameters.Add("@datestring", SqlDbType.DateTime).Value = datestring;


答:
you need to add one more parameter to your SQL command. This parameter is @datestring. Try like:

```<code>using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE [Centaur3Main].[dbo].[Users]  SET [UDText12b] = @datestring WHERE FirstName = @FirstName and LastName = @LastName ", cnn))
{
  // Create and set the parameters values
  cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName;
  cmd.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = LastName;
  cmd.Parameters.Add("@datestring",SqlDbType.DateTime).Value = dateTimePicker1.Value;
  cmd.ExecuteNonQuery();
}
</code>```

Title: Update value of a column c# winforms applicaiton

Body:
you need to add one more parameter to your SQL command. This parameter is @datestring. Try like:

using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("UPDATE [Centaur3Main].[dbo].[Users]  SET [UDText12b] = @datestring WHERE FirstName = @FirstName and LastName = @LastName ", cnn))
{
  // Create and set the parameters values
  cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName;
  cmd.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = LastName;
  cmd.Parameters.Add("@datestring",SqlDbType.DateTime).Value = dateTimePicker1.Value;
  cmd.ExecuteNonQuery();
}


问:
How to modify a number passed into a method as an argument

Background

I have a method which in which I want to modify a number which will be passed into the method, but not returned.

Example

def increase_number_by_one_and_do_some_other_stuff(number)
    number = number + 1
    some_other_stuff = "Other stuff I want to happen in this function"
    some_other_stuff
end

number = 1

increase_number_by_one_and_do_some_other_stuff(number)

puts number
# => 1
## Expecting 2
```

<p>Is there any way to achieve this in Ruby, or is it always Pass by Value? I have tried to understand exactly how object references/values are treated in Ruby, but for my level of experience it's quite confusing still.</p>

<h3>More context</h3>

<p>The situation I'm trying to use it is something like this. Tried to keep it simple but still give enough information.</p>

<pre class="lang-rb prettyprint-override"><code>total = 1000
unaccounted_for = 100
accounted_for = total - unaccounted_for

distribute_unaccounted(unaccounted_for, accounted_for)

puts unaccounted_for
# => 55
puts accounted_for
# => 945

def distributed_unaccounted(unaccounted_for, accounted_for)
   # lots of code
   category_a_reaccounted = 25 # calculated within this method
   category_b_reaccounted = 20 # calculated within this method
   total_reaccounted = category_a_reaccounted + category_b_reaccounted
   unaccounted_for -= total_reaccounted
   accounted_for += total_reaccounted
end

</code>```

答:
I have a method which in which I want to modify a number ...

Numbers are immutable, you cannot change them. 1 will always be 1.

I think what you actually want is to assign a new value to the number variable within your method and the number variable outside your method.

But that's not possible in Ruby. The variables inside your methods have their own variable scope and changes don't propagate outside. So assigning a new object to a variable inside your method won't affect "outside" variables.

Is there any way to achieve this in Ruby ...

What I see are several values and methods that work on those values. Why not move them into a class, as instance variables and instance methods?

```<code>class Foo
  attr_reader :total, :unaccounted_for

  def initialize(total, unaccounted_for)
    @total = total
    @unaccounted_for = unaccounted_for
  end

  def accounted_for
    total - unaccounted_for
  end

  def category_a_reaccounted
    25 # actually calculated
  end

  def category_b_reaccounted
    20 # actually calculated
  end

  def distributed_unaccounted
    total_reaccounted = category_a_reaccounted + category_b_reaccounted
    @unaccounted_for -= total_reaccounted
  end
end
</code>```

Usage, based on your example:

```<code>foo = Foo.new(1000, 100)

foo.unaccounted_for #=> 100
foo.accounted_for   #=> 900

foo.distributed_unaccounted

foo.unaccounted_for #=> 55
foo.accounted_for   #=> 945
</code>```

Body:
Background

I have a method which in which I want to modify a number which will be passed into the method, but not returned.

Example

def increase_number_by_one_and_do_some_other_stuff(number)
    number = number + 1
    some_other_stuff = "Other stuff I want to happen in this function"
    some_other_stuff
end

number = 1

increase_number_by_one_and_do_some_other_stuff(number)

puts number
# => 1
## Expecting 2

Is there any way to achieve this in Ruby, or is it always Pass by Value? I have tried to understand exactly how object references/values are treated in Ruby, but for my level of experience it's quite confusing still.

More context

The situation I'm trying to use it is something like this. Tried to keep it simple but still give enough information.

total = 1000
unaccounted_for = 100
accounted_for = total - unaccounted_for

distribute_unaccounted(unaccounted_for, accounted_for)

puts unaccounted_for
# => 55
puts accounted_for
# => 945

def distributed_unaccounted(unaccounted_for, accounted_for)
   # lots of code
   category_a_reaccounted = 25 # calculated within this method
   category_b_reaccounted = 20 # calculated within this method
   total_reaccounted = category_a_reaccounted + category_b_reaccounted
   unaccounted_for -= total_reaccounted
   accounted_for += total_reaccounted
end

Body:
I have a method which in which I want to modify a number ...

Numbers are immutable, you cannot change them. 1 will always be 1.

I think what you actually want is to assign a new value to the number variable within your method and the number variable outside your method.

But that's not possible in Ruby. The variables inside your methods have their own variable scope and changes don't propagate outside. So assigning a new object to a variable inside your method won't affect "outside" variables.

Is there any way to achieve this in Ruby ...

What I see are several values and methods that work on those values. Why not move them into a class, as instance variables and instance methods?

class Foo
  attr_reader :total, :unaccounted_for

  def initialize(total, unaccounted_for)
    @total = total
    @unaccounted_for = unaccounted_for
  end

  def accounted_for
    total - unaccounted_for
  end

  def category_a_reaccounted
    25 # actually calculated
  end

  def category_b_reaccounted
    20 # actually calculated
  end

  def distributed_unaccounted
    total_reaccounted = category_a_reaccounted + category_b_reaccounted
    @unaccounted_for -= total_reaccounted
  end
end

Usage, based on your example:

foo = Foo.new(1000, 100)

foo.unaccounted_for #=> 100
foo.accounted_for   #=> 900

foo.distributed_unaccounted

foo.unaccounted_for #=> 55
foo.accounted_for   #=> 945


问:
Java Jackson select registered module from multiple modules to serialize JSON as string?
I have a simple java class and want to serialize it to different JSON outputs. e.g:

```<code>Class User {
    public int id;
    public String name;
}

// 2 expected outputs
Version 1 (V1): {"id": "1", "first_name": "A"}
Version 2 (V2): {"id": "1", "name": "A"}
</code>```

I created 2 customized modules to write to JSON String and they are registered to one ObjectMapper as below:

```<code>public class ItemSerializerModuleV1 extends SimpleModule {

    public ItemSerializerModuleV1() {
        super(NAME, VERSION_UTIL.version());
        addSerializer(Item.class, new ItemSerializerV1());
    }
}

public class ItemSerializerModuleV2 extends SimpleModule {

    public ItemSerializerModuleV2() {
        super(NAME, VERSION_UTIL.version());
        addSerializer(Item.class, new ItemSerializerV2());
    }
}

ObjectMapper mapper = new ObjectMapper();
mapper.registerModules(new ItemSerializerModuleV1(), new ItemSerializerModuleV2());
</code>```

However, I don't know how to select which module should be used for ObjectMapper when it writes to JSON string. It only selects the V2 module (the last module registered) with the code below while I also want to write as V1 as well.

```<code>String serialized = mapper.writeValueAsString(myItem);
</code>```

答:
Modules can be used to extend the functionality provided by ObjectMapper, for example, by adding providers for custom serializers and deserializers. You cannot select a module for a particular serialization or disable a module once it's registered.

So you should have two instances of ObjectMapper and each instance will a different module registered.

Body:
I have a simple java class and want to serialize it to different JSON outputs. e.g:

Class User {
    public int id;
    public String name;
}

// 2 expected outputs
Version 1 (V1): {"id": "1", "first_name": "A"}
Version 2 (V2): {"id": "1", "name": "A"}

I created 2 customized modules to write to JSON String and they are registered to one ObjectMapper as below:

public class ItemSerializerModuleV1 extends SimpleModule {

    public ItemSerializerModuleV1() {
        super(NAME, VERSION_UTIL.version());
        addSerializer(Item.class, new ItemSerializerV1());
    }
}

public class ItemSerializerModuleV2 extends SimpleModule {

    public ItemSerializerModuleV2() {
        super(NAME, VERSION_UTIL.version());
        addSerializer(Item.class, new ItemSerializerV2());
    }
}

ObjectMapper mapper = new ObjectMapper();
mapper.registerModules(new ItemSerializerModuleV1(), new ItemSerializerModuleV2());

However, I don't know how to select which module should be used for ObjectMapper when it writes to JSON string. It only selects the V2 module (the last module registered) with the code below while I also want to write as V1 as well.

String serialized = mapper.writeValueAsString(myItem);


问:
How to use no fill for background color of a excel cell using c#?
With this:

```<code>using Excel = Microsoft.Office.Interop.Excel;
</code>```

I'm opening the excel and after I'm setting the color of the first cell to transparent like this:

```<code>xlRange = xlWorkSheet.get_Range("A1");
xlRange.Interior.Color = System.Drawing.Color.Transparent;
</code>```

The problem is that it puts white and the "borders" disappear. I want to put the "No Fill" option and it's not working.

I've also tried this:

```<code>xlRange.Interior.Color = System.Drawing.Color.Empty;
</code>```

but then it changed the cell color to black.

How can I solve this?

答:
Maybe this is just partly related to this question; but I noticed by using

xlRange.Interior.Pattern = Excel.XlPattern.xlPatternNone;;

Also all cell fill color disappears. This is not the case when using:

xlRange.Interior.Pattern = Excel.XlPattern.xlPatternAutomatic;

I was searching for this and came upon this question, so I add this for extra info.

Body:
With this:

using Excel = Microsoft.Office.Interop.Excel;

I'm opening the excel and after I'm setting the color of the first cell to transparent like this:

xlRange = xlWorkSheet.get_Range("A1");
xlRange.Interior.Color = System.Drawing.Color.Transparent;

The problem is that it puts white and the "borders" disappear. I want to put the "No Fill" option and it's not working.

I've also tried this:

xlRange.Interior.Color = System.Drawing.Color.Empty;

but then it changed the cell color to black.

How can I solve this?


问:
Watchpoint vs watch expression in eclipse
I am working on a lengthy C code split across different files. While debugging, I would like the simulation to stop wherever the value of a certain parameter is changed (not to a specific value).

I have come across watchpoint and watch expression feature in eclipse what is the difference, what would be best suited to track a certain parameter?

Not an expert here, so please be kind :)
Thanks :)

答:
According to official docs at Watchpoints:

A watchpoint is a special breakpoint that stops the execution of an application whenever the value of a given expression changes, without specifying where it might occur. Unlike breakpoints (which are line-specific), watchpoints are associated with files. They take effect whenever a specified condition is true, regardless of when or where it occurred. You can set a watchpoint on a global variable by highlighting the variable in the editor, or by selecting it in the Outline view.

To set a watchpoint on a global variable:

Highlight the variable in the editor, or select it in the Outline view.

Click Run > Toggle Watchpoint.

Do any of the following:

To stop execution when the watch expression is read, select the Read check box.

To stop execution when the watch expression is written to, select the Write check box.

The watchpoint appears in the Breakpoints view list.

So, I guess, the watchpoint itself is defined by the watchpoint expression.


问:
C# Testing - compare list of custom type
I'm trying to write test checking if JSON converter corectly deserialize input to my custom list

```<code>    [TestMethod]
    public void JSONInput_Changed()
    {
        List<PointOnChart> _expectedPointsOnChart;
        _expectedPointsOnChart = new List<PointOnChart>();
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:00:00.000Z", Value1 = 10, Value2 = 20, Value3 = 30 });
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:01:00.000Z", Value1 = 11, Value2 = 21, Value3 = 31 });
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:02:00.000Z", Value1 = 12, Value2 = 22, Value3 = 32 });
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:03:00.000Z", Value1 = 13, Value2 = 23, Value3 = 33 });

        MultipleBarChart multipleBarChartTest = new MultipleBarChart();
        multipleBarChartTest.MeInitialize(DateTimeIntervalType.Minutes);
        string JSONstring = System.IO.File.ReadAllText(@"C:\Users\slawomirk\source\repos\VIXCharts\iFixMultipleBarChartTests\TestJson.txt");
        multipleBarChartTest.JSONInput = JSONstring;
        List<PointOnChart> resultPointsOnChart = multipleBarChartTest.PointsOnChart;

        //bool areEqual = _expectedPointsOnChart.SequenceEqual(resultPointsOnChart);
        IEnumerable<PointOnChart> resultList;
        resultList = _expectedPointsOnChart.Except(resultPointsOnChart);
        if (resultList.Any())
        {
            Assert.Fail();
        }
    }
</code>```

List contains object of this class

```<code>public class PointOnChart
{
    public string Timestamp { get; set; }
    public double Value1 { get; set; }
    public double Value2 { get; set; }
    public double Value3 { get; set; }
}
</code>```

And this is file I'm reading to deserialize:

[{"Timestamp":"2020-02-14T09:00:00.000Z","Value1":10,"Value2":20,"Value3":30},
  {"Timestamp":"2020-02-14T09:01:00.000Z","Value1":11,"Value2":21,"Value3":31},
  {"Timestamp":"2020-02-14T09:02:00.000Z","Value1":12,"Value2":22,"Value3":32},
  {"Timestamp":"2020-02-14T09:03:00.000Z","Value1":13,"Value2":23,"Value3":33}]

I tried numerous ways to compare two Lists but all of them fails eg.:
 - Fluent Assertion
 - CollectionAssert

When I inspect both List in debug they are identical.
I know it's probably trivial but I could find any solution online, thanks in advance.

答:
You should implement the Equals method for the PointOnChart class, something like this:

```<code>public override bool Equals(object other)
{
    if (object.ReferenceEquals(other, this)) return true;

    var obj = other as PointOnChart;

    if (obj == null) return false;

    return this.Timestamp == obj.Timestamp && this.Value1 == obj.Value1 && this.Value2 == obj.Value2 && this.Value3 == obj.Value3;
}
</code>```

This way the SequenceEquals extension method will operate properly.

Body:
I'm trying to write test checking if JSON converter corectly deserialize input to my custom list

    [TestMethod]
    public void JSONInput_Changed()
    {
        List<PointOnChart> _expectedPointsOnChart;
        _expectedPointsOnChart = new List<PointOnChart>();
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:00:00.000Z", Value1 = 10, Value2 = 20, Value3 = 30 });
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:01:00.000Z", Value1 = 11, Value2 = 21, Value3 = 31 });
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:02:00.000Z", Value1 = 12, Value2 = 22, Value3 = 32 });
        _expectedPointsOnChart.Add(new PointOnChart { Timestamp = "2020-02-14T09:03:00.000Z", Value1 = 13, Value2 = 23, Value3 = 33 });

        MultipleBarChart multipleBarChartTest = new MultipleBarChart();
        multipleBarChartTest.MeInitialize(DateTimeIntervalType.Minutes);
        string JSONstring = System.IO.File.ReadAllText(@"C:\Users\slawomirk\source\repos\VIXCharts\iFixMultipleBarChartTests\TestJson.txt");
        multipleBarChartTest.JSONInput = JSONstring;
        List<PointOnChart> resultPointsOnChart = multipleBarChartTest.PointsOnChart;

        //bool areEqual = _expectedPointsOnChart.SequenceEqual(resultPointsOnChart);
        IEnumerable<PointOnChart> resultList;
        resultList = _expectedPointsOnChart.Except(resultPointsOnChart);
        if (resultList.Any())
        {
            Assert.Fail();
        }
    }

List contains object of this class

public class PointOnChart
{
    public string Timestamp { get; set; }
    public double Value1 { get; set; }
    public double Value2 { get; set; }
    public double Value3 { get; set; }
}

And this is file I'm reading to deserialize:

[{"Timestamp":"2020-02-14T09:00:00.000Z","Value1":10,"Value2":20,"Value3":30},
  {"Timestamp":"2020-02-14T09:01:00.000Z","Value1":11,"Value2":21,"Value3":31},
  {"Timestamp":"2020-02-14T09:02:00.000Z","Value1":12,"Value2":22,"Value3":32},
  {"Timestamp":"2020-02-14T09:03:00.000Z","Value1":13,"Value2":23,"Value3":33}]

I tried numerous ways to compare two Lists but all of them fails eg.:
 - Fluent Assertion
 - CollectionAssert

When I inspect both List in debug they are identical.
I know it's probably trivial but I could find any solution online, thanks in advance.

Body:
You should implement the Equals method for the PointOnChart class, something like this:

public override bool Equals(object other)
{
    if (object.ReferenceEquals(other, this)) return true;

    var obj = other as PointOnChart;

    if (obj == null) return false;

    return this.Timestamp == obj.Timestamp && this.Value1 == obj.Value1 && this.Value2 == obj.Value2 && this.Value3 == obj.Value3;
}

This way the SequenceEquals extension method will operate properly.


问:
PowerShell ForEach-Object elimination
Let's consider a collection of collections, and an operation that needs to be performed inside a pipeline on each element of the inner collection.

For the sake of simplicity, let it be an array of arrays, and the operation is simply printing to screen. For my question to be represented, let us also have an array whose elements are not collections:

```<code>$Array = "A", "B", "C"
$ArrayOfArrays = (1, 2, 3), (4, 5, 6), (7, 8, 9)
</code>```

We know that piping will break a collection down to elements, like this:

```<code>$Array | & {process {Write-Host $_}}
$ArrayOfArrays | & {process {Write-Host $_}}
</code>```

Now, to my surprise, when I run this, it is not breaking down the inner array to its elements:

$ArrayOfArrays | % -process {Write-Host $_} (1)

neither this:

$ArrayOfArrays | % -process {% -process {Write-Host $_}} (2)

(however this latter might seem an unnecessary attempt, seeing that (1) does not do that, but I tried it...)

I expected try (1) to do that, because I thought that piping does one breakdown, and when an element is received by ForEach-Object, it will further break it down, if it is a collection.

I could only solve it with inner piping:

$ArrayOfArrays | % -process {$_ | % -process {Write-Host $_}} (3)

however with this approach I can eliminate the ForEach-Object, of course:

$ArrayOfArrays | & {process {$_ | & {process {Write-Host $_}}}} (4)

So my 2 questions are:

1,

How to access an element of a collection that is in the collection
  in a pipeline, other than tries (3) and (4), or is this the only way
  to do that?

2,

If the only way to do what question 1 is asking is
  tries (3) and (4), then what is a valid use case of ForEach-Object,
  where it can not be eliminated? I mean it can be a logical case, but
  also performance vs a script block. The fact that it is nicer than a
  script block with one pair of braces less is just not really enough
  for me...

.

EDIT after Manuel Batsching's answer:

As the ForEach-Object returns a collection's elements after its processing, we can do this (I let go of Write-Host, maybe it wasn't a good arbitrary operation, so let it be GetType):

```<code>$ArrayOfArrays | % -process {$_} | & {process {$_.GetType()}}
</code>```

But we also know that if something returns a new object in the pipeline, it will trigger a breakdown if it is further piped and if it is a collection. So to do the breakdown, we can again eliminate ForEach-Object and do this:

```<code>$ArrayOfArrays | & {process {$_}} | & {process {$_.GetType()}}
</code>```

And this dummy operation can be syntactically reduced if I define a filter like this:

```<code>Filter §
{
    param (
            [Parameter (Mandatory = $True, ValueFromPipeline = $True)]
            [Object]
            $ToBeTriggeredForBreakDown
    ) # end param

    $ToBeTriggeredForBreakDown

}
</code>```

and use it like this:

```<code>$Array | § | & {process {$_.GetType()}}
$ArrayOfArrays | § | & {process {$_.GetType()}}

$ArrayOfArraysOfArrays = ((1, 2), (3, 4)), ((5, 6), (7, 8))
$ArrayOfArraysOfArrays | § | & {process {$_.GetType()}}
$ArrayOfArraysOfArrays | § | § | & {process {$_.GetType()}}
</code>```

So it is still hard to see for me when I would use ForEach-Object, it seems to me it is completely useless - except for reasons I look for in my questions.

.

EDIT after research:

Some collections provide their own methods, e.g. since v4 arrays have a ForEach method, so besides (3) and (4), one can do this (again a dummy operation, but with less code):

```<code>$ArrayOfArrays.ForEach{$_} | & {process {$_.GetType()}}
</code>```

so this partially covers question 1.

答:
In my understanding, the unwrapping of arrays is done, once they are passed down the pipeline or to the output stream.

You will see the this behaviour with all of the following approaches:

```<code>$ArrayOfArrays | % -process { $_ }
$ArrayOfArrays | & { process { $_ } }
foreach ($arr in $ArrayOfArrays) { $arr }
</code>```

Now what ruins the unwrapping in your example is the Write-Host cmdlet. As this cmdlet is writing not to the output stream but to your console, it casts the input object to [string]. That is why you see a string represenation of the inner arrays on your console.

Replace Write-Host with Write-Output and the inner arrays will be properly unwrapped:

```<code> PS> $ArrayOfArrays | % -process { Write-Output $_ }
1
2
3
4
5
6
7
8
9
</code>```

EDIT:

You can use a debugger to determine exactly, where the unwrapping is done. Use for example the following code in VSCode:

```<code>$ArrayOfArrays = (1, 2, 3), (4, 5, 6), (7, 8, 9)
$foo = $null
$foo = $ArrayOfArrays | % { Write-Output $_ }
</code>```

Set a breakpoint to the line $foo = $null, add the variables $foo and $_ to the watchlist, hit F5 to start the debugger and watch the variables change, while you hit F11 to step into the individual processing steps.

$_ will show the inner array which is the current element in the pipeline.

$foo will receive only the unwrapped elements after the pipeline execution ends

Title: PowerShell ForEach-Object elimination

Body:
Let's consider a collection of collections, and an operation that needs to be performed inside a pipeline on each element of the inner collection.

For the sake of simplicity, let it be an array of arrays, and the operation is simply printing to screen. For my question to be represented, let us also have an array whose elements are not collections:

$Array = "A", "B", "C"
$ArrayOfArrays = (1, 2, 3), (4, 5, 6), (7, 8, 9)

We know that piping will break a collection down to elements, like this:

$Array | & {process {Write-Host $_}}
$ArrayOfArrays | & {process {Write-Host $_}}

Now, to my surprise, when I run this, it is not breaking down the inner array to its elements:

$ArrayOfArrays | % -process {Write-Host $_} (1)

neither this:

$ArrayOfArrays | % -process {% -process {Write-Host $_}} (2)

(however this latter might seem an unnecessary attempt, seeing that (1) does not do that, but I tried it...)

I expected try (1) to do that, because I thought that piping does one breakdown, and when an element is received by ForEach-Object, it will further break it down, if it is a collection.

I could only solve it with inner piping:

$ArrayOfArrays | % -process {$_ | % -process {Write-Host $_}} (3)

however with this approach I can eliminate the ForEach-Object, of course:

$ArrayOfArrays | & {process {$_ | & {process {Write-Host $_}}}} (4)

So my 2 questions are:

1,

How to access an element of a collection that is in the collection
  in a pipeline, other than tries (3) and (4), or is this the only way
  to do that?

2,

If the only way to do what question 1 is asking is
  tries (3) and (4), then what is a valid use case of ForEach-Object,
  where it can not be eliminated? I mean it can be a logical case, but
  also performance vs a script block. The fact that it is nicer than a
  script block with one pair of braces less is just not really enough
  for me...

.

EDIT after Manuel Batsching's answer:

As the ForEach-Object returns a collection's elements after its processing, we can do this (I let go of Write-Host, maybe it wasn't a good arbitrary operation, so let it be GetType):

$ArrayOfArrays | % -process {$_} | & {process {$_.GetType()}}

But we also know that if something returns a new object in the pipeline, it will trigger a breakdown if it is further piped and if it is a collection. So to do the breakdown, we can again eliminate ForEach-Object and do this:

$ArrayOfArrays | & {process {$_}} | & {process {$_.GetType()}}

And this dummy operation can be syntactically reduced if I define a filter like this:

Filter §
{
    param (
            [Parameter (Mandatory = $True, ValueFromPipeline = $True)]
            [Object]
            $ToBeTriggeredForBreakDown
    ) # end param

    $ToBeTriggeredForBreakDown

}

and use it like this:

$Array | § | & {process {$_.GetType()}}
$ArrayOfArrays | § | & {process {$_.GetType()}}

$ArrayOfArraysOfArrays = ((1, 2), (3, 4)), ((5, 6), (7, 8))
$ArrayOfArraysOfArrays | § | & {process {$_.GetType()}}
$ArrayOfArraysOfArrays | § | § | & {process {$_.GetType()}}

So it is still hard to see for me when I would use ForEach-Object, it seems to me it is completely useless - except for reasons I look for in my questions.

.

EDIT after research:

Some collections provide their own methods, e.g. since v4 arrays have a ForEach method, so besides (3) and (4), one can do this (again a dummy operation, but with less code):

$ArrayOfArrays.ForEach{$_} | & {process {$_.GetType()}}

so this partially covers question 1.

Body:
In my understanding, the unwrapping of arrays is done, once they are passed down the pipeline or to the output stream.

You will see the this behaviour with all of the following approaches:

$ArrayOfArrays | % -process { $_ }
$ArrayOfArrays | & { process { $_ } }
foreach ($arr in $ArrayOfArrays) { $arr }

Now what ruins the unwrapping in your example is the Write-Host cmdlet. As this cmdlet is writing not to the output stream but to your console, it casts the input object to [string]. That is why you see a string represenation of the inner arrays on your console.

Replace Write-Host with Write-Output and the inner arrays will be properly unwrapped:

 PS> $ArrayOfArrays | % -process { Write-Output $_ }
1
2
3
4
5
6
7
8
9

EDIT:

You can use a debugger to determine exactly, where the unwrapping is done. Use for example the following code in VSCode:

$ArrayOfArrays = (1, 2, 3), (4, 5, 6), (7, 8, 9)
$foo = $null
$foo = $ArrayOfArrays | % { Write-Output $_ }

Set a breakpoint to the line $foo = $null, add the variables $foo and $_ to the watchlist, hit F5 to start the debugger and watch the variables change, while you hit F11 to step into the individual processing steps.

$_ will show the inner array which is the current element in the pipeline.

$foo will receive only the unwrapped elements after the pipeline execution ends


问:
What unix command can we use to append some text to a specific line in a file?
Does anyone know of a series of unix commands that allows someone to append some text to the end of a specific line in a file?

eg

Line 1

Line 2

Line 3

Line 4

I wish to append the text ", extra information" to Line 3 so that the File will now look like this:

Line 1

Line 2

Line 3, extra information

Line 4

答:
Perl:

```<code>perl -p -e's{\n}{, extra information\n} if $. ==3' myfile
</code>```

$. is the line number

OwnerDisplayName: Alex Wong

ContentLicense: CC BY-SA 2.5

Body:
Perl:

perl -p -e's{\n}{, extra information\n} if $. ==3' myfile

$. is the line number

OwnerDisplayName: mirod


问:
Windows initial execution context
Once Windows has loaded an executable in memory and transfert execution to the entry point, do values in registers and stack are meaningful? If so, where can I find more informations about it?</p>

答:
Chapter 5 of Windows Internals Fifth Edition covers the mechanism of Windows creating a process in detail. That would give you more information about Windows loading an executable in memory and transferring execution to the entry point.

I found this up-to-date reference that covers how registers are used in various calling conventions on various operating systems and by various compilers. It's quite detailed, and seems comprehensive:
Agner Fog's Calling Conventions document

Title: Windows initial execution context


问:
How to read color specific pixels from a site?
There is a site on which the rectangles are located.

You need to find out their color and output it to the console as RGB.

Site example:

It is important that the pixels are read by coordinates. This means that I entered the coordinates of the first rectangle, the second one and so on, and then the colors were read from these coordinates.

An example of what should turn out in the console (design does not matter):

答:
Basically in pure Python it can't be done. But you can use javascript to achieve it.

Python:

```<code># pip install pywebview

import webview

webview.create_window('your_url')
rgb = webview.evaluate_js('find_color_by_coords('+x+', '+y+');')
print(rgb)
</code>```

JavaScript (function hexToRgb was taken from here):

```<code>function find_color_by_coords(x, y) {
    const hexToRgb = hex =>
        hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i
             ,(m, r, g, b) => '#' + r + r + g + g + b + b)
          .substring(1).match(/.{2}/g)
          .map(x => parseInt(x, 16))

    elem = document.elementFromPoint(x, y);
    return hexToRgb(elem.style.background);
}
</code>```

Please notice that I couldn't check this code, so there could be mistakes.

Body:
Basically in pure Python it can't be done. But you can use javascript to achieve it.

Python:

# pip install pywebview

import webview

webview.create_window('your_url')
rgb = webview.evaluate_js('find_color_by_coords('+x+', '+y+');')
print(rgb)

JavaScript (function hexToRgb was taken from here):

function find_color_by_coords(x, y) {
    const hexToRgb = hex =>
        hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i
             ,(m, r, g, b) => '#' + r + r + g + g + b + b)
          .substring(1).match(/.{2}/g)
          .map(x => parseInt(x, 16))

    elem = document.elementFromPoint(x, y);
    return hexToRgb(elem.style.background);
}

Please notice that I couldn't check this code, so there could be mistakes.


问:
Run-length decompression using C++
I have a text file with a string which I encoded.

Let's say it is: aaahhhhiii kkkjjhh ikl wwwwwweeeett

Here the code for encoding, which works perfectly fine:

```<code>void Encode(std::string &inputstring, std::string &outputstring)
{
    for (int i = 0; i < inputstring.length(); i++) {
        int count = 1;
        while (inputstring[i] == inputstring[i+1]) {
            count++;
            i++;
        }
        if(count <= 1) {
            outputstring += inputstring[i];
        } else {
            outputstring += std::to_string(count);
            outputstring += inputstring[i];
        }
    }
}
</code>```

Output is as expected: 3a4h3i 3k2j2h ikl 6w4e2t

Now, I'd like to decompress the output - back to original.

And I am struggling with this since a couple days now.

My idea so far:

```<code>void Decompress(std::string &compressed, std::string &original)
{
    char currentChar = 0;
    auto n = compressed.length();
    for(int i = 0; i < n; i++) {

        currentChar = compressed[i++];

        if(compressed[i] <= 1) {
            original += compressed[i];
        } else if (isalpha(currentChar)) {
            //
        } else {
            //
            int number = isnumber(currentChar).....
            original += number;
        }
    }
}
</code>```

I know my Decompress function seems a bit messy, but I am pretty lost with this one.
Sorry for that.

Maybe there is someone out there at stackoverflow who would like to help a lost and beginner soul.

Thanks for any help, I appreciate it.

答: The decompression can't possibly work in an unambiguous way because you didn't define a sentinel character; i.e. given the compressed stream it's impossible to determine whether a number is an original single number or it represents the repeat RLE command. I would suggest using '0' as the sentinel char. While encoding, if you see '0' you just output 010. Any other char X will translate to 0NX where N is the repeat byte counter. If you go over 255, just output a new RLE repeat command

Title: Run-length decompression using C++

Body:
I have a text file with a string which I encoded.

Let's say it is: aaahhhhiii kkkjjhh ikl wwwwwweeeett

Here the code for encoding, which works perfectly fine:

void Encode(std::string &inputstring, std::string &outputstring)
{
    for (int i = 0; i < inputstring.length(); i++) {
        int count = 1;
        while (inputstring[i] == inputstring[i+1]) {
            count++;
            i++;
        }
        if(count <= 1) {
            outputstring += inputstring[i];
        } else {
            outputstring += std::to_string(count);
            outputstring += inputstring[i];
        }
    }
}

Output is as expected: 3a4h3i 3k2j2h ikl 6w4e2t

Now, I'd like to decompress the output - back to original.

And I am struggling with this since a couple days now.

My idea so far:

void Decompress(std::string &compressed, std::string &original)
{
    char currentChar = 0;
    auto n = compressed.length();
    for(int i = 0; i < n; i++) {

        currentChar = compressed[i++];

        if(compressed[i] <= 1) {
            original += compressed[i];
        } else if (isalpha(currentChar)) {
            //
        } else {
            //
            int number = isnumber(currentChar).....
            original += number;
        }
    }
}

I know my Decompress function seems a bit messy, but I am pretty lost with this one.
Sorry for that.

Maybe there is someone out there at stackoverflow who would like to help a lost and beginner soul.

Thanks for any help, I appreciate it.


问:
Angular - How to use the result of an observable, inside another observable?
I have an observable, to which I subscribe and I do some operations on the result value (a reduce() and a map()).

But inside that observable I would like to call another observable that just returns a number, and I need that number in my map().

Here an example:

```<code>this.getYearlyDataByIdAndYear(292, 2019).subscribe(result = > {
        let ferienSaldo: FerienSaldo;
        this.getVacationsYearlyDataByIdAndYear(292, 2019).subscribe(result = > {
            // this is my inner observable and I need to save this result, and use it below!
            ferienSaldo = result;
        });
        this.yearlyOverview = result.reduce < Array < YearlyOverview >> ((prev, current, i, all) = > {
                // some code that is not important
                let overviewVar: YearlyOverview = {
                    saldo: ferienSaldo.value
                };
                prev.push(newTLOverview);
            }
            return prev;
        }, new Array < YearlyOverview > ())
});
</code>```

basically as you can see, inside my initial Observable, I will need the value from the inner one, and I will copy that value inside my reduce() to assign it to a new object I'm creating!

The issue with my code is, the "let ferienSaldo" variable cannot be accessed inside the second observable, and besides that I'm sure there is a better way to combine this!

答:
It looks like the two calls don't depend on each other, so you can run them in parallel in a forkJoin

```<code>forkJoin([
  this.getYearlyDataByIdAndYear(292, 2019).pipe(
    tap(result => this.result1 = result)
  ),
  this.getVacationsYearlyDataByIdAndYear(292, 2019).pipe(
    tap(result => this.result2 = result)
  )
]).subscribe(() => {
  // process this.result1 and this.result2
  // TODO: more meaningful property names
});
</code>```

Edit:

I used tap because I like to keep my subscribe body clean. You can also return the results in an array to subscribe:

```<code>forkJoin([
  this.getYearlyDataByIdAndYear(292, 2019),
  this.getVacationsYearlyDataByIdAndYear(292, 2019)
]).subscribe(result => {
  // process result[0] and result[1]
});
</code>```

The second option looks cleaner in a trivial example like this, but I find it's annoying to couple your subscribe body to the array indices - especially when you make changes.

Body:
I have an observable, to which I subscribe and I do some operations on the result value (a reduce() and a map()).

But inside that observable I would like to call another observable that just returns a number, and I need that number in my map().

Here an example:

this.getYearlyDataByIdAndYear(292, 2019).subscribe(result = > {
        let ferienSaldo: FerienSaldo;
        this.getVacationsYearlyDataByIdAndYear(292, 2019).subscribe(result = > {
            // this is my inner observable and I need to save this result, and use it below!
            ferienSaldo = result;
        });
        this.yearlyOverview = result.reduce < Array < YearlyOverview >> ((prev, current, i, all) = > {
                // some code that is not important
                let overviewVar: YearlyOverview = {
                    saldo: ferienSaldo.value
                };
                prev.push(newTLOverview);
            }
            return prev;
        }, new Array < YearlyOverview > ())
});

basically as you can see, inside my initial Observable, I will need the value from the inner one, and I will copy that value inside my reduce() to assign it to a new object I'm creating!

The issue with my code is, the "let ferienSaldo" variable cannot be accessed inside the second observable, and besides that I'm sure there is a better way to combine this!

Body:
It looks like the two calls don't depend on each other, so you can run them in parallel in a forkJoin

forkJoin([
  this.getYearlyDataByIdAndYear(292, 2019).pipe(
    tap(result => this.result1 = result)
  ),
  this.getVacationsYearlyDataByIdAndYear(292, 2019).pipe(
    tap(result => this.result2 = result)
  )
]).subscribe(() => {
  // process this.result1 and this.result2
  // TODO: more meaningful property names
});

Edit:

I used tap because I like to keep my subscribe body clean. You can also return the results in an array to subscribe:

forkJoin([
  this.getYearlyDataByIdAndYear(292, 2019),
  this.getVacationsYearlyDataByIdAndYear(292, 2019)
]).subscribe(result => {
  // process result[0] and result[1]
});

The second option looks cleaner in a trivial example like this, but I find it's annoying to couple your subscribe body to the array indices - especially when you make changes.


问:
return RedirectToAction not Functioning

I already simple checking the name and pass(=true)

When return RedirectToAction("Index", "Home"); ---> not function

I don't know what wrongs! No error show

Please help.. Thx a lot.

答:
It is probably working.

However, you most likely have Cookie authentication or similar activated which means that MVC will redirect the user back to the login page since the authentication cookie cannot be found.

Before returning the redirect, you must create the cookie.

How you do that depends on which version of MVC that you are running.

Here is for MVC5:
How to set a Auth cookie in asp.net 5

Add the following before return RedirectToAction("Index", "Home");

```<code>   // Which claims depends on what kind of information you want to store about the user
   var claims = new[] { new Claim(ClaimTypes.Name, name) };
    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
    Context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
</code>```

And a ASP.NET Core MVC example is available here: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-3.1

Title: return RedirectToAction not Functioning

Body:
It is probably working.

However, you most likely have Cookie authentication or similar activated which means that MVC will redirect the user back to the login page since the authentication cookie cannot be found.

Before returning the redirect, you must create the cookie.

How you do that depends on which version of MVC that you are running.

Here is for MVC5:
How to set a Auth cookie in asp.net 5

Add the following before return RedirectToAction("Index", "Home");

   // Which claims depends on what kind of information you want to store about the user
   var claims = new[] { new Claim(ClaimTypes.Name, name) };
    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
    Context.Authentication.SignIn(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

And a ASP.NET Core MVC example is available here: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-3.1


问:
error NG6002: Appears in the NgModule.imports of <module>, but could not be resolved to an NgModule class
I just updated from Angular 8.2 to 9.

Everything works well if I disable ivy, but when it's enabled I'm getting a lot of errors that seems to be kind of obscure, at least I can't find any results when googling it.

I'm quite sure I've done everything needed for an update, i.e. changed the lazyloading to use dynamic imports and fixed Angular Material import paths etc.

I will also include my package.json dependencies here

```<code>  "dependencies": {
    "@angular/animations": "^9.0.0",
    "@angular/cdk": "^9.0.0",
    "@angular/common": "^9.0.0",
    "@angular/compiler": "^9.0.0",
    "@angular/core": "^9.0.0",
    "@angular/fire": "^5.4.2",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "^9.0.0",
    "@angular/http": "^7.2.15",
    "@angular/material": "^9.0.0",
    "@angular/material-moment-adapter": "^8.2.2",
    "@angular/platform-browser": "^9.0.0",
    "@angular/platform-browser-dynamic": "^9.0.0",
    "@angular/platform-server": "^9.0.0",
    "@angular/router": "^9.0.0",
    "@ngrx/effects": "^8.3.0",
    "@ngrx/entity": "^8.3.0",
    "@ngrx/router-store": "^8.3.0",
    "@ngrx/store": "^8.3.0",
    "@zxing/ngx-scanner": "^2.0.1",
    "angular-resizable-element": "^3.2.4",
    "angular-resize-event": "^1.1.1",
    "angular2-highcharts": "^0.5.5",
    "core-js": "^3.6.4",
    "detect-browser": "^4.7.0",
    "firebase": "^7.8.0",
    "google-polyline": "^1.0.3",
    "hammerjs": "^2.0.8",
    "highcharts": "^8.0.0",
    "i18n-iso-countries": "^4.3.1",
    "leaflet": "^1.5.1",
    "mapbox-gl": "^1.4.0",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.26",
    "ng-pick-datetime": "^6.0.7",
    "ngrx-store-freeze": "^0.2.3",
    "ngx-cacheable": "^1.3.2",
    "ngx-cookie-service": "^2.2.0",
    "ngx-csv": "^0.3.1",
    "ngx-file-drop": "^8.0.8",
    "ngx-infinite-scroll": "^0.8.4",
    "papaparse": "^5.0.2",
    "request": "^2.87.0",
    "request-promise": "^4.2.2",
    "rxjs": "^6.5.4",
    "rxjs-compat": "^6.3.3",
    "typescript-string-operations": "^1.3.1",
    "web-animations-js": "^2.3.2",
    "zone.js": "^0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.900.1",
    "@angular/cli": "^9.0.0",
    "@angular/compiler-cli": "^9.0.0",
    "@angular/language-service": "^9.0.0",
    "@ngrx/store-devtools": "^8.3.0",
    "@types/body-parser": "^1.17.0",
    "@types/cors": "^2.8.4",
    "@types/detect-browser": "^4.0.0",
    "@types/express": "^4.11.1",
    "@types/firebase": "^3.2.1",
    "@types/helmet": "0.0.37",
    "@types/jasmine": "^3.5.4",
    "@types/jasminewd2": "~2.0.3",
    "@types/leaflet": "^1.2.7",
    "@types/lodash": "^4.14.109",
    "@types/node": "^13.7.1",
    "@types/request": "^2.47.0",
    "@types/request-promise": "^4.1.41",
    "codelyzer": "^5.2.1",
    "concurrently": "^3.5.1",
    "del-cli": "^1.1.0",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "^3.1.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "^3.1.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "protractor": "^5.4.3",
    "puppeteer": "^2.0.0",
    "rxjs-tslint": "^0.1.7",
    "ts-node": "~5.0.1",
    "tslint": "^6.0.0",
    "typescript": "3.6.4",
    "webpack": "^4.41.6"
  },
  "peerDependencies": {
    "typescript": "3.6.4",
    "tslib": "1.10.0"
  },
</code>```

And errors itself that I'm getting:

I have cleared my node_modules and package-lock.json and ran npm install again

EDIT: maybe also important to note that it's compiling and running with ng serve but when I try to build it or run with AOT ng serve -aot then I get the errors.

答:
i've fixed thi by execute this command on root of the project:</p>

```<code>npx ngcc && ngcc -s dist
</code>```

Body:
I just updated from Angular 8.2 to 9.

Everything works well if I disable ivy, but when it's enabled I'm getting a lot of errors that seems to be kind of obscure, at least I can't find any results when googling it.

I'm quite sure I've done everything needed for an update, i.e. changed the lazyloading to use dynamic imports and fixed Angular Material import paths etc.

I will also include my package.json dependencies here

  "dependencies": {
    "@angular/animations": "^9.0.0",
    "@angular/cdk": "^9.0.0",
    "@angular/common": "^9.0.0",
    "@angular/compiler": "^9.0.0",
    "@angular/core": "^9.0.0",
    "@angular/fire": "^5.4.2",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "^9.0.0",
    "@angular/http": "^7.2.15",
    "@angular/material": "^9.0.0",
    "@angular/material-moment-adapter": "^8.2.2",
    "@angular/platform-browser": "^9.0.0",
    "@angular/platform-browser-dynamic": "^9.0.0",
    "@angular/platform-server": "^9.0.0",
    "@angular/router": "^9.0.0",
    "@ngrx/effects": "^8.3.0",
    "@ngrx/entity": "^8.3.0",
    "@ngrx/router-store": "^8.3.0",
    "@ngrx/store": "^8.3.0",
    "@zxing/ngx-scanner": "^2.0.1",
    "angular-resizable-element": "^3.2.4",
    "angular-resize-event": "^1.1.1",
    "angular2-highcharts": "^0.5.5",
    "core-js": "^3.6.4",
    "detect-browser": "^4.7.0",
    "firebase": "^7.8.0",
    "google-polyline": "^1.0.3",
    "hammerjs": "^2.0.8",
    "highcharts": "^8.0.0",
    "i18n-iso-countries": "^4.3.1",
    "leaflet": "^1.5.1",
    "mapbox-gl": "^1.4.0",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.26",
    "ng-pick-datetime": "^6.0.7",
    "ngrx-store-freeze": "^0.2.3",
    "ngx-cacheable": "^1.3.2",
    "ngx-cookie-service": "^2.2.0",
    "ngx-csv": "^0.3.1",
    "ngx-file-drop": "^8.0.8",
    "ngx-infinite-scroll": "^0.8.4",
    "papaparse": "^5.0.2",
    "request": "^2.87.0",
    "request-promise": "^4.2.2",
    "rxjs": "^6.5.4",
    "rxjs-compat": "^6.3.3",
    "typescript-string-operations": "^1.3.1",
    "web-animations-js": "^2.3.2",
    "zone.js": "^0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.900.1",
    "@angular/cli": "^9.0.0",
    "@angular/compiler-cli": "^9.0.0",
    "@angular/language-service": "^9.0.0",
    "@ngrx/store-devtools": "^8.3.0",
    "@types/body-parser": "^1.17.0",
    "@types/cors": "^2.8.4",
    "@types/detect-browser": "^4.0.0",
    "@types/express": "^4.11.1",
    "@types/firebase": "^3.2.1",
    "@types/helmet": "0.0.37",
    "@types/jasmine": "^3.5.4",
    "@types/jasminewd2": "~2.0.3",
    "@types/leaflet": "^1.2.7",
    "@types/lodash": "^4.14.109",
    "@types/node": "^13.7.1",
    "@types/request": "^2.47.0",
    "@types/request-promise": "^4.1.41",
    "codelyzer": "^5.2.1",
    "concurrently": "^3.5.1",
    "del-cli": "^1.1.0",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "^3.1.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "^3.1.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "protractor": "^5.4.3",
    "puppeteer": "^2.0.0",
    "rxjs-tslint": "^0.1.7",
    "ts-node": "~5.0.1",
    "tslint": "^6.0.0",
    "typescript": "3.6.4",
    "webpack": "^4.41.6"
  },
  "peerDependencies": {
    "typescript": "3.6.4",
    "tslib": "1.10.0"
  },

And errors itself that I'm getting:

I have cleared my node_modules and package-lock.json and ran npm install again

EDIT: maybe also important to note that it's compiling and running with ng serve but when I try to build it or run with AOT ng serve -aot then I get the errors.

Body:
i've fixed thi by execute this command on root of the project:

npx ngcc && ngcc -s dist


问:
Button opacity / alpha setting
I want to change the alpha when the user pressed the button. I have used the below code and it works.
However, I am having to write this line of code for every button I connect to the assistance.

Is there any way that I can create a method/class/function to enable all buttons to have this function?

```<code>@IBAction func sundayButton(_ sender: UIButton) {
    sender.alpha = 0.5
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {sender.alpha = 1.0

    }
}
</code>```

答:
You can write extention on Button and call that on every button

extension UIButton {
    func setAlpha() {
        self.alpha = 0.5
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
            self.alpha = 1.0
        }
    }
}

```

<p>call it this way:</p>

```myButton.setAlpha()

```

Title: Button opacity / alpha setting

Body:
I want to change the alpha when the user pressed the button. I have used the below code and it works.
However, I am having to write this line of code for every button I connect to the assistance.

Is there any way that I can create a method/class/function to enable all buttons to have this function?

@IBAction func sundayButton(_ sender: UIButton) {
    sender.alpha = 0.5
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {sender.alpha = 1.0

    }
}

Body:
You can write extention on Button and call that on every button

extension UIButton {
    func setAlpha() {
        self.alpha = 0.5
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
            self.alpha = 1.0
        }
    }
}

call it this way:

myButton.setAlpha()


问:
How can I get the button text to display my cell text?
I create an asp.net GridView and I bind some simple data. Some strings have newlines in \n

This displays as a new line when I add the right css to the table cell : white-space:pre-wrap;

But then I cycle through my GridView and add a button in each cell like so:

```<code>    protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                Button btn = new Button();
                btn.CssClass = "Button";
                btn.Text = cell.Text;
                cell.Controls.Add(btn);
            }
        }
    }
</code>```

The text added to the button isn't the same format. All the   have become visible and the newlines \n aren't working. At first I thought I needed to just reapply the pre-wrap css but I tried it and it didn't affect anything. Also, I think the problem is further up the chain in the btn.Text = cell.Text line because of the   becoming visible.

Does button control text not behave like the default cell text? Maybe I can replace buttons with labels or something...

答:
You are using a Button type which will result in the following HTML

    <input type="button" value="Press here" />
```

<p>the <code>input</code> html tag can't contains HTML but just text. If you want to add html inside your button you can use a <code>LinkButton</code> which will result in the following HTML</p>

<pre class="lang-html prettyprint-override"><code>
        Press here

</code>```

and the a tag can contain any HTML code or CSS style.

```<code>foreach (TableCell cell in e.Row.Cells)
{
    LinkButton btn = new LinkButton();
    btn.CssClass = "Button";
    btn.Text = cell.Text;
    cell.Controls.Add(btn);
}
</code>```

Body:
I create an asp.net GridView and I bind some simple data. Some strings have newlines in \n

This displays as a new line when I add the right css to the table cell : white-space:pre-wrap;

But then I cycle through my GridView and add a button in each cell like so:

    protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (TableCell cell in e.Row.Cells)
            {
                Button btn = new Button();
                btn.CssClass = "Button";
                btn.Text = cell.Text;
                cell.Controls.Add(btn);
            }
        }
    }

The text added to the button isn't the same format. All the   have become visible and the newlines \n aren't working. At first I thought I needed to just reapply the pre-wrap css but I tried it and it didn't affect anything. Also, I think the problem is further up the chain in the btn.Text = cell.Text line because of the   becoming visible.

Does button control text not behave like the default cell text? Maybe I can replace buttons with labels or something...

Body:
You are using a Button type which will result in the following HTML

    <input type="button" value="Press here" />

the input html tag can't contains HTML but just text. If you want to add html inside your button you can use a LinkButton which will result in the following HTML

    <a href="...">
        Press here
    </a>

and the a tag can contain any HTML code or CSS style.

foreach (TableCell cell in e.Row.Cells)
{
    LinkButton btn = new LinkButton();
    btn.CssClass = "Button";
    btn.Text = cell.Text;
    cell.Controls.Add(btn);
}