Skip to content

Instantly share code, notes, and snippets.

View shrayasr's full-sized avatar

Shrayas Rajagopal shrayasr

View GitHub Profile
@shrayasr
shrayasr / sort-and-awk-inside-file.md
Last active August 29, 2015 14:16
Summing a list of numbers from within a file using the shell

File containing numbers

Andaman Nicobar,25
Andhra Pradesh,3550
Arunachal Pradesh,37
Assam,616
Bihar,1777
Chandigarh,32
Chhattisgarh,313
Dadra & Nagar Haveli,3
@shrayasr
shrayasr / bulk-insert-sa.md
Last active December 11, 2020 16:04
Bulk Inserts via SQLAlchemy and Flask-SQLAlchemy

Bulk Inserts via SQLAlchemy and Flask-SQLAlchemy

Problem

I ran into an issue today where I had to perform a bulk insert into a postgres DB. I was already using SQLAlchemy and Flask-SQLAlchemy to manage the connections to the db and I didn't want to have to use things like psycopg2 directly.

Solution

Note: SQLAlchemy provides an ORM. It isn't just an ORM. That is an important thing to be kept in mind. This means that you can bypass choose to not use the ORM layer when you don't want it. The idea with an ORM is to track changes to objects and when you have a case like that is when you'd use the ORM. In a bulk upload scenario, you don't need to track changes to objects. All you care is that everything be pushed into the DB.

@shrayasr
shrayasr / emmet-awesomeness.md
Last active August 29, 2015 14:17
Emmet Awesomeness

Emmet Awesomeness

Lets face it, writing HTML is really not a fun thing to do. With so many < and so many > and all the horrific closing tags. There has to be a better way.

Enter Emmet. Emmet is a plugin for many text editors that makes the job of writing HTML super easy. It provides a bunch of abbreviations whose syntax is inspired by CSS.

@shrayasr
shrayasr / keybase.md
Created March 25, 2015 18:24
keybase.md

Keybase proof

I hereby claim:

  • I am shrayasr on github.
  • I am shrayasr (https://keybase.io/shrayasr) on keybase.
  • I have a public key whose fingerprint is 12A3 E09D 419C 1251 CEDA 92F9 3375 F9A3 8F7E CFC6

To claim this, I am signing this object:

@shrayasr
shrayasr / mountsharedfolder.md
Last active August 29, 2015 14:23
Mounting a shared folder on ubuntu using Virtual Box
  • Create a transient shared folder via virtualbox shared folder settings. Note down the name of the created folder

  • Create a folder in your home directory where you want to mount this share

      $ mkdir ~/share
    
  • Issue the command to mount the Vbox share in the directory just created

$ sudo mount -t vboxsf ~/share/

public class AccountController : Controller
{
//
// GET: /Account/
public ActionResult Index()
{
return RedirectToAction("Login");
}
@shrayasr
shrayasr / irctc.js
Last active January 11, 2018 16:36
IRCTC Tatkal ticket Booking JS helpers
// To be used in conjunction with [Magic Autofill](http://ctrlq.org/irctc/)
/****************************
* TESTED ON CHROME ONLY.
****************************/
// Absolutely required function because of IRCTC's stupid ID naming scheme.
function jq( myid ) {
return "#" + myid.replace( /(:|\.|\[|\]|,)/g, "\\$1" );
}
@shrayasr
shrayasr / rmwindows10.bat
Created August 2, 2015 13:55
Remove onedrive from windows 10
@echo off
cls
set x86="%SYSTEMROOT%\System32\OneDriveSetup.exe"
set x64="%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe"
echo Closing OneDrive process.
echo.
taskkill /f /im OneDrive.exe > NUL 2>&1
ping 127.0.0.1 -n 5 > NUL 2>&1
@shrayasr
shrayasr / 0_start
Last active August 29, 2015 14:27
lein-ring setting readonly attribute to files on windows
# Start a new compojure project
$ lein new compojure win-ro-problem-test
@shrayasr
shrayasr / snl.clj
Last active September 14, 2015 09:48
Snakes and Ladders - Functional Conf 2015 - Code Jugalbandi challenge
(def snls {2 99 ; ladder
7 70 ; ladder
71 3 ; snake
50 5 ; snake
98 1 ; snake
})
(defn roll-dice []
(+ (rand-int 6) 1))