Skip to content

Instantly share code, notes, and snippets.

@farhad-taran
farhad-taran / README.md
Last active February 16, 2021 08:51
Search for property with a specific name, anywhere in the object graph

In certain scenarios we would like to check whether an object anywhere in it's structure has a property with a specific name or value.

the following are two options for doing such an operation:

Breadth First Search

I have specifically opted for tree traversal instead of recursion, because it uses less stack frames and memory and because traversal is faster.

@farhad-taran
farhad-taran / README.md
Last active December 30, 2020 22:04
using .gitignore to force an always empty directory and subdirectories for local development

sometimes we need a local folder in our repos that we use to put in development content into, but this is content that we dont necessarily want to be commited to our git history, so one way to acoid these unwanted files is to use git ignore.

you need to ignore files and folders recursively:

/local/** (if you only ignore /foo/, that is the folder, then no amount of '!' exclusion rule will work, since the foo/ folder itself is ignored: Git will stop there)

Then exclude folders from the ignore rules:

@farhad-taran
farhad-taran / README.md
Last active September 7, 2020 08:32
Automatically Running custom git hooks in DotNet Solutions

Add the custom git-hooks described further down in the page to the folder ./scripts/git-hooks relative to the root of the repository.

If you are using a linux based machine, make sure that the hooks are executable, chmod +x "$f" before you commit them to your git history. you can achieve that by running the following script.

for f in ./scripts/git-hooks
do 
   chmod +x "$f"
done
@farhad-taran
farhad-taran / README.md
Created September 6, 2020 19:49
Swagger and Swashbuckle XML comments

To enable XML documentation such as comments on controllers to appear in swagger follow the following steps.

Enable XML document generation for the Assembly:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DocumentationFile>bin\Debug\netcoreapp3.1\PHDV.Deliveroo.Webhooks.Api.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DocumentationFile>bin\Release\netcoreapp3.1\PHDV.Deliveroo.Webhooks.Api.xml</DocumentationFile>
@farhad-taran
farhad-taran / README.md
Last active February 25, 2021 10:04
How to automatically navigate to current open folder when opening a new bash session

you can add the following script to your .zshrc and this will cause the newly opened bash session to automatically go to the path of the currently opened file explorer.

cdf() {
      target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
        if [[ $target == *"Desktop"* ]]; then
	    return
	elif [[ $target != "" ]]; then
 cd "$target"; pwd
@farhad-taran
farhad-taran / README.md
Last active February 17, 2025 22:15
How to install ngrock using brew

Installing ngrok on OSX

brew cask install ngrok

Using ngrok

The easiest way to use ngrok to tunnel into your localhost is if your local project is running on a specific port (e.g. not using named vhosts). You just run ngrok http [port number].

You can quickly boot up a local webserver using ruby. cd into the project's root directory and run ruby -run -e httpd . -p [port number].

@farhad-taran
farhad-taran / README.md
Last active July 4, 2024 01:18
Debugging linux permission issues

WSL is mounted on the c drive and the system32 path, a system folder which does not permit users to have full access, because of this, it is important to install applications from your default users home path ~, this is where this user has full access permissions and will ensure that all the applications and interactions will complete withouth any access permission errors.

as mentioned above you should not need to modify permissions manually except in rare cases but if you do, the following snippets might help you.

before starting, if you struggle to undrestand certain commands or snippets you can use the following service.

in order to debug any permission related issues the first step should be to start a bash window that will echo all commads that are executed:

bash --login -x
@farhad-taran
farhad-taran / README.md
Last active March 13, 2025 00:49
How to install Brew on WSL2

open ubuntu, this should give you a command prompt that looks like this:

username@DESKTOP-S0EN2QH:~$

WSL is mounted on the c drive and the system32 path, which is a system folder which does not permit users to have full access, because of this, it is important to make sure to install applications from your default users home path ~ as shown above, this is where this user has full access permissions and will ensure that all the applications and interactions will complete withouth any access permission errors.

even though you will have a default .bashrc and .profile file which get run automatically by ubunto everytime you open a terminal, it is best to run the following command to create a .bash_profile:

echo "source ~/.bashrc" >> ~/.bash_profile
@farhad-taran
farhad-taran / README.md
Last active August 2, 2020 12:15
How to install WSL 2 and Ubuntu

Check that you have latest windows updates that allows WSL 2 and then Open an admin Powershell instance and run the following commands:

  • Enable WSL
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  • Enable ‘Virtual Machine Platform’
@farhad-taran
farhad-taran / README.md
Created July 31, 2020 15:40
VS Code - ask for Port Number when debugging Node Express apps

you can ask the desire port number to run a Node Express app by utalizing the VS Code's "User Input Variables" feature like so:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",