Skip to content

Instantly share code, notes, and snippets.

Avatar

Sergi Tur Badenas acacha

View GitHub Profile
@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());
}
@acacha
acacha / gist:432921448a745d531188
Created Dec 31, 2015
Intelligent Lamp with makeblock inventor electronic kit. 2 versions uncommenting some lines
View gist:432921448a745d531188
/************************************************************************
* File Name : Smart_table_lamp.ino
* Author : crazyfeng
* Version : V1.0
* Date : 18/07/2014
*Parts required : Smart_table_lamp
* Description :The lamp can light up when someone make sound or go through.
* The Brightness of the lamp is adjustable.
* License : CC-BY-SA 3.0
* Copyright (C) 2013 Maker Works Technology Co., Ltd. All right reserved.
View Download all github repos executing this script on terminal (bash)
USER=acacha;PAGE=1; curl "https://api.github.com/users/$USER/repos?page=$PAGE&per_page=100" | grep -e 'git_url*' | cut -d \" -f 4 | xargs -L1 git clone
View gist:82c2265635a207bea544
/*
Firmata is a generic protocol for communicating with microcontrollers
from software on a host computer. It is intended to work with
any host computer software package.
To download a host software package, please clink on the following link
to open the list of Firmata client libraries your default browser.
https://github.com/firmata/arduino#firmata-client-libraries