This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Globalization; | |
namespace HumanReadable | |
{ | |
public class HumanReadableBytes | |
{ | |
private readonly Dictionary<Base, Unit[]> _baseUnits = new Dictionary<Base, Unit[]>(); | |
public int DecimalPoints = 2; | |
public int DecimalsAfterPower = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProgressBar : IDisposable, IProgress<double> | |
{ | |
private const int blockCount = 10; | |
private readonly TimeSpan animationInterval = TimeSpan.FromSeconds(1.0 / 8); | |
private const string animation = @"|/-\"; | |
private readonly Timer timer; | |
private double currentProgress = 0; | |
private string currentText = string.Empty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsoleSpinner : IDisposable | |
{ | |
private const string Sequence = @"/-\|"; | |
private int counter = 0; | |
private readonly int? left; | |
private readonly int? top; | |
private readonly int delay; | |
private bool active; | |
private readonly Thread thread; | |
private readonly ConsoleColor? color; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Format-Time() { | |
Param ([int]$ms) | |
If ($ms -gt 3600000) {[string]::Format("{0:0.00} hours", $ms / 3600000)} | |
ElseIf ($ms -gt 60000) {[string]::Format("{0:0.00} minutes", $ms / 60000)} | |
ElseIf ($ms -gt 1000) {[string]::Format("{0:0.00} seconds", $ms / 1000)} | |
ElseIf ($ms -gt 0) {[string]::Format("{0:0.00} milliseconds", $ms)} | |
Else {"0 milliseconds"} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Format-FileSize() { | |
Param ([long]$size) | |
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)} | |
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)} | |
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)} | |
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)} | |
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)} | |
Else {"0 byte"} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
while (true) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filtering a array by its keys using a callback. | |
* | |
* @param $array array The array to filter | |
* @param $callback Callback The filter callback, that will get the key as first argument. | |
* | |
* @return array The remaining key => value combinations from $array. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Written by Barand from phpfreaks.com */ | |
function numSuffix($n) { | |
$str = "$n"; | |
$t = $n > 9 ? substr($str,-2,1) : 0; | |
$u = substr($str,-1); | |
if ($t==1) return $str . 'th'; | |
else switch ($u) { | |
case 1: return $str . 'st'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function padnum { | |
NUM=$1 | |
if [ $(echo "$NUM < 10" | bc) -ne 0 ] | |
then | |
echo 0$NUM | |
else | |
echo $NUM | |
fi |
NewerOlder