This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from django.http import HttpResponse | |
import json | |
""" | |
Either use it as a decorator or as a function | |
But When using as a decorator, Make sure you return dictionary object. | |
Both HttpResponse and JsonResponse will cause an Error. | |
""" | |
class AsciiFalseJsonResponse: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import JsonResponse | |
import json | |
def get_json_data(data): | |
try: | |
return json.loads(data.body.decode('utf-8')) | |
except TypeError: | |
return JsonResponse({'response': 'Type Incorrect'}) | |
except Exception as e: | |
return JsonResponse({'response': 'Unexpected Error as follow : '+str(e)}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frame.setUndecorated(true); | |
frame.getContentPane().setBackground(new Color(1.0f,1.0f,1.0f,0.0f)); | |
frame.setBackground(new Color(1.0f,1.0f,1.0f,0.0f)); | |
//additionally panel needs to be set opaque (panel.setOpaque(false)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int rank(int key, int[] a){ | |
// Array must be sorted. | |
int lo = 0; | |
int hi = a.length - 1; | |
while (lo <= hi){ | |
// Key is in a[lo..hi] or not present. | |
int mid = lo + (hi - lo) / 2; | |
if (key < a[mid]) hi = mid - 1; | |
else if (key > a[mid]) lo = mid + 1; | |
else return mid; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int gcd(int p, int q) | |
{ | |
if (q == 0) return p; | |
int r = p % q; | |
return gcd(q, r); | |
} |
NewerOlder