Skip to content

Instantly share code, notes, and snippets.

View chirag64's full-sized avatar

Chirag Bhatia chirag64

View GitHub Profile
@chirag64
chirag64 / Sleep.js
Last active December 23, 2015 00:09
Use this only in terms of desperation because this function will keep the CPU busy as long as it exits. I hate JavaScript for the lack of a proper sleep function.
function sleep(milliseconds) {
var start = new Date().getTime();
while(true) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
@chirag64
chirag64 / xrandr.sh
Last active November 11, 2024 13:13 — forked from debloper/xrandr.sh
Added license on user request
#!/bin/bash
# Copyright © 2021 Chirag Bhatia
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOF
@chirag64
chirag64 / Create-SSL-Certificate.md
Last active December 31, 2015 08:39
Steps to create SSL certificate for nginx (most steps applicable for other server softwares as well)

#####Dependency: openssl#####

  1. Create directory:
sudo mkdir /etc/nginx/ssl
cd /etc/nginx/ssl
  1. Create private server key:
@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 / 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 / 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");})();