This file contains 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
import requests | |
from urlparse import urlparse, urljoin | |
from lxml import html, etree | |
from lxml.cssselect import CSSSelector | |
def get_content(url): | |
return requests.get(url) | |
def get_selector(css_selector): | |
return CSSSelector(css_selector) |
This file contains 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 import forms | |
from django.contrib import admin | |
from django.contrib.sites.models import Site | |
from django.contrib.sites.admin import SiteAdmin | |
from django.utils.translation import ugettext_lazy as _ | |
from colorful.fields import RGBColorField # third-party app | |
from .models import SiteOption |
This file contains 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
request = new XMLHttpRequest() | |
request.onreadystatechange = -> | |
if request.readyState is 4 | |
mimetype = request.getResponseHeader('content-type') | |
if mimetype.split('/').shift() is 'image' | |
alert 'Image!' | |
else | |
alert 'Not Image!' | |
request.open 'HEAD', 'http://upload.wikimedia.org/wikipedia/commons/5/5b/Ultraviolet_image_of_the_Cygnus_Loop_Nebula_crop.jpg', true |
This file contains 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 python:2.7 | |
ENV PYTHONUNBUFFERED 1 | |
RUN apt-get update && apt-get -y install libxml2-dev libxslt1-dev libxslt-dev python-lxml | |
RUN pip install lxml |
This file contains 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
# app_1.models.py | |
from django.db import models | |
class Model2(models.Model): | |
field = models.ForeignKey('app_1.Model3') |
This file contains 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
import requests | |
import lxml.html | |
from lxml.cssselect import CSSSelector | |
def get_filtered_nodes(content, selector): | |
dom_tree = lxml.html.fromstring(content) | |
selector = CSSSelector(selector) | |
return selector(dom_tree) |
This file contains 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
function makeid() | |
{ | |
var text = ""; | |
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for( var i=0; i < 5; i++ ) | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
return text; | |
} |
This file contains 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
/* | |
SPF | |
(c) 2012-2014 Google, Inc. | |
License: MIT | |
*/ | |
(function(){function l(a,b,c){var d=Array.prototype.slice.call(arguments,2);return function(){var c=d.slice();c.push.apply(c,arguments);return a.apply(b,c)}}function aa(a,b){if(a){var c=Array.prototype.slice.call(arguments,1);try{return a.apply(null,c)}catch(d){return d}}}function m(a,b){if(document.createEvent){var c=document.createEvent("CustomEvent");c.initCustomEvent("spf"+a,!0,!0,b);return document.dispatchEvent(c)}return!0}function n(){return(new Date).getTime()};function p(a,b){return q[a]=b}var q=window._spf_state||{};window._spf_state=q;var ba={"animation-class":"spf-animate","animation-duration":425,"cache-lifetime":6E5,"cache-max":50,"cache-unified":!1,"link-class":"spf-link","nolink-class":"spf-nolink","navigate-limit":20,"navigate-lifetime":864E5,"prefetch-on-mousedown":!1,"process-async":!1,"request-timeout":0,"url-identifier":"?spf=__type__"};function r(a){return ca()[a]}function ca(a){return!a&&"config"in q?q.config:p("config",a||{})};function |
This file contains 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
# You can easly internionalize your extension's HTMLs with this. | |
$('[data-i18n]').each -> | |
me = $(@) | |
key = me.data 'i18n' | |
switch me.attr 'data-i18n-method' | |
when 'placeholder' | |
me.attr 'placeholder', chrome.i18n.getMessage key |
This file contains 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
String::htmlspecialchars = (quote_style = 2, double_encode) -> | |
optTemp = 0 | |
i = 0 | |
noquotes = false | |
string = @.toString() | |
string = string.replace(/&/g, '&') if double_encode isnt false | |
string = string.replace(/</g, '<').replace(/>/g, '>') |