Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danyg/37db071048b1b76fc0f20635b493b359 to your computer and use it in GitHub Desktop.
Save danyg/37db071048b1b76fc0f20635b493b359 to your computer and use it in GitHub Desktop.
BLOG

Mayority of linux distributions contains a /etc/profile.d which contain a few bash script that are executed on bash login you could add the following file there, the name is not important just need to end in .sh e.g. /etc/profile.d/PS1-git.sh In order to add the file to /etc/profile.d you probably would need root access.

# Define here your own colors.
# @see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
USER_COLOR='32'
ROOT_COLOR='31'
GITCOLOR='33'

RESET_COLORS='\[\e[0m\]'

[ $(whoami) = 'root' ] && DCOLOR=$ROOT_COLOR || DCOLOR=$USER_COLOR

parse_git_branch() {
	BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`

	if [ ! -z "$BRANCH" ]; then
		echo " ($BRANCH) "
	else
		echo ""
	fi
}

# Enable/disable or add new parts for customize your prompt
PS1=''
PS1+='\[\e[1;${DCOLOR}m\]'   # base color
PS1+='['                     # start first group
#	PS1+='\u'                # current user
	PS1+='\u@\h'             # current user at host
	PS1+=' '                 # separator
	PS1+='\w'                # current directory (full path)
#	PS1+='\W'                # current directory (basename)
PS1+=']'                     # end first group
PS1+=$RESET_COLORS           # RESET_COLORS COLORS
PS1+='\[\e[1;${GITCOLOR}m\]' # GIT COLOR
PS1+='$(parse_git_branch)'   # git Branch
PS1+=$RESET_COLORS           # RESET_COLORS COLORS
PS1+='\[\e[1;${DCOLOR}m\]'   # base color
PS1+='\$'                    # root or user
PS1+=' '                     # separator
PS1+=$RESET_COLORS           # RESET_COLORS COLORS

unset USER_COLOR
unset ROOT_COLOR

Once you add it, run bash, or open a new terminal, and if you haven't done any change, you would see your prompt as green, If not, it might be because your distro haven't configured the use of profile.d for that you can add this to the file ~/.bashrc

if [ -f /etc/profile.d/ ]
 // LOOP /etc/profile.d/*
fi
# How to come back to Javascript once you embraced Typescript
## Configure your project
jsconfig.json
```json
{
"compilerOptions": {
"experimentalDecorators": true,
"checkJs": true,
"baseUrl": "src",
"target": "es6",
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"bower_components"
]
}
```
## How to work with your own d.ts
```tyoescript
// in your js file
/** @typedef {import('types/product').Product} Product */
// /types/product.d.ts
export type Product = {
name: string,
id: string
};
```
## How to Constants / easy enums
Some file that uses the enums
```typescript
import {STOCK_STATUS} from '/config/constants';
class SomeClass {
/** @param {StockAvailability} stock */
someValidationWithStock(stock) {
if(stock === STOCK_STATUS.IN_STOCK) {
// do something...
}
}
}
```
types/product.d.ts
```typescript
// ...
export type StockAvailability = 'IN_STOCK' | 'OUT_OF_STOCK';
// ...
```
config/constants.js
```tyoescript
/** @typedef {import('types/product').StockAvailability} StockAvailability */
/** @type {{[key: string]: StockAvailability}} */
export const STOCK_STATUS = {
OUT_OF_STOCK: 'OUT_OF_STOCK',
IN_STOCK: 'IN_STOCK'
};
```
With the previous example, you lose the option of haveing intellisense of the inner keys but you have no typescript error, either in this piece of code neither using the properites of this object as `StockAvailability`
The following example you have intellisense for the keys, and no error
```typescript
/** @typedef {import('types/product').StockAvailability} StockAvailability */
export const STOCK_STATUS = {
/** @type {StockAvailability} */
OUT_OF_STOCK: 'OUT_OF_STOCK',
/** @type {StockAvailability} */
IN_STOCK: 'IN_STOCK',
/** @type {StockAvailability} */
BACK_ORDER_ALLOWED: 'BACK_ORDER_ALLOWED',
/** @type {StockAvailability} */
LOW_IN_STOCK: 'LOW_IN_STOCK',
/** @type {StockAvailability} */
PRE_ORDER_ALLOWED: 'PRE_ORDER_ALLOWED'
};
```
  1. Configure the windows time service to update the time more frequently. Control Panel -> Date and Time -> Internet Time tab.

Check the box "Synchronise with an internet time server" If no server is selected choose either "time.windows.com" or "pool.ntp.org".

This will automatically set the time once per week, which should keep your computer within a few seconds of the correct time. If you are running an important server you may need to set it more often. To do that you need to edit the registry.

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\ NtpClient, and check the the value SpecialPollInterval. This is in seconds.

The default is 604800, which is the number of seconds in a week. For daily time checks, choose 86400. Unless you have very special requirements you won't need more than daily. Four hours would be every 14400.

2: Configure the system to force-update the time on boot. To do a force-update you need to run the following as administrator (or system):

SC START w32time task_started So to force update on boot, you need to run that command as administrator. You can do that using Task Scheduler. To do this run the following as administrator:

schtasks /CREATE /TN "Set Time On Start" /SC ONSTART /RU SYSTEM /TR "SC START w32time task_started"

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment