Useful regex


\/ matches the character “/” literally (case sensitive)
\* matches the character “*” literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\* matches the character “*” literally (case sensitive)
\/ matches the character “/” literally (case sensitive)

/* 501 */
/* 1 */

Reset a single file to a specific commit

Assuming the hash of the commit you want is c5f567:

git checkout c5f567 -- file1/to/restore file2/to/restore

The git checkout man page gives more information.

If you want to revert to the commit before c5f567, append ~1 (where 1 is the number of commits you want to go back, it can be anything):

git checkout c5f567~1 -- file1/to/restore file2/to/restore

As a side note, I’ve always been uncomfortable with this command because it’s used for both ordinary things (changing between branches) and unusual, destructive things (discarding changes in the working directory).

Search and rename Foreign Key Name

List foreign keys:

select schema_name(fk_tab.schema_id) + '.' + as foreign_table, '>-' as rel, schema_name(pk_tab.schema_id) + '.' + as primary_table, substring(column_names, 1, len(column_names)-1) as [fk_columns], as fk_constraint_name from sys.foreign_keys fk inner join sys.tables fk_tab on fk_tab.object_id = fk.parent_object_id inner join sys.tables pk_tab on pk_tab.object_id = fk.referenced_object_id cross apply (select col.[name] + ', ' from sys.foreign_key_columns fk_c inner join sys.columns col on fk_c.parent_object_id = col.object_id and fk_c.parent_column_id = col.column_id where fk_c.parent_object_id = fk_tab.object_id and fk_c.constraint_object_id = fk.object_id order by col.column_id for xml path ('') ) D (column_names) order by schema_name(fk_tab.schema_id) + '.' +, schema_name(pk_tab.schema_id) + '.' +

Search Primary keys:


Then rename the foreign key:

sp_rename @objname = N'PK_Notes_ADF019271172DFE', @newname = N'PK_Notes'

Update if parameter is not null or empty

Using just IsNull your query would look something like…

UPDATE [Users]
SET FirstName = IsNull(@FirstName, FirstName),
City = IsNull(@City, City)

DECLARE @value AS INT = Null
SELECT CASE WHEN ISNULL(@value, 2)=0 THEN Null Else ISNULL(@value, 2) END

will Update the row with the param value if they are NOT null, otherwise update it to itself aka change nothing.

Software craftsmenship manifesto

From Creaftsmenship Manifesto

Background materials

Food for thought

Kata and exercises

Conferences and community

Get all documents from mongodb collection

Get all documents from a MongoDB collection:

Using the current version of the driver (v2.0) you can do that by passing a filter that matches everything:

var documents = await SpeCollection.Find(_ => true).ToListAsync();

They have also added an empty filter (FilterDefinition.Empty) which will arrive in the next version of the driver (v2.1):

var documents = await SpeCollection.Find(Builders.Filter.Empty).ToListAsync();

With and without Lambda Expression

var id = 1;
var query =
from user in database.Users
join invoice in database.Invoices on user.Id equals invoice.UserId
where user.Id == id
select new { User = user, Invoice = invoice };

Here’s the same query, using Lambda Expression LINQ extension methods:

var id = 1;
var query = database.Users // your starting point - table in the "from" statement
.Join(database.Invoices, // the source table of the inner join
user => user.Id, // Select the primary key (the first part of the "on" clause in an sql "join" statement)
invoice => invoice.UserId, // Select the foreign key (the second part of the "on" clause)
(user, invoice) => new { User = user, Invoice = invoice }) // selection
.Where(userAndInvoice => userAndInvoice.User.Id == id); // where statement

Git workflow

Here you can see the basics workflow for git
After cloning your repo from any git platform provider Like github, gitlab, bitbucket etc… .
Firstly check branch:
git branch
(your base branch, most likely develop or master. Consider develop as a base branch)
Fetch latest remote code to local:
git pull
(for latest develop code)
Checkout new branch as per feature and
git checkout -b newBranchName
(If you are working on any new bug named branch feature than give branch name feature/ login-feature or you are working on any bug than give branch name bug/login-bug.
This way you can eaisily identify/judge your branch by name.)

After finish your work in your
$ git status (after Changes )
Add changed file into staging
git add . | | $ git add .. (dot) (for feature/bug branch.(in red colored) add file in staging)
Check staging file (in green colored)
$ git status
Add commit message
$ git commit -m Commit message
Checkout your base branch
$ git checkout develop (switch
For latest code (if other guy
$ git pull (for latest develop code)
Checkout your previous feature/to develop) working on it)
bug branch

git pull (for latest develop code)
Checkout your previous feature.
Rebase your branch with develop
git rebase develop
Push your feature/bug branch
git push
(it will suggest command if bug branch or master to remote: its not in remote).
After this open your git platform provider Like github, gitlab, bitbucket whatever you use.
Assign merge request to your other develop to review code, it will increase your productivity and code quality.

Git update and publish

git remote -v
git remote show
git remote add
git fetch
git fetch --all
git pull | git pull
git push
git push
git push origin :old-name new-name
git push origin -u new-name
git branch -dr
git push origin YourTagVersion