Skip to content

Instantly share code, notes, and snippets.

Rudde

Block or report user

Report or block Rudde

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View HumanReadableTime.ps1
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"}
}
View HumanReadableBytes.ps1
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"}
}
@Rudde
Rudde / IncrementLetters.cs
Last active Aug 29, 2017
Increment letters
View IncrementLetters.cs
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
while (true)
{
@Rudde
Rudde / HTTP Cookie header parser.php
Last active Jan 20, 2019 — forked from pokeb/HTTP Cookie header parser
Quick and dirty HTTP cookie header parser in PHP
View HTTP Cookie header parser.php
@Rudde
Rudde / array_filter_key.php
Created May 14, 2016 — forked from h4cc/array_filter_key.php
Filtering a PHP array by key instead of value.
View array_filter_key.php
<?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.
*/
@Rudde
Rudde / numSuffix.lib.php
Created May 12, 2016
Take a number input output it with proper suffix like 1st, 2nd, 3rd, and so on
View numSuffix.lib.php
<?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';
@Rudde
Rudde / sec2ts.sh
Created May 10, 2016
Takes int or float seconds as input will output in format hh:mm:ss.ms where ms is rounded to 3 decimals
View sec2ts.sh
#!/bin/bash
function padnum {
NUM=$1
if [ $(echo "$NUM < 10" | bc) -ne 0 ]
then
echo 0$NUM
else
echo $NUM
fi
@Rudde
Rudde / pcp.sh
Created Apr 28, 2016
Bash copy tool giving speed and progress bar, working for files and directories built of pv
View pcp.sh
#!/bin/bash
hash pv
if [ $? -ne 0 ]; then
echo "ERROR: Command pv is not available but required, please run: sudo apt-get install pv"
exit 1
fi
WORKDIR=$(pwd)
@Rudde
Rudde / firstDayofFirstWeekinCurrentMonth.php
Last active Apr 8, 2016
Gives first day of the first week of the current month
View firstDayofFirstWeekinCurrentMonth.php
<?php
/**
* Created by PhpStorm.
* User: Rudde
* Date: 01.04.2016
* Time: 00.25
*/
function firstDayofFirstWeekinCurrentMonth($date = NULL) {
$date = is_null ($date) ? new DateTime('first day of this month') : $date->modify('first day of this month');
You can’t perform that action at this time.