Posts

Showing posts from May, 2009

C# Serilog: How To Log With String Interpolation And Keep Argument Names In Message Templates?

Answer : Add this file to your project. It has ILogger extension methods VerboseInterpolated() , DebugInterpolated() and so on. There are also unit tests here. Usage with format string string name = "John"; // add 'Interpolated' to method name: InformationInterpolated() instead of Information() // add name of the property after the expression. Name is passed to the logger logger.InformationInterpolated($"length of name '{name:name}' is {name.Length:Length}"); But be careful : it's all too easy to use the wrong method. If you accidentally use the Serilog's method, for example logger.Debug($"length = {length:propertyNameForLogger}") , it will log length = propertyNameForLogger , so no argument value will be logged. This is due to propertyNameForLogger is format for your value. Usage with anonymous types string name = "John"; // add 'Interpolated' to method name: InformationInterpolated() instead of

Bootstrap 4 Cheatsheet Code Example

Example 1: bootstrap cheat sheet Two very good bootstrap Cheat Sheets are: https://getbootstrap.com/docs/5.0/examples/cheatsheet/ https://websitesetup.org/wp-content/uploads/2020/03/Bootstrap-Cheat-Sheet-websitesetup.org_.pdf Example 2: bootstrap 4 classes list with description pdf < a href = " # " class = " badge badge-primary " > Primary </ a > < a href = " # " class = " badge badge-secondary " > Secondary </ a > < a href = " # " class = " badge badge-success " > Success </ a > < a href = " # " class = " badge badge-danger " > Danger </ a > < a href = " # " class = " badge badge-warning " > Warning </ a > < a href = " # " class = " badge badge-info " > Info </ a > < a href = " # " class = " badge badge-light " > Light </ a > < a href

Bootstrap 4 Align Navbar Items To The Right

Image
Answer : Bootstrap 4 has many different ways to align navbar items. float-right won't work because the navbar is now flexbox . You can use mr-auto for auto right margin on the 1st (left) navbar-nav . Alternatively , ml-auto could be used on the 2nd (right) navbar-nav , or if you just have a single navbar-nav . <nav class="navbar navbar-expand-md navbar-light bg-light"> <a class="navbar-brand" href="#">Navbar</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="#">Home <sp

80 Cm In Inches Code Example

Example: cm to inches const cm = 1; console.log(`cm:${cm} = in:${cmToIn(cm)}`); function cmToIn(cm){ var in = cm/2.54; return in; }

#!/bin/bash - No Such File Or Directory

Answer : This kind of message is usually due to a bogus shebang line, either an extra carriage return at the end of the first line or a BOM at the beginning of it. Run: $ head -1 yourscript | od -c and see how it ends. This is wrong: 0000000 # ! / b i n / b a s h \r \n This is wrong too: 0000000 357 273 277 # ! / b i n / b a s h \n This is correct: 0000000 # ! / b i n / b a s h \n Use dos2unix (or sed , tr , awk , perl , python …) to fix your script if this is the issue. Here is one that will remove both of a BOM and tailing CRs: sed -i '1s/^.*#//;s/\r$//' brokenScript Note that the shell you are using to run the script will slightly affect the error messages that are displayed. Here are three scripts just showing their name ( echo $0 ) and having the following respective shebang lines: correctScript: 0000000 # ! / b i n / b a s h \n scriptWithBom

Color Alpha Flutter Code Example

Example: flutter how to add opacity to color backgroundColor: Colors.black.withOpacity(0.5)

Apply "ORDER BY" On A "UNION" (Mysql)

Answer : SELECT * FROM ( (SELECT * FROM user_relation WHERE from_user_id = 1) UNION (SELECT * FROM user_relation WHERE to_user_id = 1) ) AS i ORDER BY trust_degree You have to assign an alias to your select. But in this case a UNION is not necessary and could be replaced by a simple OR , as @Karoly Horvath points out in his comment. The resulting query would look like this: SELECT * FROM user_relation WHERE from_user_id = 1 OR to_user_id = 1 ORDER BY trust_degree It is written in the documentation of UNION : To apply ORDER BY or LIMIT to an individual SELECT , place the clause inside the parentheses that enclose the SELECT : (SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) UNION (SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10); ... Use of ORDER BY for individual SELECT statements implies nothing about the order in which the rows appear in the final result because UNION by default produces an unordered set of rows. ...

