Posts

Showing posts from April, 2020

Add Unique Validation On A Condition In Request Validation Laravel Code Example

Example 1: laravel unique validation /** * Store a new blog post. * * @param Request $request * @return Response */ public function store ( Request $request ) { $validatedData = $request - > validate ( [ 'title' => 'required|unique:posts|max:255' , 'body' => 'required' , ] ) ; // The blog post is valid... } Example 2: set unique value validation for laravel form request use Illuminate\Validation\Rule ; public function rules ( ) { return [ 'title' => [ 'required' , Rule : : unique ( 'posts' , 'title' ) - > ignore ( $ this - > post ) ] ] ; }

Button Disabled Javascript Code Example

Example 1: javascript disable button //disable the button document . getElementById ( BUTTON_ID ) . disabled = true ; //reable the button document . getElementById ( BUTTON_ID ) . removeAttribute ( 'disabled' ) ; Example 2: javascript how to disable a button //Using Javascript //Disabling a html button document . getElementById ( "Button" ) . disabled = true ; //Enabling a html button document . getElementById ( "Button" ) . disabled = false ; //Using jQuery //Disabling a html button $ ( '#Button' ) . attr ( 'disabled' , 'disabled' ) ; //Enabling a html button $ ( '#Button' ) . removeAttr ( 'disabled' ) ; Example 3: html button disabled < button type = "button" disabled > This button is disabled < / button > Example 4: javascript disable button document . getElementById ( BUTTON_ID ) . disabled = true ; Example 5: enable html button $ ( '#Button' ) .

AngularJS Ng-class Multiple Conditions With OR Operator

Answer : Try this. <a href="" ng-click="addFavorite(myfav.id);favorite=!favorite"> <i class="fa orange" ng-class="{'fa-star': favorite || fav==myfav.id, 'fa-star-o': !favorite}"></i> No need the brackets. Once you have to add some logic behind ng-class it's always better to stick to using the controller to do that. You can do it two of either ways: JSON syntax (same as in your HTML, just more readable) or obviously JavaScript. HTML (JSON) Syntax HTML <i ng-class="getFavClassIcon(myFav.id)"></i> JS $scope.getFavClassIcon= function (favId) { return { 'fa-star-o' : !$scope.favorite, 'fa-star' : $scope.favorite || $scope.fav === favId }; }; Good Old IF-statement (JavaScript) HTML <i ng-class="getFavClassIcon(myFav.id)"></i> JS $scope.getFavClassIcon= function (favId) { if (!$scope.favori

Chrome Extension Content Script Re-injection After Upgrade Or Install

Answer : There's a way to allow a content script heavy extension to continue functioning after an upgrade, and to make it work immediately upon installation. Install The install method is to simply iterate through all tabs in all windows, and inject some scripts programmatically into tabs with matching URLs. Obviously, you have to do it in a background page or event page script declared in manifest.json: "background": { "scripts": ["background.js"] }, background.js: // Add a `manifest` property to the `chrome` object. chrome.manifest = chrome.app.getDetails(); var injectIntoTab = function (tab) { // You could iterate through the content scripts here var scripts = chrome.manifest.content_scripts[0].js; var i = 0, s = scripts.length; for( ; i < s; i++ ) { chrome.tabs.executeScript(tab.id, { file: scripts[i] }); } } // Get all windows chrome.windows.getAll({ populate: true }, func

How To Add Color Text In Discord Code Example

Example 1: css discord color guide Default : # 839496 ``` NoKeyWordsHere ``` Quote : # 586e75 ```brainfuck NoKeyWordsHere ``` Solarized Green : # 859900 ```CSS NoKeyWordsHere ``` Solarized Cyan : # 2 aa198 ```yaml NoKeyWordsHere ``` Solarized Blue : # 268 bd2 ```md NoKeyWordsHere ``` Solarized Yellow : #b58900 ```fix NoKeyWordsHere ``` Solarized Orange : #cb4b16 ```glsl NoKeyWordsHere ``` Solarized Red : #dc322f ```diff - NoKeyWordsHere ``` Example 2: css discord color guide And here is the escaped Default : # 839496 ``` This is a for statement ``` Quote : # 586e75 ```bash # This is a for statement ``` Solarized Green : # 859900 ```diff + This is a for statement ``` //Second Way to do it ```diff ! This is a for statement ``` Solarized Cyan : # 2 aa198 ```cs "This is a for statement" ``` ```cs 'This is a for statement' ``` Solarized Blue : # 268 bd2 ```ini [ This is a for statement ] ``` //Second Way to do it ```asciido

Checking The Gcc Version In A Makefile?

Answer : I wouldn't say its easy, but you can use the shell function of GNU make to execute a shell command like gcc --version and then use the ifeq conditional expression to check the version number and set your CFLAGS variable appropriately. Here's a quick example makefile: CC = gcc GCCVERSION = $(shell gcc --version | grep ^gcc | sed 's/^.* //g') CFLAGS = -g ifeq "$(GCCVERSION)" "4.4.3" CFLAGS += -Wtype-limits endif all: $(CC) $(CFLAGS) prog.c -o prog Edit: There is no ifgt . However, you can use the shell expr command to do a greater than comparison. Here's an example CC = gcc GCCVERSIONGTEQ4 := $(shell expr `gcc -dumpversion | cut -f1 -d.` \>= 4) CFLAGS = -g ifeq "$(GCCVERSIONGTEQ4)" "1" CFLAGS += -Wtype-limits endif all: $(CC) $(CFLAGS) prog.c -o prog To transform full 3-part gcc version (not only first digit) into numerical format, suitable for comparison (e.g. 40701 ) us

Array Reduce Mdn Code Example

Example 1: reduce javascript const sum = array . reduce ( ( accumulator , element ) => { return accumulator + element ; } , 0 ) ; // An example that will loop through an array adding // each element to an accumulator and returning it // The 0 at the end initializes accumulator to start at 0 // If array is [2, 4, 6], the returned value in sum // will be 12 (0 + 2 + 4 + 6) const product = array . reduce ( ( accumulator , element ) => { return accumulator * element ; } , 1 ) ; // Multiply all elements in array and return the total // Initialize accumulator to start at 1 // If array is [2, 4, 6], the returned value in product // will be 48 (1 * 2 * 4 * 6) Example 2: javascript reduce var array = [ 36 , 25 , 6 , 15 ] ; array . reduce ( function ( accumulator , currentValue ) { return accumulator + currentValue ; } , 0 ) ; // 36 + 25 + 6 + 15 = 82 Example 3: reduce() const array1 = [ 1 , 2 , 3 , 4 ] ; const reducer =

20 Inch To Cm Code Example

Example: inch to cm 1 inch = 2.54 cm

Are These 2 Resistors In Parallel?

Image
Answer : Redrawing schematics is a great way to analyze circuits, but also an exercise in why schematics are drawn in particular ways — to more clearly communicate to other engineers. simulate this circuit – Schematic created using CircuitLab The rearrangement above should be a little more clear. If you trace a path from one terminal of the battery to the other, you can hopefully see that there are two paths (the split occurs at the junctions on either side of R1). Series means one-after-another current flow (like a series of events or a television serial). Parallel means that current flows through two or more components at the same time (proportional to the component values). Just as when you measure voltage, where the value depends on your reference point, components can be series or parallel depending on what you are comparing them to: You could say: R2 is in series with the voltage source, or R2 forms a series-parallel circuit with R1 and R3, or R1 and

Android Studio Change Package Name Code Example

Example: android studio change package name In Android Studio , you can do this : For example , if you want to change com . example . app to my . awesome . game , then : In your Project pane , click on the little gear icon ( Gears icon ) Uncheck the Compact Empty Middle Packages option Compact Empty Middle Packages Your package directory will now be broken up into individual directories Individually select each directory you want to rename , and : Right - click it Select Refactor Click on Rename In the pop - up dialog , click on Rename Package instead of Rename Directory Enter the new name and hit Refactor Click Do Refactor in the bottom Allow a minute to let Android Studio update all changes Note : When renaming com in Android Studio , it might give a warning . In such case , select Rename All Enter image description here Now open your Gradle Build File ( build . gradle - Usually app or mobile

Aws Cli Query Contains Code Example

Example: aws cli filter vs query aws ec2 describe-volumes \ --filters Name=tag-key,Values="Name" Name=tag-value,Values="Test*" \ --query 'Volumes[*].{ID:VolumeId,Tag:Tags}'

Button Onclick Location.href Code Example

Example 1: javascript onclick href location onclick="location.href='unit_01.htm'" Example 2: html button link This is a button Example 3: buton html href Button Button Example 4: button with href onClick={() => {window.location.href="https://www.golfballs.com/"}}

Codeigniter Like Query Code Example

Example 1: codeigniter raw query $sql="Select * from my_table where 1"; $query = $this->db->query($SQL); return $query->result_array(); Example 2: where_in codeigniter $this->db->select('ae_users.employee_id, ae_users.emp_name, ae_users.emp_name2, ae_users.emp_name3'); $this->db->from('ae_users'); $this->db->where_in('ae_users.employee_id',$employee_ids); $query =$this->db->get(); if ($query->num_rows()) { return $query->result_array(); } else { return 0; } Example 3: codeigniter where_not_in $names = array('Frank', 'Todd', 'James'); $this->db->where_not_in('username', $names); // Produces: WHERE username NOT IN ('Frank', 'Todd', 'James') Example 4: codeigniter where order by $this->db->select('ae_users.employee_id, ae_users.emp_name, ae_users.emp_name2, ae_users.emp_n

Add Timestamp To Oh-my-zsh Robbyrussell Theme

Image
Answer : According to the zshmisc man page there are several % codes for date and time, eg: %D The date in yy-mm-dd format. %T Current time of day, in 24-hour format. %t %@ Current time of day, in 12-hour, am/pm format. %* Current time of day in 24-hour format, with seconds. %w The date in day-dd format. %W The date in mm/dd/yy format. %D{strftime-format} The last one allows codes listed in the strftime(3) man page. Edit your ~/.zshrc file and add at the end a new PROMPT value, eg: PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} %D %T % %{$reset_color%}' If you want add date/time to the right, you set RPROMPT local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' RPROMPT="[%D{%y/%m/%f}|%@]" I added this %D{%m/%f/%y}|%D{%L:%M:%S} to the main theme to disp

Centering A Div Css Code Example

Example 1: center a div in css .container { display: flex; justify-content: center; align-items: center; } Example 2: centering css elements // add to the parent element .parent { display: grid; place-items: center; } Example 3: how to center text in css .class { text-align: center; } Example 4: how to center a div .container { ... display: flex; justify-content: center; } Example 5: css center div <!-- Simple CSS CENTER DIV Example * See Fiddle in link for PoC * --> < div class = " parent " > < div class = " child " > < p > Eh Up Me Duck! </ p > </ div > </ div > < style > .parent { /* Just for aesthetics: see fiddle */ border : 1 px solid black ; padding : 2 px ; } .child { border : 1 px solid red ; width : 50 % ; /* This is where the magic happens */ margin-left : auto ; margin-right : auto ; /************

Autoclose Alert

Answer : jsFiddle Demo This functionality is not possible with an alert. However, you could use a div function tempAlert(msg,duration) { var el = document.createElement("div"); el.setAttribute("style","position:absolute;top:40%;left:20%;background-color:white;"); el.innerHTML = msg; setTimeout(function(){ el.parentNode.removeChild(el); },duration); document.body.appendChild(el); } Use this like this: tempAlert("close",1000); You can't close alert any how . But you can use div To show your alert MSG. function Mymsg(msg,duration) { var alt = document.createElement("div"); alt.setAttribute("style","position:absolute;top:50%;left:50%;background-color:white;"); alt.innerHTML = msg; setTimeout(function(){ alt.parentNode.removeChild(alt); },duration); document.body.appendChild(alt); } You can use as : Mymsg('close',2000) jsFiddle Demo Basically you

Apt Clean Cache Code Example

Example 1: apt clean cache sudo apt clean Example 2: remove all cache ubuntu $ sudo apt-get clean

Bootstrap Radio Button Yes No Code Example

Example: bootstrap radio buttons Bootstrap’s . button styles can be applied to other elements , such as < label > s , to provide checkbox or radio style button toggling . Add data - toggle = "buttons" to a . btn - group containing those modified buttons to enable their toggling behavior via JavaScript and add . btn - group - toggle to style the < input > s within your buttons . Note that you can create single input - powered buttons or groups of them . The checked state for these buttons is only updated via click event on the button . If you use another method to update the input—e . g . , with < input type = "reset" > or by manually applying the input’s checked property—you’ll need to toggle . active on the < label > manually . Note that pre - checked buttons require you to manually add the . active class to the input’s < label > . < div class = "btn-group-toggle" data - toggle = "buttons&qu

AngularJS 'scrollTop' Equivalent?

Answer : $window.pageYOffset This is property from service $window I don't believe there's anything in Angular to get the scroll position. Just use plain vanilla JS. You can retrieve the scrollTop property on any element. https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollTop document.body.scrollTop Fiddle for you: http://jsfiddle.net/cdwgsbq5/ Inject the $window into your controller and you can get the scroll position on scroll var windowEl = angular.element($window); var handler = function() { console.log(windowEl.scrollTop()) } windowEl.on('scroll', handler); Fiddle Adaptation from another stackoverflow answer