Skip to content

Instantly share code, notes, and snippets.

import csv
csv_connection = open("predict.csv", "wb")
f = csv.writer(csv_connection)
f.writerow(["pk", "dt", "name", "temp", "humidity", "smv", "trigger"])
f.writerow(["pk111", "dt1111", "name1111", "temp1111", "humidity1111", "smv1111", "trigger1111"])
f.writerow(["pk111", "dt1111", "name3331", "temp3331", "humidity3331", "smv3331", "trigger3331"])
csv_connection.close()
@codephillip
codephillip / GCS Crud
Last active February 5, 2018 07:11
Google Cloud Storage using python(django)
# in settings.py
DEFAULT_FILE_STORAGE = 'appengine_toolkit.storage.GoogleCloudStorage'
APPENGINE_TOOLKIT = {
'BUCKET_NAME': 'XXXXXX',
}
###################
# save 1
uploaded_file = request.FILES.get('file_' + str(i))
# settings.py
def get_app_credentials():
import io
import json
from google.oauth2 import service_account
json_credentials_path = 'xxxxxx.json'
with io.open(json_credentials_path, 'r', encoding='utf-8') as json_fi:
credentials_info = json.load(json_fi)
credentials = service_account.Credentials.from_service_account_info(credentials_info)
@codephillip
codephillip / ConsumeJson
Created February 6, 2018 09:35
Consume Json in android
private String connectToServer(String urlConnection) throws Exception{
Request request = new Request.Builder().url(urlConnection).build();
OkHttpClient client = new OkHttpClient();
Response response = client.newCall(request).execute();
String jsonData = response.body().string();
Log.d("JSON STRING_DATA", jsonData);
return jsonData;
}
@codephillip
codephillip / Google cloud storage demo
Last active April 12, 2018 09:04
Google cloud storage. Write image. Make image public. Get image url
from django.core.files.storage import default_storage
print default_storage.__class__
from django.core.files.base import ContentFile
import io
import random
def generate_photo_file():
from PIL import Image
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
"""
@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']
@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_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 / 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[@]}"