Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'public/' content from commit 07faafc
git-subtree-dir: public git-subtree-split: 07faafc14603bfffc69153d6c3e06bf99e50cab6
- Loading branch information
0 parents
commit 11c8553
Showing
599 changed files
with
54,896 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"bitwise": true, | ||
"browser": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"eqnull": true, | ||
"es5": false, | ||
"esnext": true, | ||
"immed": true, | ||
"jquery": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"strict": false, | ||
"trailing": false, | ||
"undef": true, | ||
"multistr": true, | ||
"expr": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
prakhar.me |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
> Hugo | ||
New Blog in using [Hugo](http://gohugo.io/). |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
+++ | ||
Date = "2014-04-07" | ||
author = "Prakhar Srivastav" | ||
+++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
baseurl = "http://prakhar.me" | ||
languageCode = "en-us" | ||
title = "cat /dev/random" | ||
contentdir: "content" | ||
layoutdir: "layouts" | ||
publishdir: "public" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
+++ | ||
title = "About" | ||
nopaging = true | ||
nodate = true | ||
+++ | ||
|
||
Hi there. | ||
|
||
I'm Prakhar Srivastav and I love building things (mostly for the web) and celebrating the joy of programming. In my free time I enjoy gaming, [doing courses](https://www.class-central.com/@prakhar) and trying out new programming languages. | ||
|
||
I use this blog as a place to redirect random streams of thoughts (much like `/dev/random`), ideas and rants about software development, programming and other things that interest me. | ||
|
||
<p>If you’d like to connect, feel free to <a href="mailto:prakhar1989@gmail.com">email</a> or stalk me elsewhere on the web | ||
<h1 class="social-me"> | ||
<a title="Github" href="http://github.com/prakhar1989"><i class="ion-social-octocat"></i></a> | ||
<a title="Hacker News" href="https://news.ycombinator.com/user?id=krat0sprakhar"><i class="ion-social-hackernews-outline"></i></a> | ||
<a title="Twitter" href="https://twitter.com/prakharsriv9"><i class="ion-social-twitter"></i></a> | ||
<a title="LinkedIn" href="https://www.linkedin.com/in/prakharsrivastav"><i class="ion-social-linkedin-outline"></i></a> | ||
</h1></p> | ||
|
||
### Colophon | ||
|
||
This website would not have been possible without the open-source contributions of numerous programmers. It is written in Vim and compiled into HTML | ||
using [Hugo](http://gohugo.io) - a static site generator in [Go](https://golang.org/). | ||
|
||
For the design, it uses the excellent minimalistic CSS framework called [Skeleton](http://getskeleton.com). Beautiful [icons](http://ionicons.com/) on the site are courtesy of the team behind the awesome [Ionic Framework](http://ionicframework.com/). | ||
|
||
For typography, it uses the [Source Serif Pro](https://github.com/adobe-fonts/source-serif-pro) open sourced by Adobe. Sans-serif goodness is provided by [Raleway](https://github.com/theleagueof/raleway). | ||
|
||
Lastly, [Git](http://git-scm.com/) is used to publish on Github, where all the code for this website is freely [available](https://github.com/prakhar1989/prakhar1989.github.com). | ||
|
||
### Subscribe | ||
|
||
If you like what you see, subscribe below to get content delivered straight to your inbox. I pinky swear I won't spam. | ||
|
||
<div id="mc_embed_signup"> | ||
<form action="//prakhar.us8.list-manage.com/subscribe/post?u=46da35e130c3a9ab7e4a5e631&id=608c6bc1fc" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate> | ||
<div id="mc_embed_signup_scroll"> | ||
|
||
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required> | ||
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--> | ||
<div style="position: absolute; left: -5000px;"><input type="text" name="b_46da35e130c3a9ab7e4a5e631_608c6bc1fc" tabindex="-1" value=""></div> | ||
<input type="submit" class="button button-primary" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<!--End mc_embed_signup--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
date: 2014-02-27T12:34:58+03:00 | ||
title: A Few Git Tricks | ||
tags: [git] | ||
--- | ||
|
||
I just finished reading the [Think Like (a) Git](http://think-like-a-git.net/) book which is a *advanced beginners* introduction to Git. Below is a quick rundown of a few cool git commands I learned about. Read on below to level up your Git skillz! | ||
|
||
### git add file --patch | ||
|
||
Touted as the [most powerful feature that you will ever use](https://news.ycombinator.com/item?id=4744405) the patch mode allows you to selectively move changes from your working copy into the staging area. What does this mean? What this means is that instead of moving the entire set of changes on working copy into the staging area (for commit and push) it allows you to select what git calls `hunks` and commit them. This lets you keep changes that you are unsure about locally instead of keeping them stashed somewhere and keeps your commits clean and focused to one specific functionality. | ||
|
||
Only recently I learned ([thanks to Ryan Tomayko](http://tomayko.com/writings/the-thing-about-git)) that this is one of those features that makes git super powerful as a VCS when compared to other VCS's. How do you use this awesome feature you ask? Here's how [^1] - | ||
|
||
I have a file `new.txt` that has few parts that are intended to be committed for this release and other parts that can wait for later. You get a call from your colleague and you are told the first fix is required immediately so you are required to stop all your work and commit **ASAP** | ||
|
||
``` | ||
$ git status | ||
# On branch master | ||
# Changes not staged for commit: | ||
# modified: new.txt | ||
``` | ||
|
||
To selectively commit the urgent changes, I use the `git add new.txt --patch` command at which stage git prompts me with the first hunk that it has identified with a set of options regarding what I can do with it. To cycle to the next hunk you need to tell git what to do with the current one. If the single-letter commands feel confusing you can try the `?` command that will show you a helpful list of what all actions you can carry out on this (and other) hunks. | ||
|
||
``` | ||
$ git add -p new.txt | ||
diff --git a/new.txt b/new.txt | ||
index e69de29..274a6fb 100644 | ||
--- a/new.txt | ||
+++ b/new.txt | ||
@@ -0,0 +1,6 @@ | ||
+# this is for the first release | ||
+puts "hello world" | ||
+ | ||
+ | ||
+# this is for the second release | ||
+puts "bye world" | ||
Stage this hunk [y,n,q,a,d,/,e,?]? | ||
``` | ||
|
||
Git decides on hunks based on white-space and since nothing was added in the file before, it considers all of the code as just one hunk. Ideally, you would have already committed code separating spaced edits in which case you can easily just use `s` to tell git to split the hunk for you. I, however, will you use the `e` command to edit the hunk git has identified. | ||
|
||
To edit a hunk (git gives you a friendly message here as well about how to edit) you can use # to remove a line from a hunk and add a + to add line to the hunk. In my case, I simply prefix the second release code with a # and mark it out of the hunk. Now I can easily do a `git commit -m "first release ready"` and push my changes to the remote branch. | ||
|
||
Lastly, if you like this then you can surely try out `git add --interactive` which gives you a whole lot of other options and allows you to have more fine grained control on how you want your staging area to change. You can read [this](http://git-scm.com/book/en/Git-Tools-Interactive-Staging) page for a nice intro. | ||
|
||
### git commit --amend | ||
|
||
Was there a time when you hurriedly typed `git commit -m "bug 1337 - pwned"` but only as you run your test-suite you realize that the bug still remains (or worse - you have broken something else in the process). You slap your head disappointed with the premature commit, roll up your sleeves and fix the bug. This time; for good. In this case, your next commit probably looks like `git commit -m "bug 1337 - pwned for good"` | ||
|
||
If you're like me you probably do this 10 times (yes, I love `git commit` THAT much), this command will really help you clean up your over-excited commits. This is how it works | ||
|
||
```bash | ||
$ git commit -am "bug pwned" | ||
$ # write some kick-ass code to fix the bug (really) | ||
$ git commit -am "bug pwned" --amend | ||
|
||
$ git log | ||
commit c841103a1babe33b76add3034ba4921221becce1 | ||
Author: Prakhar Srivastav <prakhar1989@gmail.com> | ||
Date: Wed Feb 19 21:04:45 2014 +0300 | ||
|
||
bug pwned | ||
``` | ||
|
||
The last command will overwrite your old commit message and help you keep a straight face in front of your boss when he checks those commits. | ||
|
||
### git cherry-pick | ||
|
||
Last week I working was on a [project](https://github.com/a85/PostmanInterceptor) where our work spanned across multiple git branches. At one time, I simply needed to replay the work (one specific commit) I had done in one branch onto another. It was not the right time for a merge hence the only option was to manually make those changes. That's when a friend introduced me to `git cherry-pick`. As evident, this command allows you to selectively pick commits and replay the changes. If you have small code patches to be moved across branches, `cherry-pick` is your friend. To use cherry pick, simply refer the commit SHA hash and you're done. | ||
|
||
```bash | ||
$ git cherry-pick 5d3e1b6 | ||
Finished one cherry-pick. | ||
[master e458a9b] Bug fixes for :contains() another-class. | ||
3 files changed, 36 insertions(+), 3 deletions(-) | ||
``` | ||
|
||
### git extras | ||
|
||
[Git Extras](https://github.com/visionmedia/git-extras) is a set of very useful git utilities that was developed by the extremely prolific node hacker - TJ Holowaychuk. My personal favorite includes `git summary` which gives a great summary of how long the project has been active along with author contributions and `git effort` which gives a very cool heat-map around what files have been worked on the most. Be sure to checkout the project, it'll surely make your git journey even more fun! | ||
|
||
```shell | ||
$ git summary | ||
|
||
project : httpbin | ||
repo age : 2 years, 9 months | ||
active : 103 days | ||
commits : 359 | ||
files : 21 | ||
authors : | ||
298 Kenneth Reitz 83.0% | ||
7 Rodrigo Chacon 1.9% | ||
7 Kyle Conroy 1.9% | ||
5 Zbigniew Siciarz 1.4% | ||
4 Chris Dary 1.1% | ||
3 Steven Honson 0.8% | ||
. ...... ... | ||
``` | ||
|
||
[^1]: If you're the GUI kind of guy, you can simply use a [good](http://www.sourcetreeapp.com/) [enough](http://gitx.frim.nl/) git UI to do all this for you. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: A Happy Accident | ||
date: 2014-09-13T12:34:58+03:00 | ||
tags: [rant] | ||
--- | ||
|
||
Last week, I was pleasantly surprised to find an email by a correspondent of [Economic Times](http://economictimes.indiatimes.com/) (a leading newspaper in India) asking for permission to quote a comment I made on [Hacker News](https://news.ycombinator.com/item?id=7698688) in the newspaper's front page! | ||
|
||
> I hope they have India on their radar! It would be awesome for the Indian Startup scene to hear all those great speakers live! | ||
<figure> <img src="/images/et.jpg"> </figure> | ||
|
||
Who knew that a comment on HN would end up on the front-page of a newspaper! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
--- | ||
title: Application Structure | ||
tags: [python, flask] | ||
date: 2013-05-07T12:34:58+03:00 | ||
--- | ||
|
||
In this post, we're going to talk about a seemingly easy but an important topic - organizing and structuring your flask applications. | ||
|
||
As mentioned earlier, getting started with flask is super easy. Unlike django, flask doesn't follow a directory structure when you start a new app. Flask will not complain even if all of your code resides in a single `main.py` file. But we all know that that is not the way to go. Having all your code in one file makes it messy and unmaintainable. | ||
|
||
Lets assume that you've gone through the throughly explained [flaskr tutorial](http://flask.pocoo.org/docs/tutorial/) (which you definitely should in case you haven't) and unable to contain the excitement you start a new flask app. As you keep writing more code and see it working you start getting that nice feeling about the awesomeness of flask. However, as your code keeps growing and since its all in a single file you start getting frustrated. Configurations, models, views etc. should definitely go in separate files, you think, so that your application is kept modular. But where do you start? | ||
|
||
This post will provide you an answer and show you a good way of structuring your apps. For starters, the flask [patterns site](http://flask.pocoo.org/docs/patterns/packages/) provides an easy-to-follow tutorial for structuring an app. This post will cover that and will go beyond by covering configuration module and an extension called [flask-script](http://flask-script.readthedocs.org/en/latest/). Lets get started! | ||
|
||
|
||
### Packages | ||
For larger applications going the packages way is generally a good idea. A small app might look like this - | ||
|
||
``` | ||
- myapp | ||
|- static | ||
|- templates | ||
|- main.py | ||
``` | ||
|
||
To change this into a python module all you need to do is move the files in a separate folder and create a new file ( or rename the existing `main.py` ) `__init__.py` so that python can interpret the folder as a module. After re-structuring your app will look like this - | ||
|
||
``` | ||
- myapp | ||
|- hello | ||
|-- __init__.py | ||
|-- static | ||
|-- templates | ||
|-- main.py | ||
``` | ||
|
||
The next step is to separate app initialization, models and views declaration from your `__init__.py`. To do that write the following code in your `__init__.py`. Note: I'm assuming that you're assuming sqlalchemy as your ORM. Additionally, I've used hello as the name of the app folder. | ||
|
||
``` | ||
# flask imports go here | ||
from flask import Flask | ||
from flask.ext.sqlalchemy import SQLAlchemy | ||
import os | ||
# declaring the app | ||
app = Flask(__name__) | ||
# get the base dir | ||
base_dir = os.path.dirname(os.path.abspath(__file__)) | ||
app.config.from_pyfile(os.path.join(base_dir, '../app.cfg')) | ||
# create db | ||
db = SQLAlchemy(app) | ||
# importing views | ||
import hello.views | ||
# import models | ||
from hello.models.person import Person | ||
``` | ||
|
||
In this code, you'll notice that `hello.views`, `hello.models.person` and `app.cfg` are missing files. Don't worry, we'll create them soon. The rest of the code is self-explainatory. We get the base directory so that we can easily reference the config file to instantiate our app. | ||
|
||
### Application Configuration | ||
|
||
The next step is to create the missing files. In your app (in my case - | ||
hello) folder, create a new folder called `models` and add your models | ||
(either separately or all in single file). Dont forget to create a | ||
blank `__init__.py` file in this folder as well. Next, create a file | ||
called `app.cfg` to store your configuration. This file should reside | ||
alongside your app (or hello) folder. Finally, inside your app (or | ||
hello) folder add all your views in a file `views.py`. Below is a sample | ||
excerpt of how your files should look like. | ||
|
||
``` | ||
# sample app.cfg | ||
DEBUG = True | ||
SECRET= "mysupersecretkey" | ||
# dummy model inside models folder | ||
# filename hello/models/dummy.py | ||
from hello import db | ||
class Dummy(db.Model): | ||
pass | ||
# views inside hello/views.py | ||
from hello import app | ||
from hello.models.dummy import Dummy | ||
from flask import render_template | ||
@app.route('/') | ||
def hello(): | ||
return render_template('index.html') | ||
``` | ||
|
||
At this stage this is how your structure looks like - | ||
|
||
``` | ||
- myapp | ||
|- app.cfg | ||
|- hello | ||
|-- __init__.py | ||
|-- static/ | ||
|-- templates/ | ||
|-- views.py | ||
|-- models/ | ||
|--- __init__.py | ||
|--- dummy.py | ||
``` | ||
|
||
If you've noticed we still haven't told our app to run. To do that, create | ||
a new file called `manage.py` alongside `app.cfg` and enter the | ||
following code - | ||
|
||
``` | ||
from hello import app | ||
from hello import db | ||
if __name__ == "__main__": | ||
app.run() | ||
``` | ||
|
||
Now that you have everything setup, your app should work. Give it a go by running `python manage.py` | ||
and make sure there aren't any import errors. | ||
### Flask Script | ||
|
||
One last thing I need to introduce before we wrap up is a flask extension called | ||
[flask-script](http://flask-script.readthedocs.org/en/latest/). The | ||
flask-script extensions provides support for writing scripts and makes | ||
it super easy to add commands that can runserver, open shell, manage | ||
cronjobs and other things right from the terminal. The documentation for | ||
the extension is very easy to follow and I encourage you to give it a | ||
read. I've edited the `manage.py` file and added support for | ||
flask-script. | ||
|
||
``` | ||
from flask.ext.script import Manager, Server, Shell | ||
from hello import app | ||
from hello import db | ||
# (optional) - include models if you want to! | ||
import hello.models as models | ||
def _make_context(): | ||
""" context for passing into to the shell command """ | ||
return dict(app=app, db=db, models=models) | ||
# set manager | ||
manager = Manager(app) | ||
# add commands | ||
manager.add_command("runserver", Server()) | ||
manager.add_command("shell", Shell(make_context = _make_context)) | ||
if __name__ == "__main__": | ||
manager.run() | ||
``` | ||
|
||
After making these changes, simply run `python manage.py runserver` to | ||
run the app and `python manage.py shell` to jump into a python shell | ||
with your application context, db and models loaded! | ||
|
||
I hope this has been a fun tutorial for you to follow. If there are any | ||
issues feel free to email me. | ||
|
||
The code for this lesson is available on my [github](https://github.com/prakhar1989/flask-tuts/tree/master/lesson-1/hello). | ||
|
||
In the next post we're going to delve further into the topic of project structure by taking a look at **blueprints in Flask**. | ||
|
||
See you next time! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: Armin on Rust | ||
date: 2014-10-01T12:34:58+03:00 | ||
tags: [rust] | ||
--- | ||
|
||
I've been trying out Rust for some time and have been totally loving it so far. Glad to see that Armin Ronacher, one of the programmers I highly respect [feels the same](http://lucumr.pocoo.org/2014/10/1/a-fresh-look-at-rust/)! | ||
|
||
> Rust is inspiring for many reasons. The biggest reason I like it is because it's practical. I tried Haskell, I tried Erlang and neither of those languages spoke "I am a practical language" to me. I know there are many programmers that adore them, but they are not for me. Even if I could love those languages, other programmers would never do and that takes a lot of enjoyment away. | ||
One aspect that Armin doens't mention is the Rust community. In my (relatively small) experience I have felt that the community is extremely friendly and open to new comers. Case in point: I submitted a [pull-request](https://github.com/Hoverbear/rust-rosetta/pull/224) to a popular rust project and I got a number of comments from reviewers pointing out my mistakes and showing me idiomatic Rust code. All in all, they made me feel very welcome and inspired me to keep writing more Rust. | ||
|
||
> Rust has been changing for years now in such dramatic ways that coming back after two months feels almost like working in a different language | ||
This is indeed true. The language changes so fast that builds spaced even a week apart cause the same code to not compile anymore. Overall, I feel that is great and although that might lead to frustration it shows that the Rust team is dedicated to improving the language. | ||
|
||
There's this famous quote by Alan Perlis where he says - | ||
|
||
> A language that doesn't affect the way you think about programming, is not worth knowing | ||
Rust is definitely a language that changes the way you think. The concepts of borrowing and data races are typically foreign to a programmer who's spent most of his time on languages like Python, Javascript, Java and having to think about these concepts is extremely enlightening. | ||
|
||
Overall, if you're looking to learn a programming language that changes the way you think and want to have fun at the same time pick Rust. You will not be disappointed. |
Oops, something went wrong.