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 / ubuntu_android_studio
Created September 1, 2015 21:21
[Ubuntu] Setup Android Studio on Ubuntu
# enable 32bit architecture
sudo dpkg --add-architecture i386
sudo apt-get update
# install some required packages
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
@alxsimo
alxsimo / clone_to_existing
Created June 22, 2015 18:28
[Git] Clone repository to non-empty folder
/* clones repository to existing folder */
git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master
NOTE: -t will set the upstream branch for you, if that is what you want, and it usually is.
@alxsimo
alxsimo / session_handling
Created June 22, 2015 06:53
[Ajax/jQuery] Handle sessions in client side with ajax requests
/*
Handles session expired in AJAX requests
*/
$(document).ajaxError(function(e, jqXHR, ajaxSettings, thrownError) {
// if 403 - check if user still has active session - if not redirect to login page
if(jqXHR.status == '403' || jqXHR.status == '500'){
$.get('/users/check_session',function(data){
// inactive session so redirect to login page
@alxsimo
alxsimo / FormatString
Created June 3, 2015 08:20
[C#] Extension methods
public static string FormatString(this string format, params object[] args)
{
return string.Format(format, args);
}
// usage
string message = "Welcome {0} (Last login: {1})".FormatString(userName, lastLogin);
@alxsimo
alxsimo / json_serialize_circular
Created May 18, 2015 10:55
[C#] Serialize JSON with circular references
var serializerSettings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
};
string json = JsonConvert.SerializeObject(afectados, Formatting.Indented, serializerSettings);
return Content(JsonConvert.SerializeObject(afectados, Formatting.Indented, serializerSettings));
@alxsimo
alxsimo / search_all_sqlite
Created February 9, 2015 11:59
[Python] Search in all SQLite database
import sqlite3
import os
filename = ...
with sqlite3.connect(filename) as conn:
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
for tablerow in cursor.fetchall():
table = tablerow[0]
@alxsimo
alxsimo / mysq_root_reset
Created February 7, 2015 18:41
[MySQL] Reset MySQL root password
For Ubuntu Server
1. Set root password
sudo su
passwd
2. sudo /etc/init.d/mysql stop
3. sudo /etc/init.d/mysql start --skip-grant-tables
4. mysql
5. UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
6. mysql -u root -p
@alxsimo
alxsimo / chrome_settings
Created February 2, 2015 22:35
[Chrome] Chrome settings and tricks
Change default language
chrome://chrome/settings/languages
@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
{
@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