Skip to content

Instantly share code, notes, and snippets.

View bogdangrigg's full-sized avatar

Luca-Bogdan Grigorescu bogdangrigg

View GitHub Profile
@bogdangrigg
bogdangrigg / log-tools.sh
Created April 29, 2019 14:26
Log parsing snippets
# Realtime lines per second in a log file
tail -f /var/log/logfile | perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}'
@bogdangrigg
bogdangrigg / Base64Tools.ps1
Last active April 19, 2019 19:55
base64 encode & decode
# encode
$Text = "Hidden secret!"
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Text) # or Unicode.GetBytes($Text), if Unicode is not needed
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText
# decode
$EncodedText = “SABpAGQAZABlAG4AIABzAGUAYwByAGUAdAAhAA==”
$DecodedText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedText))
$DecodedText
@bogdangrigg
bogdangrigg / Install-TelnetClient.ps1
Created November 15, 2018 14:23
Install the telnet client on Windows
Install-WindowsFeature -name Telnet-Client
# or
dism /online /Enable-Feature /FeatureName:TelnetClient
@bogdangrigg
bogdangrigg / Get-InternetFacingIP.ps1
Last active March 20, 2020 09:19
Returns the public / Internet-facing IP used by a host. Be careful with multiple outgoing IPs.
### WINDOWS ###
# option #1: generic version, from here: https://gallery.technet.microsoft.com/scriptcenter/Get-ExternalPublic-IP-c1b601bb
Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
# option #2: Azure metadata service
(Invoke-RestMethod -H @{'Metadata'='true'} "http://169.254.169.254/metadata/instance?api-version=2017-08-01").network.interface.ipv4.ipAddress.publicIpAddress
### LINUX ###
dig +short myip.opendns.com @resolver1.opendns.com
@bogdangrigg
bogdangrigg / http-ping.ps1
Last active December 15, 2016 18:30
http-ping.ps1
##############################################################################
## Original version @ https://gallery.technet.microsoft.com/scriptcenter/Powershell-Script-for-13a551b3
## Updated: 5/26/2015, Version 2.0, By: Sangamesh (sangameshb@yahoo) on 5/26/2015
##############################################################################
param (
[string]$url = 'https://google.com',
[switch]$t = $true,
[switch]$help
)
tcpping.exe google.com:80
nameresolver.exe google.com
public class FeedStorage
{
public FeedStorage()
{
GroupStoryChildIdList = "";
}
[PrimaryKey]
public string Id { get; set; }
public DateTime FeedItemDateTime { get; set; }
public string ItemType { get; set; }
@bogdangrigg
bogdangrigg / GET_ALL_COLUMNS.sql
Last active June 16, 2016 11:40
Get all columns for all tables & views
-- from: https://stackoverflow.com/questions/2729126/how-to-find-column-names-for-all-tables-in-all-databases-in-sql-server
SELECT
s.name as ColumnName
,sh.name+'.'+o.name AS ObjectName
,o.type_desc AS ObjectType
,CASE
WHEN t.name IN ('char','varchar') THEN t.name+'('+CASE WHEN s.max_length<0 then 'MAX' ELSE CONVERT(varchar(10),s.max_length) END+')'
WHEN t.name IN ('nvarchar','nchar') THEN t.name+'('+CASE WHEN s.max_length<0 then 'MAX' ELSE CONVERT(varchar(10),s.max_length/2) END+')'
WHEN t.name IN ('numeric') THEN t.name+'('+CONVERT(varchar(10),s.precision)+','+CONVERT(varchar(10),s.scale)+')'
ELSE t.name
@bogdangrigg
bogdangrigg / sso_login_freshdesk.cs
Created May 19, 2016 08:18 — forked from darkpssngr/sso_login_freshdesk.cs
SSO Login for Freshdesk support portal - ASP.Net C# Sample Code
static string GetSsoUrl(string baseUrl, string secret, string name, string email) {
var timems = (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();
return String.Format("{0}/login/sso?name={1}&email={2}&timestamp={3}&hash={4}",
baseUrl, Server.UrlEncode(name), Server.UrlEncode(email), timems, GetHash(secret, name, email, timems));
}
private static string GetHash(string secret, string name, string email, string timems) {
var input = name + secret + email + timems;
var keybytes = Encoding.Default.GetBytes(secret);
var inputBytes = Encoding.Default.GetBytes(input);
@bogdangrigg
bogdangrigg / gist:5ea6dcd1cac188264c6a
Created February 6, 2015 14:48
Check if any application is using the SMTP port
Get-NetTCPConnection -RemotePort 25 -ErrorAction SilentlyContinue | Format-Table