Posts

python - Pipe Twisted Request Content to STDIN of Process -

i'm looking pipe content of http post or put stdin of process. i'm using klein library , have following code: from klein import run, route twisted.internet import reactor, defer, protocol import os class curlprocprotocol(protocol.processprotocol): def __init__(self, data): self.data = data def connectionmade(self): self.transport.write(self.data) self.transport.closestdin() def outreceived(self, data): return 'got ' + str(data) @route('/') def home(request): d = defer.deferred() reactor.spawnprocess(curlprocprotocol(request.channel), '/usr/bin/curl', args=['curl', '-t', '-', 'ftp://localhost/test.txt'], env={'home': os.environ['home']}, usepty=false) d.addcallback(reactor.run) return d run("localhost", 8080) the problem ...

methods - Is Java "pass-by-reference" or "pass-by-value"? -

i thought java pass-by-reference ; i've seen couple of blog posts (for example, this blog ) claim it's not. don't think understand distinction they're making. what explanation? java pass-by-value . unfortunately, decided call location of object "reference". when pass value of object, passing reference it. confusing beginners. it goes this: public static void main( string[] args ) { dog adog = new dog("max"); // pass object foo foo(adog); // adog variable still pointing "max" dog when foo(...) returns adog.getname().equals("max"); // true, java passes value adog.getname().equals("fifi"); // false } public static void foo(dog d) { d.getname().equals("max"); // true // change d inside of foo() point new dog instance "fifi" d = new dog("fifi"); d.getname().equals("fifi"); // true } in example adog.getname() still retur...

oop - C++ Design: Overloading/Overriding many many functions, way to clean up? -

the case trying implement here base class has function (let's call modify_command) can accept many different types virtually derived classes can implement modify_command function see fit. right have along these lines in base class: class base { template<typename command> void modify_command(command cmd) { std::cout << "modify command called unimplemented command type:" << typeid(cmd).name(); } virtual void modify_command(specificcommanda cmd) { modify_command<specificcommanda>(cmd); // calls templated function } virtual void modify_command(specificcommandb cmd) { modify_command<specificcommandb>(cmd); // calls templated function } // etc. }; then in derived class: class derived : public base { virtual void modify_command(specificcommanda cmd) { cmd.x = 1; cmd.y = 2; } } obviously virtual template function isn't possibility i...

windows - Accessing Remote Registry for the currently logged in user with Powershell -

i'm trying find printer ports in use user logged in multiple machines. however, when run script running regedit myself... how go getting user logged in? here current script: get-content -path c:\listofcomputers.txt | foreach-object { get-itemproperty -path registry::"hkey_current_user\software\microsoft\windows nt\currentversion\printerports\" | foreach-object {get-itemproperty $_.pspath} | format-list | out-file c:\portresults.txt }

Copying all files of a directory to one text file in python -

my intention copy text of c# (and later aspx) files 1 final text file, doesn't work. for reason, "yo.txt" file not created. i know iteration on files works, can't write data .txt file. the variable 'data' contain text files . . . *******could connected fact there non-ascii characters in text of c# files? here code: import os import sys src_path = sys.argv[1] os.chdir(src_path) data = "" file in os.listdir('.'): if os.path.isfile(file): if file.split('.')[-1]=="cs" , (len(file.split('.'))==2 or len(file.split('.'))==3): print "copying", file open(file, "r") f: data += f.read() print data open("yo.txt", "w") f: f.write(data) if has idea, great :) thanks you have ensure directory file created has sufficient write permissions, if not run chmod -r 777 . to make directory writab...

javascript - how to make ReactCSSTransitionGroup animate elements on setState? -

how make elements animate on changing state setinterval ? trying render elements in random position , try animate position changes following: var elem = react.createclass({ render: function () { return ( <h1 classname="elem"> hello, {this.props.name} ! </h1> ); } }); var maincontainer = react.createclass({ componentdidmount: function () { setinterval(this.shf, 777); }, getinitialstate: function () { return {source: []}; }, shf: function () { var source = this.props.source.sort(function () { return .5 - math.random(); }); this.setstate({ source: source }); }, render: function () { var reactcsstransitiongroup = react.addons.csstransitiongroup; var elems = this.state.source....

python - Django - Rendering Markdown Sanitizied with Bleach -

when markdown(text), without bleach, desired result (raw): <p>blah</p> and displays correctly as: blah where "p" tags rendered correctly paragraph block. when bleach.clean(markdown.markdown(text)), (raw): &lt;p&gt;blah&lt;/p&gt; and displays incorrectly as: <p>blah</p> where "p" tags part of text , not html paragraph block. you need mark bleach ed html safe from django.utils.safestring import mark_safe ... return mark_safe(bleach.clean(markdown.markdown(text))) but, there django-bleach provides integration django , ready-made tags use bleach in django. {% load markdown_deux_tags bleach_tags %} {{ view_user.profile.about|markdown:"user"|bleach }} in settings.py can tell django-bleach tags okay bleach_allowed_tags = ['h1', 'h2', 'p', 'b', 'i', 'strong', 'a'] bleach_allowed_attributes = ['href', 'title...