Skip to content

Instantly share code, notes, and snippets.

View vishaltelangre's full-sized avatar

Vishal Telangre vishaltelangre

View GitHub Profile
@vishaltelangre
vishaltelangre / pg_gem_installation_error_and_solution.txt
Last active March 16, 2024 01:50
pg (postgresql) gem installation error and solution [ubuntu 12.04]
ERROR
=======
$ gem install pg -v '0.17.0'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/vishal/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for pg_config... yes
@vishaltelangre
vishaltelangre / youtube-dl-aria
Created April 14, 2014 07:12
aria2 youtube download
# aria2c must be installed before moving on
sudo curl https://yt-dl.org/downloads/2014.04.04.2/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+x /usr/local/bin/youtube-dl
sudo curl https://raw.githubusercontent.com/tobbez/youtube-dl-aria/master/youtube-dl-aria -o /usr/local/bin/youtube-dl-aria
sudo chmod a+x /usr/local/bin/youtube-dl-aria
# Usage:
youtube-dl-aria --get-filename -o "%(title)s.%(ext)s" OWHJa0jKJgo
# ^
# |
@vishaltelangre
vishaltelangre / nginx_assets.md
Last active October 3, 2023 19:30
Serving Static Assets via Nginx

Concept

  • People talk about two servers: a web server (e.g. Nginx, Apache, etc.) and a app server (e.g. Language specific servers like Unicorn, Node.js, Tomcat, Http-Kit, etc.). There are exceptions where app servers not required at all (as web server itself provides preprocessors for handling), but let's not talk about now.
  • Web servers are really fast and supports lot of standard and commonly used MIME-type requests. Concept of serving a file is -- forming and sending a response of bytes of data and labeling it with requested MIME-type by a client (e.g. web browser).
  • Every response format (in layman's language, a file) is recognized by it's MIME-type, for e.g. a PNG image file has "image/png" MIME-type. JavaScript file has "text/javascript". HTML responses (or files) has "text/html". Plain text files have "text/plain".
  • Modern Browsers supports a lot of standard MIME-types. Images, videos, text files (XML, HTML, SVG, JS), and they better know how to visualize it. Browser also knows unrec
@vishaltelangre
vishaltelangre / recurrentlyBackupGoogleSpreadsheet.js
Last active April 12, 2023 13:00
Recurrently backup Google spreadsheets #backup #google #sheet #backupgooglesheet
// Instructions
//
// 1. Open the spreadsheet that you want to backup in Google Drive.
// 2. Go to Extensions -> Apps Script.
// 3. Copy and paste the code below into the editor. Change "Untitled" script name
// to something meaningful
// 4. Save and run the script. You will have to authorize access.
// 5. Go to the spreadsheet's parent folder in Google Drive.
// 6. Make sure that the backup folder and the year folder have been created.
// 7. Go to the year folder and make sure that the backup file has been created.
@vishaltelangre
vishaltelangre / tools_i_use.md
Last active July 11, 2022 12:43
Tools I Use #tools_i_use

Shell

  • z - Easily jump around
  • tmux - Sessions, windows, panes, whoa! (key-bindings)
    • On a remote server, tmux -CC [attach] mode from iTerm2. More details here.
  • https://asciinema.org - Record and share terminal sessions as video (very lightweight!)
  • FiraCode Nerd Font (previously used FiraCode, mononoki and Consolas)
  • fzf - Fuzzy reverse search (using Ctrl-R)
  • nvim with Nvchad
  • gifgen - video to GIF converter
  • Create /etc/logrotate.d/my-crazy-app file with following snippet:
/var/log/my-crazy-app/*.log {
        daily
        size 500M
        missingok
        rotate 10
        compress
 delaycompress
@vishaltelangre
vishaltelangre / post_message_example.js
Last active March 24, 2022 04:47
window.postMessage example
// recieve message
// event object contains:
// - data: message sent
// - origin (host from which the message was sent, e.g. http://blah.example.com)
// - source (reference to a Window object from which message was sent)
function postMessageHandler( event ) {
console.log("We've got a message!");
console.log("* Message:", event.data);
console.log("* Origin:", event.origin);
console.log("* Source:", event.source);
@vishaltelangre
vishaltelangre / mac_locate_big_files.md
Last active February 22, 2022 00:55
Locate big files on macOS #mdfind #find #bigfiles
$ mdfind 'kMDItemFSSize > 200000000' | sed 's| |\\ |g' | xargs du -sch
#                             ^
#                         ~ 200MiB
@vishaltelangre
vishaltelangre / java_ruby_unsigned_int_to_hex.rb
Created January 8, 2014 06:59
ruby converting an unsigned int to hexadecimal (java-like implementation)
# In Java, the following expression
# Integer.toHexString(1286933134)
# produces:
# "4cb50a8e"
# and
# Integer.toHexString(-1286933134)
# produces:
# "b34af572"
# ref doc: http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#toHexString(int)
@vishaltelangre
vishaltelangre / auto_install_sublime_packages.markdown
Last active May 24, 2021 15:15
[Automate Packages Installation in Sublime Text 2] -- Automatically install Sublime Text 2 packages (some necessary ones, w/o fucking crap ones which makes sublime alike hell!)
  • To install packages, every time pressing ' ctrl+shift+pPackage Control: Install Package is very cumbersome task... right?

  • After fresh installation of ST2, open it and ctrl+` and hit enter after pasting below line [(1)][1]:

  import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')
  • Restart ST2.

  • Open terminal, and navigate to Sublime's dir under your home folder by below command and create file w/ name Package Control.sublime-settings there in: