Posts

Showing posts from October, 2009

An Array Of Elements Can Be Sorted Using The Heap Sort Algorithm. The First Step Of The Heap Sort Algorithm Is To Convert The Array Into A Maximum Heap. If The Following Array Is To Be Sorted: Code Example

Example 1: heap sort // @see https://www.youtube.com/watch?v=H5kAcmGOn4Q function heapify(list, size, index) { let largest = index; let left = index * 2 + 1; let right = left + 1; if (left < size && list[left] > list[largest]) { largest = left; } if (right < size && list[right] > list[largest]) { largest = right; } if (largest !== index) { [list[index], list[largest]] = [list[largest], list[index]]; heapify(list, size, largest); } return list; } function heapsort(list) { const size = list.length; let index = ~~(size / 2 - 1); let last = size - 1; while (index >= 0) { heapify(list, size, --index); } while (last >= 0) { [list[0], list[last]] = [list[last], list[0]]; heapify(list, --last, 0); } return list; } heapsort([4, 7, 2, 6, 4, 1, 8, 3]); Example 2: heap sort name meaning A sorting algorithm that works by first org

How To Add Blur Background Image In Css Code Example

Example 1: how to do a background blur in css /* Answer to "blur behind element css" */ /* This blurs everything behind the element it's applied to */ backdrop-filter : blur ( 10 px ) ; Example 2: image blur css filter : blur ( 8 px ) ; -webkit-filter : blur ( 8 px ) ; Example 3: add blur background css backdrop-filter : blur ( 5 px ) ; Example 4: css blur background /* Keyword value */ backdrop-filter : none ; /* URL to SVG filter */ backdrop-filter : url ( commonfilters.svg#filter ) ; /* <filter-function> values */ backdrop-filter : blur ( 2 px ) ; backdrop-filter : brightness ( 60 % ) ; backdrop-filter : contrast ( 40 % ) ; backdrop-filter : drop-shadow ( 4 px 4 px 10 px blue ) ; backdrop-filter : grayscale ( 30 % ) ; backdrop-filter : hue-rotate ( 120 deg ) ; backdrop-filter : invert ( 70 % ) ; backdrop-filter : opacity ( 20 % ) ; backdrop-filter : sepia ( 90 % ) ; backdrop-filter : saturate ( 80 % ) ; /* Multiple filters */ backdrop-fil

Bundler: You Must Use Bundler 2 Or Greater With This Lockfile

Answer : I had a similar experience. Here's how I solved it Display a list of all your local gems for the bundler gem gem list bundler N/B : The command above is for rbenv version manager, the one for rvm might be different This will display the versions of the bundler gem installed locally bundler (2.1.4, default: 1.17.2) if you don't have bundler version 2 installed locally, then run gem install bundler OR gem install bundler -v 2.1.4 if you have bundler version 2 already installed locally or just installed it, then you need to simply install an update for RubyGems Package Manager locally. To do this, run gem update --system And then finally run bundle update --bundler For Docker projects in Ruby on Rails If you're experiencing this issue when trying to build your application using Docker, simply do this: Delete the Gemfile.lock file Please don't create it again by running bundle install . Run your docker build or docker-compose build comm

Count Total Set Bits In All Numbers From 1 To N Code Example

Example: bitwise count total set bits //WAP to find setbits (total 1's in binary ex. n= 5 => 101 => 2 setbits int count { } , num { } ; cin >> num ; while ( num > 0 ) { count = count + ( num & 1 ) ; // num&1 => it gives either 0 or 1 num = num >> 1 ; // bitwise rightshift } cout << count ; //count is our total setbits

Can I Pass Default Value To Rails Generate Migration?

Answer : You can't: https://guides.rubyonrails.org/active_record_migrations.html#column-modifiers null and default cannot be specified via command line. The only solution is to modify the migration after it's generated. It was the case in Rails 3, still the case in Rails 6 Rails migration generator does not handle default values, but after generation of migration file you should update migration file with following code add_column :users, :disabled, :boolean, default: false you can also see this link - http://api.rubyonrails.org/classes/ActiveRecord/Migration.html Default migration generator in Rails does not handle default values, there is no way around as of now to specify default value defined through terminal in rails migration. you would like to follow below steps in order to achieve what you want 1). Execute $ rails generate migration add_disabled_to_users disabled:boolean 2). Set the new column value to TRUE/FALSE by editing the new migration file cr

Bypass Vs Unrestricted Execution Policies

Answer : Per the comments, there should be no particular difference with how these execution policies behave. However Bypass is intended to be used when you are temporarily changing the execution policy during a single run of Powershell.exe , where as Unrestricted is intended to be used if you wish to permanently change the setting for the exeuction policy for one of the system scopes (MachinePolicy, UserPolicy, Process, CurrentUser, LocalMachine). Some examples: You are on a system where you want to change the execution policy to be permanently unrestricted so that any user could run any PowerShell script without issue. You would run: Set-ExecutionPolicy Unrestricted You are on a system where the exeuction policy blocks your script but you want to run it via PowerShell and ignore the execution policy when run. You would run: powershell.exe .\yourscript.ps1 -executionpolicy bypass You run Powershell.exe on a system where the execution policy blocks the exeuction of scri

Can We Change Package Name Of My Flutter App In Future Code Example

Example 1: change package name flutter flutter create --org com.yourdomain appname Example 2: flutter change package name Go to build.gradle in app module and rename applicationId "com.company.name" Go to Manifest.xml in app/src/main and rename package="com.company.name" and android:label="App Name" Go to Manifest.xml in app/src/debug and rename package="com.company.name" Go to Manifest.xml in app/src/profile and rename package="com.company.name" Go to app/src/main/kotlin/com/something/something/MainActivity.kt and rename package="com.company.name" Go to app/src/main/kotlin/ and rename each directory so that the structure looks like app/src/main/kotlin/com/company/name/ Go to pubspec.yaml in your project and change name: something to name: name, example :- if package name is com.abc.xyz the name: xyz Go to each dart file in lib folder and rename the imports to the modified name. Open XCode and open the runner f

Conditional At End Of Line Python Code Example

Example 1: 1 line if statement python value_when_true if condition else value_when_false Example 2: python inline if Python does not have a trailing if statement . There are two kinds of if in Python : 1 . if statement : if condition : statement if condition : block 2 . if expression ( introduced in Python 2.5 ) expression_if_true if condition else expression_if_false And note , that both print a and b = a are statements . Only the a part is an expression . So if you write print a if b else 0 it means print ( a if b else 0 ) and similarly when you write x = a if b else 0 it means x = ( a if b else 0 ) Now what would it print / assign if there was no else clause? The print / assignment is still there . And note , that if you don 't want it to be there, you can always write the regular if statement on a single line, though it' s less readable and there is really no reason to avoid the two - line variant

Bootstrap Multiselect Get Selected Values

Answer : the solution what I found to work in my case $('#multiselect1').multiselect({ selectAllValue: 'multiselect-all', enableCaseInsensitiveFiltering: true, enableFiltering: true, maxHeight: '300', buttonWidth: '235', onChange: function(element, checked) { var brands = $('#multiselect1 option:selected'); var selected = []; $(brands).each(function(index, brand){ selected.push([$(this).val()]); }); console.log(selected); } }); Shorter version: $('#multiselect1').multiselect({ ... onChange: function() { console.log($('#multiselect1').val()); } }); more efficient, due to less DOM lookups: $('#multiselect1').multiselect({ // ... onChange: function() { var selected = this.$select.val(); // ... } });

My Cpp Code Example

Example: my cpp # include <iostream> using namespace std ; int main ( ) { cout << "Micael Illos" << endl ; return 0 ; }

C# Jobject Get Value Code Example

Example 1: how to get value from object in c# var nameOfProperty = "property1" ; var propertyInfo = myObject . GetType ( ) . GetProperty ( nameOfProperty ) ; var value = propertyInfo . GetValue ( myObject , null ) ; Example 2: jobject c# get value by key /* { "status": "success", "data": { "city": "Don Mueang", "state": "Bangkok", "country": "Thailand", "location": { "type": "Point", "coordinates": [ 100.58994, 13.91392 ] }, "current": { "weather": { "ts": "2021-01-18T04:00:00.000Z", "tp": 25, "pr": 1018, "hu": 53, "ws": 3.6, "

Allow Only Numbers And Dot In Script

Answer : This is a great place to use regular expressions. By using a regular expression, you can replace all that code with just one line. You can use the following regex to validate your requirements: [0-9]*\.?[0-9]* In other words: zero or more numeric characters, followed by zero or one period(s), followed by zero or more numeric characters. You can replace your code with this: function validate(s) { var rgx = /^[0-9]*\.?[0-9]*$/; return s.match(rgx); } That code can replace your entire function! Note that you have to escape the period with a backslash (otherwise it stands for 'any character'). For more reading on using regular expressions with javascript, check this out: http://www.regular-expressions.info/javascript.html You can also test the above regex here: http://www.regular-expressions.info/javascriptexample.html Explanation of the regex used above: The brackets mean " any character inside these brackets ." Y