Category Archives: Code

Code is a question and answer site for professional and enthusiast programmers.

¿Como cargar un select seleccionado al editar?

Tengo un crud, al editar una fila, me aparecen una serie de campos, entre ellos un componente vue.js con un select, como puedo marcar que select estaba seleccionado al editar la fila. EL selec es dinamico, es decir al seleccionar un país, te aparece otro select con las comunidades de ese pais y al seleccionar una comunidad te aparecen las provincias de esa comunidad

  <template>
<div>
  <div class="form-group">
    <label for>Selecciona una Pais</label>
    <select name="country_id" class="form-control" v-model="country" v-on:change="cargarComunidades()">
        <option v-for="(item, index) in countries" :key="index" :value="item.id" :selected="(this.country == item.id) ? true : false">
            {{item.name}}
        </option>
    </select>
  </div>
  <div class="form-group">
    <label for>Selecciona una Comunidad</label>
    <select name="community_id" class="form-control" v-model="community" v-on:change="cargarProvincias()">
        <option v-for="(item, index) in communities" :key="index" :value="item.id" :selected="(this.community == item.id) ? true : false">
            {{item.name}}
        </option>
    </select>
  </div>
  <div class="form-group">
    <label for>Selecciona una Provincia</label>                  
    <select name="province_id" class="form-control" v-model="province">
        <option v-for="(item, index) in provinces" :key="index" :value="item.id" :selected="(this.province == item.id) ? true : false">
            {{item.name}}
        </option>
    </select>
  </div>
</div>

read more

Change colour of a menu option depend a value

I’m new in ASP.NET with MVC. My application have a menu options and I need to change the color of a menu option depend of the selection of a textbox.

In the controller file I wrote this:

[HttpPost]
public ActionResult Rise(int rise)
{
Session[“Var1”] = rise;
if (rise != 0)
{
ViewBag.Var1= “class = active”;
}
else
{
ViewBag.Var1 = “class = visited”;
}
return View();
}
In my css file I wrote this:

read more

Different Output of Pyspark code on same set of data while multiple runs

I have write one pyspark function,but when i run multiple times its giving me every time diffrent outputs
on same set of input data.

-pyspark Function

def give_percentile(plat,metrics,perc):
df_perc = df_final.filter(df_final.platform.like('%' + plat + '%'))
df_perc = df_perc.filter(df_final[metrics]!=0)
percentile_val = df_perc.approxQuantile(metrics, [perc], 0.05)
if len(percentile_val)>0:
    percentile_val = float(percentile_val[0])
else:
    percentile_val = float(0)
return percentile_val

Calling Function-

   df_agg = sqlContext.createDataFrame([Row(platform='iOS',
                                        percentile_page_load_50=give_percentile("iOS","page_load",0.5),
                                        percentile_time_diff_50=give_percentile("iOS","session_duration",0.5)),
                                        Row(platform='Android',
                                        percentile_page_load_50=give_percentile("Android","page_load",0.5),
                                        percentile_time_diff_50=give_percentile("Android","session_duration",0.5)),
                                        Row(platform='Web',
                                        percentile_page_load_50=give_percentile("Web","page_load",0.5),
                                        percentile_time_diff_50=give_percentile("Web","session_duration",0.5)))

read more

Call to a member function has() on string in laravel

I am working for user authentication. When a user provides invalid email or password, I want to redirect it to login.blade.php with a flash error message.

Auth/LoginController:

public function login(Request $request)
{
$user=User::where(’email’,$request->email)->first();

    if(!is_null($user))
    {
        if($user->status==1)
        {
            if(Auth::guard('web')->attempt(['email'=>$request->email,'password'=>$request->password],$request->remember))

                return redirect()->intended(route('index'));

            }

        }

        else
        {

            if(Auth::guard('web')->attempt(['email'=>$request->email,'password'=>$request->password],$request->remember))
            {
                if(Auth::check())
                {
                    Auth::logout();
                }
            $user->notify(new VerifyRegistration($user));
            session()->flash('success','A new confirmation mail has sent to you...Please check and confirm your email');
            return redirect('/');
            }
            else
            {
                session()->flash('errors','Password is incorrect!!');
                return redirect()->route('login');
            }
        }
    }
    else
    {

        session()->flash('errors','Email or Password is incorrect!!');
            return redirect('/login');
    }

read more