Online Linux Compiler C++ Code Example

Example: cpp online compiler Best Site With auto compile : https : //godbolt.org/z/nEo4j7

Angularjs $http Post Response Code Example

Example: angularjs make post request var url = 'posturl' , data = 'parameters' , config = 'contenttype' ; $http . post ( url , data , config ) . then ( function ( response ) { // This function handles success } , function ( response ) { // this function handles error } ) ;

Chart Js Timeline Code Example

Example 1: chart.js < canvas id = "myChart" width = "400" height = "400" > < / canvas > < script > var ctx = document . getElementById ( 'myChart' ) . getContext ( '2d' ) ; var myChart = new Chart ( ctx , { type : 'bar' , data : { labels : [ 'Red' , 'Blue' , 'Yellow' , 'Green' , 'Purple' , 'Orange' ] , datasets : [ { label : '# of Votes' , data : [ 12 , 19 , 3 , 5 , 2 , 3 ] , backgroundColor : [ 'rgba(255, 99, 132, 0.2)' , 'rgba(54, 162, 235, 0.2)' , 'rgba(255, 206, 86, 0.2)' , 'rgba(75, 192, 192, 0.2)' , 'rgba(153, 102, 255, 0.2)' , 'rgba(255, 159, 64, 0.2)' ] , borderColor : [

Sudo Service Mongod Start Code Example

Example 1: start mongodb service ubuntu sudo systemctl start mongod sudo systemctl stop mongod Example 2: remove mongo lock file from centos 7 sudo rm / var / lib / mongodb / mongod . lock sudo mongod -- repair sudo service mongod start sudo service mongod status

Ansi Color Codes Python Code Example

Example 1: ansi colors Black \e [ 0 ; 30m Blue \e [ 0 ; 34m Green \e [ 0 ; 32m Cyan \e [ 0 ; 36m Red \e [ 0 ; 31m Purple \e [ 0 ; 35m Brown \e [ 0 ; 33m Gray \e [ 0 ; 37m Dark Gray \e [ 1 ; 30m Light Blue \e [ 1 ; 34m Light Green \e [ 1 ; 32m Light Cyan \e [ 1 ; 36m Light Red \e [ 1 ; 31m Light Purple \e [ 1 ; 35m Yellow \e [ 1 ; 33m White \e [ 1 ; 37m Example 2: python ansi escape sequences color collection class colors : reset = "\033[0m" # Black fgBlack = "\033[30m" fgBrightBlack = "\033[30;1m" bgBlack = "\033[40m" bgBrightBlack = "\033[40;1m" # Red fgRed = "\033[31m" fgBrightRed = "\033[31;1m" bgRed = "\033[41m" bgBrightRed = "\033[41;1m" # Green fgGreen = "\0

Angular Material - Change Color Of Mat-list-option On Selected

Answer : You can use aria-selected="true" attribute from mat-list-option tag to target the selected option, and provide corresponding css properties for the same. mat-list-option[aria-selected="true"] { background: rgba(0, 139, 139, 0.7); } Stackblitz Working Demo The accepted answer works fine, but it uses a hardcoded color value ( background: rgba(0, 139, 139, 0.7) ). This approach will actually break your styles and colors if you decide to switch to another pre-build material theme or use a custom theme (as described in Theming your Angular Material app page). So, if you use SCSS, you can use the following code in your component's style file: @import '~@angular/material/theming'; mat-list-option[aria-selected="true"] { background: mat-color($mat-light-theme-background, hover, 0.12); } The above code is adapted from mat-select options - in this way, you will have a consistent look in the entire app: .mat-option.mat-s

Angular Dependency Providers Example

By configuring providers, you can make services available to the parts of your application that need them. A dependency provider configures an injector with a DI token, which that injector uses to provide the runtime version of a dependency value. Specifying a provider token If you specify the service class as the provider token, the default behavior is for the injector to instantiate that class with new . In the following example, the Logger class provides a Logger instance. providers: [Logger] You can, however, configure an injector with an alternative provider in order to deliver some other object that provides the needed logging functionality. You can configure an injector with a service class, you can provide a substitute class, an object, or a factory function. Dependency injection tokens When you configure an injector with a provider, you are associating that provider with a dependency injection token, or DI token. The injector allows Angular to create a map of a

Angular-UI Tabs: Add Class To A Specific Tab

Answer : I'm not sure that you can apply ng-class to tabs like that. After trying and failing I decided to look at the bootstrap-ui source for tabs and made an interesting discovery related to the tab heading attribute. Apparently you can put html in the heading section if you place the tab-heading as a child to a tab element. Check out the tabheading directive in here. This is the example they show: <tabset> <tab> <tab-heading><b>HTML</b> in my titles?!</tab-heading> And some content, too! </tab> <tab> <tab-heading><i class="icon-heart"></i> Icon heading?!?</tab-heading> That's right. </tab> </tabset> In your case I think you might be able to do something like this to get the same effect: <tab ng-repeat="tab in tabs" active="tab.active"> <tab-heading>{{tab.title}} <span ng-show="tab.new">new<

Array Explode In Javascript Code Example

Example 1: string split javascript var myString = "An,array,in,a,string,separated,by,a,comma" ; var myArray = myString . split ( "," ) ; /* * * myArray : * ['An', 'array', 'in', 'a', 'string', 'separated', 'by', 'a', 'comma'] * */ Example 2: javascript split var names = 'Harry ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ' ; console . log ( names ) ; var re = / \s * (?: ; | $ ) \s * / ; var nameList = names . split ( re ) ; console . log ( nameList ) ;

Are The Days And Nights In Minecraft Of Equal Length?

Image
Answer : As it has been stated, days are actually longer than nights. Here, have a diagram — yet you're not entirely wrong! There is a logical reason why days do feel shorter. Day and night only matter on the surface, where it regulates mob spawning. At sunset, there's no mob on the surface. At sunrise, there is however. By the time the night's mob spawn is burned away by sunlight and it's safe to go out again, a sizable chunk of precious day time will have gone wasted. If we mark with red the dangerous period of the day, with green the productive period of the day and with orange the risk transitions between, we get this: So yes. While day is longer than night, the productive period is actually shorter than the risky period. In a way, yes: night and its practical effects are longer than day's. This is connected to why properly lit mines are much safer and much more productive environments than surface is. Are the Nights longer than the days? _ No

Cheat Sheets And Presets-settings That Actually Work With FFmpeg 1.0?

Image
Answer : FFmpeg does not include text file based presets and profiles anymore for libx264, i.e. what you've used with the -vpre option. These have been depreciated and removed in favor of accessing the actual x264 presets, profiles (and tunes) with the -preset , -profile:v , and -tune options. The old text files only emulated the official x264 presets and profiles, and due to several limitations could not offer full functionality that the new system provides. It is also much easier to maintain. Additionally, many encoders have their own separate options; also called "private options". You will have to look into the audio and video encoder options for common codecs in the FFmpeg online documentation, or check the output of ffmpeg -h full for a complete list of supported options. For example, x264 lists its options under libx264 AVOptions in the full help output. If your ffmpeg supports -preset then any text file presets should not be used, and FFmpeg no longer

Ajax Jquery Post Done Code Example

Example 1: jquery ajax post $ . ajax ( { type : "POST" , url : url , data : data , success : success , dataType : dataType } ) ; Example 2: jquery post $ . post ( "test.php" , { name : "John" , time : "2pm" } ) ;

Servicenow Hi Code Example

Example: hi servicenow HI ( Service Now ) abbreviate Hosted Instance .