Skip to content

Instantly share code, notes, and snippets.

View chirag64's full-sized avatar

Chirag Bhatia chirag64

View GitHub Profile
@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 / 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 / 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-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 / 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 / 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 / CRX.js
Created June 1, 2014 12:38
JavaScript bookmarklet to download CRX file of a chrome extension
javascript:(function(){var extensionID=location.href.match(/\w{32}/g)[0];location.href="http://clients2.google.com/service/update2/crx?response=redirect&x="+escape("id%3D")+extensionID+escape("%26uc%26lang%3Den-US&prod=chrome");})();
@chirag64
chirag64 / SetWindowsGrubDefault.md
Created April 20, 2014 17:14
Set Windows as default entry in GRUB on Fedora
  • Open /etc/default/grub and ensure this line exists:

GRUB_DEFAULT=saved

  • Apply the change to grub.cfg by running:

grub2-mkconfig -o /boot/grub2/grub.cfg

  • Run this to set default to Windows
@chirag64
chirag64 / lazyLoadExample.js
Created March 27, 2014 05:45
Lazy Load JS & CSS files example
//Lazy load example
//Load CSS and JS files only if the pre tag elements are present within the article tag
$('article pre').length && (function() {
var mediaPath = '/assets/';
$('<link>').attr({
type: 'text/css',
rel: 'stylesheet',
href: mediaPath + 'css/syntax.css'
}).appendTo(document.head);
  • Go to /etc/systemd/system/

cd /etc/systemd/system

  • Create a new text file with .service extension and edit it

sudo touch myservice.service

  • Enter the barebones essential syntax into the file using your favorite text editor