Skip to content

Instantly share code, notes, and snippets.

View josejuansanchez's full-sized avatar

José Juan Sánchez josejuansanchez

View GitHub Profile
@josejuansanchez
josejuansanchez / checkWeatherAPI
Created December 9, 2014 13:23
Code Snippet de cómo realizar una petición HTTP con HttpURLConnection
private String checkWeatherAPI(String ApiUrl, String q) {
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
// Almacenará la respuesta JSON como una cadena
String weatherJsonStr = null;
try {
// Codificamos el nombre de la ciudad en UTF8
q = URLEncoder.encode(q, "UTF-8");
@josejuansanchez
josejuansanchez / WeatherDataParser
Created December 9, 2014 14:20
Code Snippet de cómo parsear una respuesta JSON para buscar los atributos que nos interesan
public class WeatherDataParser {
public String getWeatherCityName(String weatherJsonStr) throws JSONException {
JSONObject weatherJson = new JSONObject(weatherJsonStr);
return weatherJson.getString("name");
}
public int getWeatherResponseCode(String weatherJsonStr) throws JSONException {
JSONObject weatherJson = new JSONObject(weatherJsonStr);
return weatherJson.getInt("cod");
@josejuansanchez
josejuansanchez / isAvailable
Created December 10, 2014 23:41
Comprueba si hay algún Activity que sea capaz de manejar un determinado Intent
public static boolean isAvailable(Context ctx, Intent intent) {
final PackageManager mgr = ctx.getPackageManager();
List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
public void openGoogleMaps(View v) {
Uri geoLocation = Uri.parse("geo:36.782085,-2.815337?q=36.782085,-2.815337");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(geoLocation);
@josejuansanchez
josejuansanchez / gist:33e8a81267c1a252c7fc
Last active August 29, 2015 14:16
How to remove several files from a Git repository that have been deleted from disk
git rm $(git status | grep deleted | awk '{print $2}')
@josejuansanchez
josejuansanchez / bazaar-to-git.md
Last active April 6, 2021 13:41
How to import the p2psp bazaar repository in GitHub

1. Install bzr and bzr-fastimport

sudo apt-get install bzr
sudo apt-get install bzr-fastimport

2. Get the trunk branch from launchpad

bzr branch lp:p2psp 
@josejuansanchez
josejuansanchez / gist:9f11e8c1f86141459a25
Created March 20, 2015 01:01
How to handle big repositories with git
<manifest ...>
...
<!-- Make sure your app (or individual activity) uses the
theme with the custom attribute defined. -->
<application android:theme="@style/AppTheme" ...>
...
</application>
</manifest>
@josejuansanchez
josejuansanchez / how-to-use.md
Last active August 29, 2015 14:18
Bash script and Gnuplot file to create a curve with the codestream size for each frame of a sequence of frames.

Step 1

./getbytesperframe.sh 0 100 > sun.dat

Step 2

gnuplot < sun.gpt > sun.svg 
/* JPEG 2000 - defined in IEC 15444-1 "JPEG 2000 Core (part 1)" */
  /* delimiters */
SOC   = 0x4f,	/* start of codestream */
SOT   = 0x90,	/* start of tile */
SOD   = 0x93,	/* start of data */
EOC   = 0xd9,	/* end of codestream */
  /* fixed information segment */
SIZ   = 0x51,	/* image and tile size */
  /* functional segments */

COD = 0x52, /* coding style default */

|Time | 172.20.55.72 |
| | | 46.101.34.192 |
|7.801943000| GET /jpip?cid=JPHT85 |HTTP: GET /jpip?cid=JPHT85B91EE67E99FA1A&cclose=JPHT85B91EE67E99FA1A&stream=0 HTTP/1.1
| |(53185) ------------------> (8080) |
|7.801945000| GET /jpip?cid=JPHT01 |HTTP: GET /jpip?cid=JPHT011897797E99FA1A&cclose=JPHT011897797E99FA1A&stream=0 HTTP/1.1
| |(53185) ------------------> (8080) |
|7.924470000| HTTP/1.1 200 OK |HTTP: HTTP/1.1 200 OK
| |(53185) <------------------ (8080) |
|7.972195000| HTTP/1.1 200 OK |HTTP: HTTP/1.1 200 OK
| |(53185) <------------------ (8080) |