Skip to content

Instantly share code, notes, and snippets.

View paveltimofeev's full-sized avatar

Pavel Timofeev paveltimofeev

View GitHub Profile
@paveltimofeev
paveltimofeev / cpu.js
Created July 22, 2016 15:07 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
@paveltimofeev
paveltimofeev / Nginx-hints-tips-tricks.md
Created July 14, 2016 13:28
Nginx hints, tips & tricks

Nginx hints, tips & tricks

Reverse Proxy with Caching

nginx.com example
nginx-caching

http {
    proxy_cache_path  /data/nginx/cache  levels=1:2  keys_zone=STATIC:10m  inactive=24h  max_size=1g;
 server {
@paveltimofeev
paveltimofeev / Fitnesse-Hints-Tricks.md
Last active June 23, 2016 10:42
Fitnesse Hints &Tricks

Fitnesse Hints &Tricks

Case Sensitive regexp for FitNesse:

Use =~/(?i: ... )/

-|script|
|check| eval| "CaseInsensitive"| =~/caseinsensitive/   | # fail
|check| eval| "CaseSensitive"  | =~/(?i:casesensitive)/| # success
@paveltimofeev
paveltimofeev / CS-merger.ps1
Last active March 7, 2022 22:39
Merge *.cs files into the one file
param(
[Parameter(Mandatory=$true)]
$source,
[Parameter(Mandatory=$true)]
$output,
$header = "/// © Pavel Timofeev",
$excludes = @("AssemblyInfo.cs", "*.Designer.cs", "TemporaryGeneratedFile_*" ),
$copyAsIs = @(), # list of filemasks that should be copy as is without merge
$addFileNames = $false, # add names of src files
$leftComments = $false, # remove line commented with //
@paveltimofeev
paveltimofeev / password-hash-strategies.md
Last active June 7, 2016 08:18
Good storing passwords' hashes strategies

Good storing passwords' hashes strategies

Do not store users' passwords in plain text, store hash of password instead. But only hashing is not enough, use one of these techniques, to make your users' data more protected:

  • simple way:

passwordHash = hash( hash(passwd) + salt )

  • better one - will produce different hashes for users with the same passwords:
@paveltimofeev
paveltimofeev / Batch-cmd-hints-tips-tricks.md
Last active June 2, 2016 08:39
Batch (CMD) hints, tips & tricks

Batch (CMD) hints, tips & tricks

"try-catch" for bat-files

my-command with parameters && (
  
  echo - my-command completed successfuly

  (call)
) || (
<?xml version="1.0" encoding="utf-16"?>
<StorableColorTheme xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Keys>
<string>ErrorForegroundColor</string>
<string>ErrorBackgroundColor</string>
<string>WarningForegroundColor</string>
<string>WarningBackgroundColor</string>
<string>VerboseForegroundColor</string>
<string>VerboseBackgroundColor</string>
<string>DebugForegroundColor</string>
cls
$text = "Hello <color clr=`"green`">World</color>"
write-host $text
$tag=$false
$text.ToCharArray() | % {
if(!$tag){ $tag = $_ -eq "<" }
@paveltimofeev
paveltimofeev / Bash-hints-tips-tricks.md
Last active October 18, 2017 13:06
Bash hints, tips & tricks

Bash hints, tips & tricks

Exit on Error

set -e
set -o pipefail

# -e (errexit): Abort script at first error, when a command exits with non-zero status (except in until or while loops, if-tests, list constructs)
# In case script is calling subscript inside, the pipefail option can be useful.
# -o pipefail: Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value.
@paveltimofeev
paveltimofeev / Powershell-Hints.md
Last active April 5, 2017 12:22
Powershell Hints & Tricks

Powershell Hints & Tricks

Convert hex to bytes, bytes to hex

function ConvertTo-Hex([byte[]]$bytes)
{
    return ($bytes | % { $_.ToString("X2") }) -join ""
}

function ConvertTo-Bytes([string]$hex)