Skip to content

Instantly share code, notes, and snippets.

View soukiassianb's full-sized avatar

Benjamin Soukiassian soukiassianb

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React Tutorial</title>
<!-- Not present in the tutorial. Just for basic styling. -->
<link rel="stylesheet" href="css/base.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.16/browser.js"></script>
<!doctype html>
<!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ -->
<html>
<head>
<title>iOS 8 web app</title>
<!-- CONFIGURATION -->

models.py

class Edito(models.Model):
	title = models.CharField(max_length=50)
	cover_picture = models.ImageField(upload_to=edito_picture_upload_path, blank=True, null=True)
	picture = CloudinaryField('image', blank=True, null=True)

script

@soukiassianb
soukiassianb / translate_tags.py
Last active August 29, 2015 14:20
translate tags w/ goslate
import goslate
gs = goslate.Goslate()
for tag in tags:
if tag.english_name == 'not-translated':
try:
tag.english_name = gs.translate(tag.name, 'en')
print 'translating %s in english: %s' % (tag.name, tag.english_name)
tag.save()
except:
print "something happened :("
@soukiassianb
soukiassianb / queryset_compare.py
Last active February 19, 2023 10:00
Use python set to compare django querysets
"""
First technique, use set
"""
# two querysets or lists
q1
>>> [<obj1>,<obj2>, <obj3>]
q2
>>> [<obj4>,<obj2>, <obj5>]
# compare querysets :
@soukiassianb
soukiassianb / python-server.py
Last active August 29, 2015 14:18
Make your own python server
# get to the directory you want to share
cd <mydirectory>
# step 1: Get your ip adress
python
import socket
print socket.gethostbyname(socket.gethostname())
quit() # back to shell
@soukiassianb
soukiassianb / filter_products_by_tag.py
Last active August 29, 2015 14:13
Filter product by tag [TaggedProduct classmethod]
class TaggedProducts(GenericTaggedItemBase):
[...]
# filter products by tags
@classmethod
def filter(cls, *tags):
products = Products.objects.all()
for tag in tags:
if tag not in (t.slug for t in ProductTags.objects.all()): # not good for speed
@soukiassianb
soukiassianb / models.py
Last active August 29, 2015 14:13
Check if image field has the URL attribute associated with
class Products(models.Model):
# [....]
picture = models.ImageField(upload_to='products', blank=True, null=True)
picture_2 = models.ImageField(upload_to='products', blank=True, null=True)
picture_3 = models.ImageField(upload_to='products', blank=True, null=True)
# [....]