Skip to content

Instantly share code, notes, and snippets.

View chirag64's full-sized avatar

Chirag Bhatia chirag64

View GitHub Profile
@chirag64
chirag64 / SocialShareCount.js
Created February 19, 2014 16:27
Use this to get the Facebook & Twitter social share counts of a web page
function twitterCallback(result) {
result.count && console.log('The count is: ', result.count);
}
function getTwitterCount(url) {
var script = document.createElement('script');
script.async = true;
script.src = 'http://urls.api.twitter.com/1/urls/count.json?url=' + url + '&callback=twitterCallback';
document.body.appendChild(script);
}

Scenario: Connect from Laptop to Desktop using SSH without password prompt.

  1. Login to Laptop terminal.

  2. Make sure there is a .ssh directory in home folder of user and that it is only accessible to the user:

mkdir ~/.ssh
chmod 700 ~/.ssh
  • 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
@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);
@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 / uri.js
Last active August 29, 2015 14:05 — forked from jlong/uri.js
// var parser = document.createElement('a');
// parser.href = "http://user:secretpassword@example.com:3000/pathname/?search=test#hash";
// OR
var parser = new URL("http://user:secretpassword@example.com: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-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 / 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);