Skip to content

Instantly share code, notes, and snippets.

View darkwing's full-sized avatar

David Walsh darkwing

View GitHub Profile
parent_id = request.POST.get('parent_id', '')
# Attempt to set a parent
if show_translation_parent_block and parent_id:
try:
parent_doc = get_object_or_404(Document, id=parent_id)
doc.parent = parent_doc
except Document.DoesNotExist:
logging.debug('Could not find posted parent')
// Document
{{ GetAttachmentContent() }}
// Intermediate template
<%- mdn.getFileContent(env.files[0]) %>
// Complete template:mdn:common
<% module.exports = {
@darkwing
darkwing / gist:3744439
Created September 18, 2012 17:23
Mozilla Developer Network Search Bookmarklet
(function()%7Bvar%20d=document,w=window,ds=d.getSelection,ws=w.getSelection,ss=d.selection,e=encodeURIComponent;t=(ws)%3Fws():(ds)%3Fds():(ss)%3Fss.createRange().text:'';t=(t.toString().length)%3Ft:prompt('What term would you like to research?','');if(t)%7Ba='https://developer.mozilla.org/en-US/search?q=';u=a+e(t);f=function()%7Bx=w.open(u,'nfx','scrollbars=1,toolbar=0,resizable=1,status=1,width=600,height=600');if(!x)w.location.href=u;%7D;if(/Firefox/.test(navigator.userAgent))setTimeout(f,0);else%20f();%7D%7D)();
@darkwing
darkwing / gist:4083092
Created November 16, 2012 01:28
Stylesheet from Microsoft.com
<link rel="stylesheet" type="text/css" href="http://i.s-microsoft.com/en-us/home/style.cssx?k=~/shared/templates/Styles/reset-css.aspx;~/shared/templates/Styles/cols-css.aspx;~/shared/templates/Styles/webfont-css.aspx;~/shared/templates/Styles/type-css.aspx;~/shared/templates/Styles/layout-css.aspx;~/shared/templates/Styles/header-css.aspx;~/shared/templates/Styles/_search-css.aspx;~/shared/templates/Styles/_listoflinks-css.aspx;~/shared/templates/Styles/_menu-css.aspx;~/shared/templates/Styles/hero-css.aspx;~/shared/templates/Styles/_pivot-css.aspx;~/shared/templates/Styles/_features-css.aspx;~/shared/templates/Styles/_news-css.aspx;~/shared/templates/Styles/prefooter-css.aspx;~/shared/templates/Styles/footer-css.aspx;~/shared/templates/Styles/animations-css.aspx;~/shared/templates/Styles/feedback-css.aspx&amp;sc=/en-us/home/site.config&amp;pc=/en-us/home/PageConfig/Optimize.config.xml&amp;v=1762138064"></link>
<% var wiki = module.exports = buildAPI({
/*
* Given a MediaWiki path attempt to update it to a Kuma path
* This is not a DekiScript function
*/
kumaPath: function(in_path) {
// Strip the base path, allows this to replace Template:getRelativeURL
path_strip = in_path.replace(RegExp('^https:\/\/developer\.mozilla\.org','i'),'');
// Get/fix/update/add language
var pathLang = (path_strip.match(/^\/?(\w{2}(?:[-|_]\w{2})?)?(?=\/)/)[1] || env.locale).replace(/^en$/i,'en-US').replace(/^(?:zh_)?cn$/i,'zh-CN').replace(/zh_tw/i,'zh-TW').replace(/^pt$/i,'pt-PT');
@darkwing
darkwing / gist:4575399
Created January 19, 2013 21:43
Test gist!
(function($) {
var $el = $('someNode');
})(jQuery;
// Line 525
dialog.setValueOf('info', 'txtUrl', "{{ ImageAttachment('" + value + "'}}");
var xhr = new XMLHttpRequest({
mozSystem: true
});
// To enable xhr.abort if user cancels
outReq.xhr = xhr;
outReq.oncancel = function() {
this.xhr.abort();
}
function boolSet(attr) {
return function(state) {
!!state ? this.setAttribute(attr, null) : this.removeAttribute(attr);
}
}
function boolGet(attr) {
return function() {
return typeof this.getAttribute(attr) != 'undefined';
}
dwalsh-08215:kuma dwalsh$ vagrant provision
[default] Running provisioner: Vagrant::Provisioners::Puppet...
[default] Running Puppet with /tmp/vagrant-puppet/manifests/dev-vagrant.pp...
stdin: is not a tty
notice: /Stage[hacks]/Dev_hacks/Exec[locale-gen]/returns: executed successfully
notice: /Stage[hacks]/Dev_hacks/Exec[update-locale]/returns: executed successfully
notice: /Stage[pre]/Update_repos/Exec[apt-update]/returns: executed successfully
notice: /Stage[langs]/Python_modules/Exec[pip-install-dev]/returns: executed successfully
notice: /Stage[langs]/Python_modules/Exec[pip-install-compiled]/returns: executed successfully
notice: /Stage[main]/Kuma_config/Exec[kuma_sql_migrate]/returns: executed successfully