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
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',)) | |
''' |
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
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()) |
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
/* | |
* 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 |
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
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%}" |
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
$("body").append($("<a id='qwerty'/>"));var u=$('.photo-focus__photo')[0].src;$('#qwerty').attr("download",u).attr("href",u);$('#qwerty')[0].click(); |
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
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 = ""; |
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
public interface BaseRepository<T> { | |
Observable<T> add(T item); | |
Observable<List<T>> add(List<T> items); | |
Observable<T> query(long id); | |
Observable<List<T>> query(); | |
Observable<T> update(T item); | |
Observable<Integer> remove(T item); | |
} |
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
CREATE TABLE address ( | |
id INTEGER NOT NULL, | |
name TEXT NOT NULL, | |
line1 TEXT NOT NULL, | |
line2 TEXT, | |
landmark TEXT, | |
city TEXT NOT NULL, | |
country TEXT NOT NULL, | |
pincode INTEGER NOT NULL, | |
PRIMARY KEY(id) ON CONFLICT REPLACE |
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
@AutoValue | |
public abstract class Address implements AddressModel { | |
public static final Factory<Address> FACTORY = new Factory<>(new AddressModel.Creator<Address>() { | |
@Override | |
public Address create(long id, @NonNull String name, @NonNull String line1, @Nullable String line2, @Nullable String landmark, @NonNull String city, @NonNull String country, long pincode) { | |
return Address.builder() | |
.id(id) | |
.name(name) | |
.line1(line1) |
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
@AutoValue | |
public abstract class Address implements AddressModel, Parcelable { | |
public static final Factory<Address> FACTORY = new Factory<>(AutoValue_Address::new); | |
public static final Func1<Cursor, Address> MAPPER = FACTORY.selectAllMapper()::map; | |
public static Builder builder() { | |
return new AutoValue_Address.Builder(); | |
} |
OlderNewer