Thursday, December 14, 2023

Bootstrap

Bootstrap, very cool, a popular front-end framework for building responsive and visually appealing websites.

d-inline is a utility class that sets the display property of an element to inline.

  • Margin and Padding:

    • m-1, m-2, ... m-5: Margin classes for spacing (1 to 5).
    • p-1, p-2, ... p-5: Padding classes for spacing (1 to 5).
    • mx-3: Horizontal margin.
    • px-3: Horizontal padding.
  • Text Alignment:

    • text-center: Center-align text.
    • text-right: Right-align text.
  • Background and Color:

    • bg-primary, bg-secondary, ...: Background color classes.
    • text-primary, text-secondary, ...: Text color classes.
  • Buttons:

    • btn, btn-primary, ...: Bootstrap button classes.
    • btn-outline-primary: Outline button with primary color.

Bootstrap, Here is the Documentation site for it: https://getbootstrap.com/docs/5.0/utilities/api/

WordPress - Useful Links

Very good WordPress tutorialshttps://www.wpbeginner.com/

Display posts plugin and tutorials:

https://displayposts.com/tutorials/

https://wordpress.org/plugins/display-post-types/


WordPress - PHP

Making new  menu and display location:

1. Code Snippets » Add Snippet 

<?php
    function wpb_top_right_menu() 
{
        register_nav_menu('top-right-menu',__( 'Top Right Menu' ));
}
add_action( 'init', 'wpb_top_right_menu' );?>

2. Appearance » Theme File Editor » Header(typically)

wp_nav_menu( array( 'theme_location'=>'top-right-menu', 'container_class'=>'top-right-class' ) );

WordPress - CSS

I am helping alumnus to build a WordPress website, quite interesting.

Additional CSS: good way to custom the style.

Remove the page title:

.bread_crumb

{ display: none; }

For custom top right menu:

div.top-right-class ul {

float:right;

    margin:20px 0px 20px 0px;

    list-style-type: none;

    list-style: none;

    list-style-image: none;

    text-align:right;

    display:inline-block;

}

div.top-right-class li {

    padding: 0px 20px 0px 0px;

    display: inline-block;

}  

div.top-right-class a { color:blue; }

Remove 1st letter drop cap:

