Skip to content

Instantly share code, notes, and snippets.

@n1ru4l
n1ru4l / index.js
Created August 7, 2017 10:47
Fetch blob and convert to base64
export const fetchAsBlob = url => fetch(url)
.then(response => response.blob());
export const convertBlobToBase64 = blob => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
@xmlking
xmlking / app.js
Last active March 7, 2023 14:52
angular authentication with angular modules: http-auth-interceptor, angular-growl , angular-ui : UI-Router & UI-Bootstrap , restangular
angular.module('ConsoleUIApp', ['ui.router','ui.bootstrap','ngAnimate','angular-growl', 'restangular','http-auth-interceptor'])
.config(function ($stateProvider, $urlRouterProvider, growlProvider, RestangularProvider, $httpProvider) {
// For any unmatched url, redirect to /state1
$urlRouterProvider.otherwise("/home");
$stateProvider
.state('home', {
url: "/home",
templateUrl: "views/home.html",
@robhudson
robhudson / gist:3848832
Last active July 12, 2018 15:25
Quick way to set CORS headers on django-tastypie resources
class CORSResource(object):
"""
Adds CORS headers to resources that subclass this.
"""
def create_response(self, *args, **kwargs):
response = super(CORSResource, self).create_response(*args, **kwargs)
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Headers'] = 'Content-Type'
return response