Skip to content

Instantly share code, notes, and snippets.

@epigos
epigos / form.py
Created August 26, 2013 17:21 — forked from faruken/form.py
"""
HTML forms
(part of web.py)
"""
import copy, re
import webapi as web
import utils, net
def attrget(obj, attr, value=None):
@epigos
epigos / fields.py
Created July 22, 2014 23:14 — forked from yprez/fields.py
import base64
from django.core.files.base import ContentFile
from rest_framework import serializers
class Base64ImageField(serializers.ImageField):
def from_native(self, data):
if isinstance(data, basestring) and data.startswith('data:image'):
# base64 encoded image - decode
@epigos
epigos / scrapy_mongodb_pipeline
Last active January 16, 2020 14:19
Mongodb pipeline for scrapy
from twisted.internet.threads import deferToThread
#from scrapy.utils.serialize import ScrapyJSONEncoder
from pymongo import MongoClient
from pymongo.errors import DuplicateKeyError
from scrapy.exceptions import DropItem
class MongoPipeline(object):
"""Pushes scraped data in to mongodb"""
@epigos
epigos / forms.py
Created February 24, 2017 10:26 — forked from gonvaled/forms.py
Django widget to replace the file selection standard button by an image preview. Tested with Django 1.8.5
from django.forms import ModelForm, FileField
from .models import Campaign
from .widgets import ImagePreviewWidget
class DesignCampaignForm(ModelForm):
brand_logo = FileField(widget=ImagePreviewWidget)
@epigos
epigos / gae_shell.py
Created July 31, 2017 13:43 — forked from djm/gae_shell.py
Google App Engine Development Shell
#!/usr/bin/env python -i
"""
A local interactive IPython shell for Google App Engine on Mac OSX.
Usage:
cd /to/project/folder/with/app.yaml
python gae_shell.py
Notes:
@epigos
epigos / nes.py
Created July 10, 2020 11:57 — forked from karpathy/nes.py
Natural Evolution Strategies (NES) toy example that optimizes a quadratic function
"""
A bare bones examples of optimizing a black-box function (f) using
Natural Evolution Strategies (NES), where the parameter distribution is a
gaussian of fixed standard deviation.
"""
import numpy as np
np.random.seed(0)
# the function we want to optimize
@epigos
epigos / weight_init.py
Created July 12, 2020 17:06 — forked from jeasinema/weight_init.py
A simple script for parameter initialization for PyTorch
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import torch
import torch.nn as nn
import torch.nn.init as init
def weight_init(m):
'''