Skip to content

Instantly share code, notes, and snippets.

@Kozlov-V
Kozlov-V / crossclient.java
Last active August 29, 2015 14:21
CrossClient
import java.util.Arrays;
import java.util.List;
import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.gms.common.AccountPicker;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.accounts.AccountManager;
import android.content.Intent;
@Kozlov-V
Kozlov-V / filesize.java
Created August 24, 2015 10:47
File size to string
public static String getStringSizeLengthFile(long size) {
DecimalFormat df = new DecimalFormat("0.00");
float sizeKb = 1024.0f;
float sizeMo = sizeKb * sizeKb;
float sizeGo = sizeMo * sizeKb;
float sizeTerra = sizeGo * sizeKb;
@Kozlov-V
Kozlov-V / StringValueBytes.m
Created September 1, 2015 21:32
StringValueBytes
- (NSString *)readableValueWithBytes:(id)bytes{
NSString *readable;
//round bytes to one kilobyte, if less than 1024 bytes
if (([bytes longLongValue] < 1024)){
readable = [NSString stringWithFormat:@"1 KB"];
}
@Kozlov-V
Kozlov-V / site.conf
Created October 4, 2015 19:12 — forked from paskal/site.conf
Nginx configuration for best security and modest performance. Full info on https://terrty.net/2014/ssl-tls-in-nginx/
# read more at https://terrty.net/2014/ssl-tls-in-nginx/
# latest version on https://gist.github.com/paskal/628882bee1948ef126dd/126e4d1daeb5244aacbbd847c5247c2e293f6adf
# security test score: https://www.ssllabs.com/ssltest/analyze.html?d=terrty.net
# your nginx version might not have all directives included, test this configuration before using in production against your nginx:
# $ nginx -c /etc/nginx/nginx.conf -t
server {
# public key, contains your public key and class 1 certificate, to create:
# (example for startssl)
# $ (cat example.com.pem & wget -O - https://www.startssl.com/certs/class1/sha2/pem/sub.class1.server.sha2.ca.pem) | tee -a /etc/nginx/ssl/domain.pem > /dev/null
@Kozlov-V
Kozlov-V / andrlayout
Created April 21, 2013 16:15
Android layout, так, например, можно получить размеры
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Log.v("Log", "" + findViewById(R.id.qqq).getWidth());
}
}, 100);
@Kozlov-V
Kozlov-V / andrlayoutxml
Created April 21, 2013 16:38
To provide a special layout for landscape, including while on large screens, then you need to use both the large and land qualifier:
MyProject/
res/
layout/ # default (portrait)
main.xml
layout-land/ # landscape
main.xml
layout-large/ # large (portrait)
main.xml
layout-large-land/ # large landscape
main.xml
@Kozlov-V
Kozlov-V / andrcam
Last active December 16, 2015 11:58
Пример кода для работы с камерой. Задача этого кода, подогнать соотношение сторон окна (экрана телефона) и соотношения сторон кадра с камеры и повернуть изображение соответственно ориентации телефона.
Size previewSize = camera.getParameters().getPreviewSize();
float aspect = (float) previewSize.width / previewSize.height;
int previewSurfaceWidth = preview.getWidth();
int previewSurfaceHeight = preview.getHeight();
LayoutParams lp = preview.getLayoutParams();
if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
{
// портретный вид
#!/bin/sh
mkdir ~/down/
cd ~/down/
sudo apt-get install build-essential
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar -xzf Python-2.7.2.tgz
cd Python-2.7.2
sudo apt-get install libsqlite3-dev zlib1g-dev libncurses5-dev
sudo apt-get install libgdbm-dev libbz2-dev libreadline5-dev
sudo apt-get install libssl-dev libdb-dev
%%%-------------------------------------------------------------------
%%% @author egobrain <egobrain@linux-ympb>
%%% @copyright (C) 2012, egobrain
%%% @doc
%%% Function for uploading files and properties,which were sent as a
%%% multipart. Files are stored in tmp_folder with random name,
%%% generated by tmp_filename function.
%%% @end
%%% Created : 25 Mar 2012 by egobrain <egobrain@linux-ympb>
%%%-------------------------------------------------------------------
@Kozlov-V
Kozlov-V / file_to_ins.java
Last active December 20, 2015 13:19
file to inputstream
File file = ...
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} finally {
if (in != null) {
try {
in.close();