Posts

Showing posts from May, 2011

django - HTTPS PUT Request using djangorestframework -

i trying send https put request restful api django web service using djangorestframework (drf: http://django-rest-framework.org/ ) view. cannot work due django's cross site request forgery (csrf) protection. the put request intended allow unauthenticated users add resource. what have considered/tried: disabling csrf -- not acceptable. api runs on same django instance non-api service. disabling csrf protection risk. using x-requested-with: xmlhttprequest header on put request (i control clients). doesn't work -- still csrf error. using @crsf_exempt decorator on put view. if -- framework defines class, not view. my current best option write put views myself without using drf's view class. can use @crsf_exempt decorator successfully. i'd use drf's view class -- cannot see how. can you? thanks james cran wellward, able solve issue using method_decorator. class exampleview(responsemixin,view): renderers=default_renderers def get(self,request): response=...

algorithm - How to calculate "expected" number of inversions in a semi-random array of integers? -

consider array of integers. pair (i,j) called inversion in if < j , a[i] > a[j]. for every position 'i' in array there 2 possible candidates: a[i] probability p[i] , a[i]+x probability 1-p[i]. now have calculate expected number of inversions. given a[i] , p[i] every index , integer x. i know o(n^2) approach (check every legal possible pair). also, know o(nlogn) approach calculate number of inversions in array in elements predetermined 100% probability. done modifying merge sort. i want know approach better n squared. please let me know. this can done simple modification standard merge-sort based algorithm counting inversions, assign weight each value , compute sum of w[i]*w[j] i<j , a[i]>a[j] (when each weight 1, normal count). instead of adding count number of elements remaining in left array, add sum of weights these elements multiplied weight of element in right array processing. to use algorithm solve posed problem, create array of twice size, each e...

security - Pass Codeigniter CSRF string to server via AJAX -

i have enabled codeigniter's csrf protection on site uses ajax submit user form , handles other user interaction require data submission via ajax. result came against "action not allowed" server side error. worked out data javascript collected , submitted via ajax passed server , result csrf code not being sent. the generated token tag looks like: <input type="hidden" name="csrf_test_name" value="dsflkabsdf888ads888xxxxxx" /> so seems me simplest way submit token server verification using jquery selector on csrf_test_name value , adding post data server verify. per code below: //get csrf token var csrf = $('[name="csrf_test_name"]').val(); //build form data array var form_data = { csrf_test_name: csrf, ... ... ... ... ... ... } //send form data server can stored $.ajax({ type: "post", data: form_data, url: ..., datatype: "html", success: function(msg){ ... ... ... }//end success });//end ajax ...

ruby on rails - How do I create a link (or button) that will execute an Application Helper method? -

i new ruby/rails , trying create links update variable in session. have following method defined in application_helper.rb-- i put here in hopes correct place have can used all views: module applicationhelper def add_workspace_to_session(workspace_id) session[:workspace_id] = workspace_id end end in view want create simple link (or button) call helper, passing in workspace id updates session[:workspace_id] . how make link in view? using link_to? i'm missing something...having routes? thanks! if creating button or link should pointed url path not helper method. quick fix add path helper method. note: have not tested passing parameter. def add_workspace_to_session(workspace_id, url) session[:workspace_id] = workspace_id url end <%= button_to "store workspace", add_workspace_to_session(workspace_id, root_path), :method => :get %>

java - Issues with djecjni.dll -

while registering djecjni.dll command prompt, getting following error: loadlibrary("c:\software\pervasive\cosmos9\common\djecjni.dll") failed . i used following command register dll command prompt: regsvr32 "c:\software\pervasive\cosmos9\common\djecjni.dll" am trying run djecjni.dll file java getting error : operating system cannot run c:\software\pervasive\cosmos9\common\djecjni.dll java.lang.unsatisfiedlinkerror: djecjni.dll (the operating system cannot run c:\software\pervasive\cosmos9\common\djecjni.dll. ) @ java.lang.classloader.loadlibrarywithpath(classloader.java:993) @ java.lang.classloader.loadlibrarywithclassloader(classloader.java:962) @ java.lang.system.loadlibrary(system.java:465) @ datajunction.ec.nengine.<clinit>(unknown source) @ java.lang.j9vminternals.initializeimpl(native method) @ java.lang.j9vminternals.initialize(j9vminternals.java:200) @ datajunction.ec.engine.<init>(unknown source) i've added dll in path still dll canno...

java - Spring-ws VS Apache cxf VS Apache Axis2 VS Metro -

i need create soap web service. have wsdl , interface , implementation (as pojo). i choosing between subj. need frame work will: work servlet in servlet container require 1 servlet mapping in web.xml have spring integration (because service implementation spring bean) no require me add annotations. not have annotations on interface or implementation. spring-ws: looks cool, far understood forces me deal xml directly not want do. want framework deserialize message , pass parameter pojo. apache cxf powerful , has spring integration, if use jax-ws frontend have use annotations, , not want touch pojo. simple front-end? metro jax-ws ri, depends on annotations heavily. axis2 seems choice. choose? just wanna tell trying do: our app connects remote service using soap. gave wsdl, we've generated proxy classes , dto , stuff packed in jar , stored in vcs. need write emulation web service. , not want generate new dto. i think spring ws fit given requirements. not need deal dir...

iphone - 'MyAnnotation' may not respond to 'initWithDictionary:' -

i keep getting semantic issue code ('myannotation' may not respond 'initwithdictionary:'), im adding annotations map using plist. even though displays pin , want to, semantic issue , cant seem solve problem if great thanks heres code, problem in //brewmapviewcontroller.m error on line myannotation *annotation = [[myannotation alloc] initwithdictionary:brewerydict]; /*myannotation.h*/ #import <foundation/foundation.h> #import <mapkit/mapkit.h> @interface myannotation : nsobject <mkannotation> { cllocationcoordinate2d coordinate; nsstring *title; nsstring *subtitle; nsstring *test; } @property (nonatomic, readonly) cllocationcoordinate2d coordinate; @property (nonatomic, copy) nsstring *title; @property (nonatomic, copy) nsstring *subtitle; @property (nonatomic, copy) nsstring *test; @end /*myannotation.m*/ #import "myannotation.h" @implementation myannotation @synthesize coordinate, title, subtitle, test; - (id) initwithdictionary:(nsd...

java - How to have multiple spinners with one set of code -

Image
all- have layout looks this: my goal have 3 spinners on of rows. right on st. james (yes, monopoly). each spinner has significant amount of code , create whole new spinner scratch each row difficult @ best. tried duplicate first row , change text: <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <relativelayout android:id="@+id/stjameslay" android:layout_width="wrap_content" android:layout_height="wrap_content"> <textview android:id="@+id/st_james_place" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/st_james" android:padding="5dp" android:textsize="6pt" /> <spinner android:id="@+id/owner...

haskell - How to import specific PortNumber constructor -

simple question. this compiles: module example import network port :: portid port = portnumber 3001 and not: module example import network (portid, portnumber) port :: portid port = portnumber 3001 ghc says: example.hs:6:8: not in scope: data constructor `portnumber' why? it has be import network (portid(portnumber)) as portnumber seems constructor of portid . other import imports of network , hence portnumber found.

Magento - Add button [+ Add Field] that adds/shows a new text field in system.xml -

i have custom module optional text fields (shown via standard text field option in system.xml ). i'd show 1 mandatory text field , have button says [+ add field] . when button pressed, text field added. i'd up to 10 total text fields (max). can me accomplish or point me nice tutorial on how this? edit 7/10/12 @ 11:30am i've been working on , far can text fields show up. have few issues... when pressing "save config" button, none of values entered in these dynamically created textfields save. is there way limit how many text fields save? i'm unsure of correct way retrieve text field(s) data. due fact cannot save values...(i add update after #1 fixed if need this...) my system.xml file has in (directly related this).. <labels translate="label"> <label>this label</label> <comment>this comment.</comment> <tooltip><![cdata[this tooltip]]></tooltip> <frontend_type>text</frontend_type>...

bash - Capitalize the first letter of every word in a filename or directory in Shell -

i'm trying write shell command can specify directory, , every file , directory inside have first letter of every word capitalized. /documents/test.txt should change /documents/test.txt i'm thinking should start like for in directory tr something_goes_here done the problem can't figure out how first letter. i've made script uppercase whole file name, can't figure out how first letter of every word. thanks! using gnu sed you can quite gnu sed. example: $ echo '/documents/test.txt' | sed 's!/.!\u&!g' /documents/test.txt limitations note \u escape gnu sed extension. manual says: finally, gnu 'sed' extension, can include special sequence made of backslash , 1 of letters 'l', 'l', 'u', 'u', or 'e'. `\u' turn replacement uppercase until `\l' or `\e' found

entity framework - Listen for EDMX conversion? -

Image
when re-targeting project .net 4.0 .net 4.5 in vs2012 edmx in project automatically converted ef 5, i.e., namespaces updated match target framework. is there way, maybe via extension edm tools, "listen" conversion? use custom annotations in edmx, , when upgrade performed need convert/update our annotations. we implement imodeltransformextension perform custom logic when model loaded , saved, , in theory can use onaftermodelloaded conversion of annotations too, since conversion needed 1 time only, , when .net framework retargeted, great if there's option. any ideas? entity framework - listen edmx conversion? - stack overflow stack overflow questions developer jobs documentation beta tags users current community help chat stack overflow meta stack overflow communities sign up or log in customize list. more stack exchange communities company blog tour start here quick overview of site ...