Skip to content

Instantly share code, notes, and snippets.

View acacha's full-sized avatar

Sergi Tur Badenas acacha

View GitHub Profile
@acacha
acacha / javamd5
Created January 19, 2015 15:30
Java MD5 function
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 January 20, 2015 10:37
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 January 21, 2015 08:57
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 August 29, 2015 14:13
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;
@acacha
acacha / DebugIntent
Created January 26, 2015 17:27
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 February 28, 2015 09:23
Composer bash autocompletion
_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
public function getPermissionNameSuffix(Model $model) {
return strtolower((new ReflectionClass($model))->getShortName());
}
@acacha
acacha / gist:432921448a745d531188
Created December 31, 2015 11:59
Intelligent Lamp with makeblock inventor electronic kit. 2 versions uncommenting some lines
/************************************************************************
* 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.
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
@acacha
acacha / gist:82c2265635a207bea544
Created February 17, 2016 17:19
StandardFirmata
/*
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