.entry-content > p:first-of-type:first-letter{

font-size: 100%;

          line-height: 1; 

margin-right:-10px;

Display posts style:

.display-posts-listing .listing-item {    clear: both;  }

.display-posts-listing img {

    float: left;

    margin: 0 10px 10px 0;

}

Tuesday, November 28, 2023

MVC - C# Reference

? A question mark (?) is used to denote a nullable type. A nullable type can represent all the values of its underlying non-nullable value type plus an additional null value. This is particularly useful when dealing with value types, which cannot normally be assigned a null value. 

int? nullableInt = 42;  // Valid assignment

nullableInt = null;    // Valid assignment

DateTime? nullableDateTime = DateTime.Now;  // Valid assignment

nullableDateTime = null;                    // Valid assignment

?? The ?? operator, also known as the null-coalescing operator, is used for handling null values in a concise way. It provides a way to return a default value when the left-hand operand is null. 

string proName = pro?[0]?.Name ?? "Default Value";

The #pragma warning disable directive is used in C# to disable specific compiler warnings: #pragma warning disable CS8602

Target-typed new expressions are a feature introduced in C# 9.0. They allow you to omit the type in the new expression when the type can be inferred from the surrounding context. This helps reduce redundancy in your code and makes it more concise.        

// Without target-typed new expression

List<string> names = new List<string>();

// With target-typed new expression (C# 9.0 and later)

List<string> names = new(); 

The update-database command is part of the Entity Framework Migrations workflow and is crucial for keeping the database schema in sync with your code changes. It's a powerful tool that automates the process of evolving the database as your application evolves, making it easier to manage changes to your data model over time.

        Applying Database Migrations/Creating the Initial Database/Applying Subsequent     Migrations/Rolling Back Migrations

In Entity Framework, the DbContext class provides a set of methods to interact with the underlying database using LINQ queries. Here are some common methods associated with DbSet that allow you to perform various operations:

  1. Query Operations:

    • FirstOrDefault, SingleOrDefault: Retrieve the first or a single entity that satisfies a condition.
    • Where: Filter entities based on a condition.
    • OrderBy, OrderByDescending, ThenBy, ThenByDescending: Order entities based on one or more properties.
  2. Insert/Update Operations:

    • Add, AddRange: Add a new entity or a collection of entities to the context.
    • Attach: Attaches an entity or a disconnected graph of entities to the context.
    • Update: Marks an entity or entities as modified.
    • Remove, RemoveRange: Remove an entity or a collection of entities from the context.
  3. Save Changes:

    • SaveChanges, SaveChangesAsync: Persist changes made in the context to the underlying database.
  4. Bulk Operations:

    • Entity Framework Core (EF Core) has introduced extensions like BulkInsert, BulkUpdate, BulkDelete for handling bulk operations efficiently.
  5. Raw SQL Queries:

    • FromSqlRaw, FromSqlInterpolated: Execute raw SQL queries.



Friday, May 14, 2021

ORCL - Pivot

Sometime users request converting multiple rows to columns for same ID, like the following:

with l as

 (select '333' id, 'email1' email, 1 xsequence  from dual

  union  select '333' id, 'email2' email, 2 xsequence  from dual

  union  select '333' id, 'email3' email, 3 xsequence   from dual)

select * from l;

333 email1 1

333 email2 2

333 email3 3

Sometimes users are OK with comma concatenated like this (with listagg function):

333 email1,email2,email3 (one column)

And most time users want like this: 

333 email1 email2 email3 (3 columns)

So in order to get that, I used to do an old way: first rank() them and doing case then group max, like the following:

select n.id, max(email1) e1, max(email2) e2, max(email3) e3

  from (select m.id,  case  when rn = 1 then m.email  end email1,

               case when rn = 2 then m.email end email2,

               case when rn = 3 then m.email end email3

          from m) n  group by id

By using Pivot, it will cut the CASE and MAX, just like this:

select *  from m pivot (max(email) for rn in(1, 2, 3))

with l as
 (select '333' id, 'email1' email, 1 xsequence
    from dual
  union
  select '333' id, 'email2' email, 2 xsequence
    from dual
  union
  select '333' id, 'email3' email, 3 xsequence
    from dual),
m as
 (select distinct l.id, l.email,
                  rank() over(partition by l.id order by l.xsequence) rn  
    from l)
select *  from m pivot (max(email) for rn in(1, 2, 3))

If you want to select them for other joined query, you could set the column alias to get rid of the number(rn), since you can not pick/select the column started with numbers.

select *   from m
pivot (max(email) for rn in(1 as e1, 2 as e2, 3 as e3))

I made a video to show the process, thanks for watching!


You can online search for Pivot documentation and examples.

"Oracle 11g introduced the new PIVOT clause that allows you to write cross-tabulation queries which transpose rows into columns, aggregating data in the process of the transposing. As a result, the output of a pivot operation returns more columns and fewer rows than the starting data set.

In this syntax, following the PIVOT keyword are three clauses:

  • pivot_clause specifies the column(s) that you want to aggregate. The pivot_clause performs an implicitly GROUP BY based on all columns which are not specified in the clause, along with values provided by the pivot_in_clause.
  • pivot_for_clause specifies the column that you want to group or pivot.
  • pivot_in_clause defines a filter for column(s) in the pivot_for_clause. The aggregation for each value in the pivot_in_clause will be rotated into a separate column."

Monday, May 10, 2021

Windows 10 Your Phone

Just found Windows 10’s Your Phone app on my $300 ThinkPad Yoga book, which I really like. The App links your android phone with PC. Of course it works with iPhone but it's said it works best for Android users, letting you text from your PC, sync your notifications, and wirelessly transfer photos back and forth, also screen your phone to TV.

OK, Sounds pretty good, usually I USB connect my Huawei Pro20 with PC to transfer files, specially pictures and songs. So with Phone app we can do those wirelessly, WIRELESSLY, yes, nowadays it's a very popular thing.

Setup Your Phone is extremely easy, just click Windows Logo on your PC and scroll down the bottom, click it and follow along, I made a silly video, you can watch if you like to support my starting YouTube Channel. 

Also a quick tip about the Windows OneDrive, OneDrive is Microsoft's cloud storage for consumers, and it is built into Windows 10. For free, it comes with 15 GB of storage, and there are a couple of paid tiers to increase that storage. 15GB is plenty for normal people:), but make sure you are aware of the OneDrive sync options.

The OneDrive cloud icon in the Windows taskbar notification area, right click it will show some options/tasks you can do.  I also added a little talk about this on the below clip.

Well, let's leave our phones somewhere and focus on the PC:))




Monday, April 19, 2021

Linked to NetEase Email Account

I have been having a NetEase free email account (something@163.com) for long time and mainly use for subscription registration (less important than Hotmail/Gmail:) and usually link the account with Microsoft Windows default Inbox.

Then suddenly not working and complaining about the password not correct and I tried quite time and failed. After search on line and found the problem so I would like to share it. (Long Live Internet Search!)

Basically the problem is that the password is not the pass loign to NetEase email account and it's the one you generate form NetEase account.

1. login to NetEase account and Setting -> POP3/SMTP/IMAP

2. Make sure the receiving/sending servie is open

开启服务
服务器地址:
POP3服务器: pop.163.com
SMTP服务器: smtp.163.com
IMAP服务器: imap.163.com
安全支持:
POP3/SMTP/IMAP服务全部支持SSL连接

3. Go to 授权密码管理, and get the passcode and use this code fro your Inbox setup


4. Go to Windows Inbox Accounts -> Add account 

Using the bottom two options: Other account POP, IMAP or Advance setup

It's easy just to use Other account POP, IMAP, click it and enter the information


Pleave your question if you have:))