Skip to content

Instantly share code, notes, and snippets.

Avatar

Sergi Tur Badenas acacha

View GitHub Profile
View _convert_date_to_sql_date
protected function _convert_date_to_sql_date($date)
{
$date = substr($date,0,10);
if(preg_match('/\d{4}-\d{2}-\d{2}/',$date))
{
//If it's already a sql-date don't convert it!
return $date;
}elseif(empty($date))
{
return '';
@acacha
acacha / mysql_backup.sh
Last active Mar 18, 2017
Mysql Backup
View mysql_backup.sh
#!/bin/sh
#CÒPIA DE SEGURETAT BASE DE DADES MEDIAWIKI
# First clean files older than 20 days: http://acacha.org/mediawiki/index.php/Tmpwatch
tmpreaper --verbose 20d /linux2/backups/mysql
inici=`date`
dia=`date "+%Y%m%d"`
mysql_backups_folder="/linux2/backups/mysql"
echo "##################################################################################"
echo "Executant còpia de base de dades (mysqldump) de mediawiki. Inici: $inici"
echo "##################################################################################"
@acacha
acacha / gist:b59aa63d8fed9347b929
Created Jan 19, 2015
isConnected Android. Check if device is connected
View gist:b59aa63d8fed9347b929
private static boolean isConnected(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = null;
if (connectivityManager != null) {
networkInfo =
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
}
return networkInfo == null ? false : networkInfo.isConnected();
}
@acacha
acacha / javamd5
Created Jan 19, 2015
Java MD5 function
View javamd5
public String computeMD5Hash(String password){
StringBuffer MD5Hash = new StringBuffer();
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(password.getBytes());
byte messageDigest[] = digest.digest();
@acacha
acacha / OKHTTPSSLSelfSigned
Created Jan 20, 2015
OKHTTPSSLSelfSigned
View OKHTTPSSLSelfSigned
private static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
@acacha
acacha / FirstTimeExecutionSharedPreferences
Created Jan 21, 2015
FirstTimeExecutionSharedPreferences
View FirstTimeExecutionSharedPreferences
final String PREFS_NAME = "MyPrefsFile";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments", "First time");
// first time task
@acacha
acacha / GetAndroidAccounts
Last active Aug 29, 2015
GetAndroidAccounts
View GetAndroidAccounts
/* Sergi Tur Badenas
* http://acacha.org/sergitur
* See http://acacha.org/mediawiki/index.php/Android_AccountManager
* for more info
*/
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
View DebugIntent
private void debugIntent(Intent intent, String tag) {
Log.v(tag, "action: " + intent.getAction());
Log.v(tag, "component: " + intent.getComponent());
Bundle extras = intent.getExtras();
if (extras != null) {
for (String key: extras.keySet()) {
Log.v(tag, "key [" + key + "]: " +
extras.get(key));
}
}
@acacha
acacha / gist:4ca4b66287bd54e64e01
Created Feb 28, 2015
Composer bash autocompletion
View gist:4ca4b66287bd54e64e01
_composer()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local cmd=${COMP_WORDS[0]}
if ($cmd > /dev/null 2>&1)
then
COMPREPLY=( $(compgen -W "$($cmd list --raw | cut -f 1 -d " " | tr "\n" " ")" -- $cur) )
fi
}
complete -F _composer composer
View gist:d908bcc6ffd089878a2a
public function getPermissionNameSuffix(Model $model) {
return strtolower((new ReflectionClass($model))->getShortName());
}