Skip to content

Instantly share code, notes, and snippets.

View chirag64's full-sized avatar

Chirag Bhatia chirag64

View GitHub Profile
@chirag64
chirag64 / irssi.conf.md
Last active June 13, 2021 21:13
Irssi configuration
Manually editing the configuration files isn't recommended since its kind of complicated. It is recommended to configure using irssi's commands.
  • Start irssi and connect to a server. Then enter the commands.

  • Auto-connect to a server during startup. Password is server password but can be used as a user password for quick authentication. This method is useful since it authenticates you before irssi tries to connect to the channels, so you are able to join channels where authentication is required. (Password is optional and will be visible in the configuration file in plain text).

/server add -auto -ssl -ssl_verify -ssl_capath /etc/ssl/certs -network freenode irc.freenode.net 6697 password

If you keep getting SSL errors after starting irssi, try removing SSL certificate verification:

@chirag64
chirag64 / uri.js
Last active August 29, 2015 14:05 — forked from jlong/uri.js
// var parser = document.createElement('a');
// parser.href = "http://user:[email protected]:3000/pathname/?search=test#hash";
// OR
var parser = new URL("http://user:[email protected]:3000/pathname/?search=test#hash");
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
@chirag64
chirag64 / Get-Bytes.ps1
Last active September 2, 2015 11:45
Gets bytes of a file
function Get-Bytes {
<#
.SYNOPSIS
Outputs the contents of the file in bytes
.DESCRIPTION
Outputs the contents of the file in bytes
.EXAMPLE
Get-Bytes -File C:\myfile.exe -Bytes 4
.EXAMPLE
Get-Bytes C:\myfile.exe 10
@chirag64
chirag64 / Get-StringHash.ps1
Created November 13, 2014 17:55
Calculates hash of specified string
Function Get-StringHash
{
param (
[String] $String,
[ValidateSet('MD5', 'SHA1', 'SHA256', 'SHA384', 'SHA512')]
[String] $HashName = "MD5"
)
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
[Void]$StringBuilder.Append($_.ToString("x2"))
@chirag64
chirag64 / Get-FileHash.ps1
Created November 13, 2014 18:10
Calculates the file hash of an input file
function Get-FileHash
{
param (
[String] $Path,
[ValidateSet('MD5', 'SHA1', 'SHA256', 'SHA384', 'SHA512')]
$HashName = "MD5"
)
$fullPath = Resolve-Path $Path
$HashType = new-object -TypeName System.Security.Cryptography."$HashName"CryptoServiceProvider
$file = [System.IO.File]::Open($fullPath,[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
@chirag64
chirag64 / Microsoft.PowerShellISE_profile.ps1
Last active July 27, 2017 17:11
PowerShell profile - .bashrc equivalent
<#
%windir%\system32\Windows­PowerShell\v1.0\profile.ps
This is for all users of the computer and for all shells.
%windir%\system32\Windows­PowerShell\v1.0\Microsoft.Power­Shell_profile.ps1
This is for all users of the computer, but it is only for the Microsoft.PowerShell shell.
%UserProfile%\Documents\Windows­PowerShell\profile.ps1
This is for the current user only and all shells.
@chirag64
chirag64 / PSSnippets.ps1
Last active May 11, 2023 22:32
PowerShell snippets
#Create array of file list from a directory.
$arr = (dir).FullName #Get all files
$arr = (dir *.log).FullName #Get files of .log extension
#Get headers of file to identify its format.
Get-Content -Path FilePath -Encoding Byte -TotalCount 4
#Download File via http.
Invoke-WebRequest "http://filepath/file.jpg" -OutFile "C:\LocalPath\filename.jpg"
@chirag64
chirag64 / AfterRunning.ps1
Created November 20, 2014 06:19
Execute something after a process has ended via PowerShell
function AfterRunning {
param (
[String] $Process
)
while ((Get-Process $Process -ErrorAction SilentlyContinue | Select-Object -ExpandProperty ProcessName) -ne $null) {
Start-Sleep -Seconds 2
Write-Host "Process still running..."
}
}
if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) {
(function() {
var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
Object.defineProperty(Element.prototype, "textContent",
{
get: function() {
return innerText.get.call(this);
},
set: function(s) {
return innerText.set.call(this, s);
# How to use:
#
# Dependencies - scort, imagemagick, i3lock
#
# Just place a lock.png in your home folder to overlay whatever you want
#!/bin/bash
scrot -e 'convert -blur 0x3 $f ~/lockbg.png'
convert -gravity center -composite ~/lockbg.png ~/lock.png ~/lockfinal.png
i3lock -i ~/lockfinal.png -p default -e