Skip to content

Instantly share code, notes, and snippets.

View sourabhv's full-sized avatar

Sourabh Verma sourabhv

View GitHub Profile
@sourabhv
sourabhv / multipart.java
Created March 22, 2017 16:53 — forked from mcxiaoke/multipart.java
multipart request using httpurlconnection
public String multipartRequest(String urlTo, String post, String filepath, String filefield) throws ParseException, IOException {
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
InputStream inputStream = null;
String twoHyphens = "--";
String boundary = "*****"+Long.toString(System.currentTimeMillis())+"*****";
String lineEnd = "\r\n";
String result = "";
@sourabhv
sourabhv / 500pxdownload
Last active November 25, 2016 17:57
Just paste it in your console on any 500px page, and it'll be downloaded.
$("body").append($("<a id='qwerty'/>"));var u=$('.photo-focus__photo')[0].src;$('#qwerty').attr("download",u).attr("href",u);$('#qwerty')[0].click();
@sourabhv
sourabhv / Skylight.zsh-theme
Created October 3, 2016 09:12
Skylight theme for OhMyZsh
PROMPT='%{$fg_bold[cyan]%} ♪ %{$fg[blue]%}%c%{$fg_bold[blue]%}$(git_prompt_info)$(git_remote_status)%{$fg_bold[blue]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%} (%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}) %{$fg[red]%}⚡%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%})"
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="%{$fg_bold[magenta]%} ↓%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="%{$fg_bold[magenta]%} ↑%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="%{$fg_bold[magenta]%} ↕%{$reset_color%}"
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@sourabhv
sourabhv / Tree utility in Python
Last active August 29, 2015 14:06
Print contents of directories in a tree-like format
def tree(path, depth=1, max_depth=100, print_hidden=False, pad_info=[]):
'''Print contents of directories in a tree-like format
By default, it prints upto a depth of 100 and doesn't print hidden files,
ie, files whose name begin with a '.'
returns number of files, number of directories it encountered
'''
fileCount, dirCount = 0, 0
files = sorted(os.listdir(path), key=lambda s: s.lower())
@sourabhv
sourabhv / JSONSerializer
Created October 18, 2013 17:08
Django JSONSerializer to serialize Django model's fields and properties into JSON
from StringIO import StringIO
from django.core.serializers.json import Serializer
class JSONSerializer(Serializer):
'''
JSON serialize to serialize db fields and properties
Example:
>>> JSONSerializer().serialize(Model.objects.all(), ('field1', 'field2',))
'''