Skip to content

Instantly share code, notes, and snippets.

View alxsimo's full-sized avatar
💙
Loving what I do

Alex Simonescu alxsimo

💙
Loving what I do
View GitHub Profile
@alxsimo
alxsimo / CookieHelper
Created October 7, 2014 14:39
[Android] CookieHelper - Saves cookies retrieved from Apache HTTP Client to SharedPreferences
package com.alexsimo.utils.network;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.util.Base64InputStream;
import android.util.Base64OutputStream;
import android.util.Log;
@alxsimo
alxsimo / CustomHttpClient
Created October 7, 2014 14:40
[Java] Custom HTTP Client (Apache) with cookies
package es.ineco.sima.helper.network;
/**
* Created by alexandru.simonescu on 29/09/2014.
*/
import android.content.Context;
import android.util.Log;
import java.io.BufferedReader;
@alxsimo
alxsimo / dp2px
Created October 27, 2014 12:37
[Android] Convert DP to Pixel
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
@alxsimo
alxsimo / screen_density
Created December 25, 2014 15:31
[Android] Size and screen density
public void determineScreenDensity() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int density = metrics.densityDpi;
if (density==DisplayMetrics.DENSITY_HIGH) {
Toast.makeText(this, "DENSITY_HIGH: " + String.valueOf(density), Toast.LENGTH_LONG).show();
}
else if (density==DisplayMetrics.DENSITY_MEDIUM) {
Toast.makeText(this, "DENSITY_MEDIUM: " + String.valueOf(density), Toast.LENGTH_LONG).show();
@alxsimo
alxsimo / backup_linux
Last active August 29, 2015 14:13
[SYS] Backup Scripts
#!/bin/bash
# /usr/bin/backup
# Backup www folder + database
# author: Alexandru Simonescu
#
a=$(date +%T-%d_%m_%Y)
b=$(date +%d_%m_%Y)
mkdir /home/webserver_backups/$b/
cp -i -p -R /var/www/museo /home/webserver_backups/$b/museo_$a
@alxsimo
alxsimo / servlet_maven
Created January 17, 2015 20:43
[J2EE] The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
@alxsimo
alxsimo / device_density
Created January 22, 2015 15:42
[Android] Device display density
switch (getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_LOW:
// ...
break;
case DisplayMetrics.DENSITY_MEDIUM:
// ...
break;
case DisplayMetrics.DENSITY_HIGH:
// ...
break;
@alxsimo
alxsimo / hidde_log_menu
Created January 24, 2015 17:53
[Huawei] Log hidden menu for Huawei Ascen G510
Dial
*#*#2846579#*#*
You will see a hidden menu. Go ProjectMenu / Background Setting / Log setting and define the log availability (log swith) and level (log level setting)
And then make sure you restart your phone
Please note this probably only applies to Huawei phones
@alxsimo
alxsimo / sqlite_non_rooted
Created January 24, 2015 20:51
[Android] SQLite on non rooted devices
$ adb -e pull /system/xbin/sqlite3 # get sqlite3 binary from emulator with the same CPU arch.
$ adb -d push sqlite3 /mnt/sdcard # push it
$ adb -d shell
$ run-as <PACKAGE_NAME> # run as your app, which should be debuggable.
$ cd databases; pwd
/data/data/<PACKAGE_NAME>/databases
$ cat /mnt/sdcard/sqlite3 > sqlite3 # copy it to internal storage directory
$ ls -l sqlite3
-rw-rw-rw- u0_a138 u0_a138 36860 2014-03-26 06:37 sqlite3
$ chmod 777 sqlite3 # change mode bits, to be executable
@alxsimo
alxsimo / ServiceContainer
Created January 30, 2015 13:46
[C#] ServiceContainer - Lighweight DI / IoC implementation
using System;
using System.Collections.Generic;
namespace SIMA.Core.Layers.Transversal.IoC
{
/** ServiceAnomalias serviceAnom = ServiceContainer.Resolve<IUniverseFileServiceAdapter>() **/
public static class ServiceContainer
{