Skip to content

Instantly share code, notes, and snippets.

@codephillip
codephillip / ParseXML.java
Created January 28, 2020 08:23
Extracts data from xml file on android local storage and extracts the data
private void parseXML(String targetFilePath) {
try {
FileInputStream is = new FileInputStream(targetFilePath);
XmlToJson xmlToJson = new XmlToJson.Builder(is, null).build();
JSONObject jsonObject = xmlToJson.toJson();
Timber.d("Content " + jsonObject.toString());
// get the root key.
// This prevents us from manually checking key. This is a special case
Iterator keys = jsonObject.keys();
@codephillip
codephillip / JavaFileContentExtractor.java
Created January 28, 2020 08:19
Gets access to Android(java) internal storage using the provided url
private String getFileContent(String targetFilePath) {
try {
FileInputStream fis = new FileInputStream(targetFilePath);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
StringBuilder sb = new StringBuilder();
while ((strLine = br.readLine()) != null)
sb.append(strLine);
Timber.d("form data");
@codephillip
codephillip / MainMenuActivity.java
Last active September 4, 2019 09:54
Moving the form download logic from FormDownloadList to MainMenuActivity. Based on ODK(https://github.com/opendatakit/collect)
/*
* Copyright (C) 2009 University of Washington
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
@codephillip
codephillip / pytest_sample.py
Created October 18, 2018 17:47
Pytest example
import json
from run import app
import pytest
@pytest.fixture()
def client():
test_client = app.test_client()
return test_client
@codephillip
codephillip / ds_python.py
Created October 11, 2018 15:47
Datastructures in python
print('list, string, tuple, dict, sets')
print('########### LISTS #############')
tasks = [474,837,8675,636,86,976,23,4]
print(tasks)
tasks.append(100)
print(tasks)
print(len(tasks))
@codephillip
codephillip / delete-older-gcloud-app-versions.sh
Created August 28, 2018 07:37
Deletes old app engine versions
#!/bin/bash
## Modification of https://almcc.me/blog/2017/05/04/removing-older-versions-on-google-app-engine/
## to allow deletion of of old app versions, leaving only version per service
## define all your services
declare -a arr=("default" "sellio-clients" "ad-manager" "sellio-test" "unified-bot" "momo" "healthcheck")
echo 'started'
## now loop through the above array
for i in "${arr[@]}"
@codephillip
codephillip / python_sql.py
Created August 15, 2018 09:28
Sql commands in python
import mysql.connector
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="XXXXXX"
)
@codephillip
codephillip / Curl graphql client
Created June 25, 2018 06:22
Making graphql request using curl
curl \
-X POST \
-H "Content-Type: application/json" \
--data '{"query": "{links {url}}"}' \
http:///35.227.57.118/graphql/
@codephillip
codephillip / Python graphql client
Last active September 3, 2018 17:23
Making request to graphql server
import requests
r = requests.post(url='http://35.227.57.118/graphql/', json={"query": "{links {url}}"})
print(r.status_code)
print(r.content)
if r.status_code == 200 or r.status_code == 201:
r_json = r.json()
data = r_json['data']
links = data['links']
import requests
import DotMap
from httplib import OK
import logging
def get_accounts_no_meta_data():
"""
https://app.beyonic.com/api/collectionrequests -H "Authorization: Token XXXX"
beyonic collection requests that dont have meta field
"""