Thursday, 15 September 2011

ruby on rails - Configure MX to both SendGrid and Google Apps in order to use sendgrid parse API -



ruby on rails - Configure MX to both SendGrid and Google Apps in order to use sendgrid parse API -

i utilize google apps mx records.

so have email utilize send emails in sendgrid:

support@mycompany.com

now, want parse emails sent straight back upwards email , come in in app using parse api.

the problem i'll have set mx records, create both google apps , sendgrid works, i'll have create subdomain like:

support@mail.mycompany.com

right now, have reputation first email.

am gonna lose if have create subdomain , start parsing emails?

currently, reputation has lot more ip domain (although providers, domain plays part). so, switching back upwards emails support@mail.example.com not end of world.

however, if want prevent this, there couple solutions can use:

reply-to, while still sending support@example.com have reply-to of support@mail.example.com (or taken step further, $unique_ticket_hash@mail.example.com). you'll see github , zendesk emails. this best. forwarding, can setup google apps business relationship forwards every email support@example.com support@mail.example.com. however, means you're counting on google apps , running back upwards emails work. while safe assumption still adds unnecessary complexity system.

ruby-on-rails sendgrid mx-record

dependency injection - Can Python do DI seamlessly without relying on a service locator? -



dependency injection - Can Python do DI seamlessly without relying on a service locator? -

i'm coming c# world, views may little skewed. i'm looking di in python, i'm noticing trend libraries appear rely on service locator. is, must tie object creation framework, such injectlib.build(myclass) in order instance of myclass.

here illustration of mean -

from injector import injector, inject class inner(object): def __init__(self): self.foo = 'foo' class outer(object): @inject(inner=inner) def __init__(self, inner=none): if inner none: print('inner not provided') self.inner = inner() else: print('inner provided') self.inner = inner injector = injector() outer = outer() print(outer.inner.foo) outer = injector.get(outer) print(outer.inner.foo)

is there way in python create class while automatically inferring dependency types based on parameter names? if have constructor parameter called my_class, instance of myclass injected. reason inquire don't see how inject dependency class gets created automatically via 3rd party library.

to reply question explicitly asked: no, there's no built-in way in python automatically myclass object parameter named my_class.

that said, neither "tying object creation framework" nor illustration code gave seem terribly pythonic, , question in general kind of confusing because di in dynamic languages isn't big deal.

for general thoughts di in python i'd this presentation gives pretty overview of different approaches. specific question, i'll give 2 options based on might trying do.

if you're trying add together di own classes, utilize paramaters default values in constructor, presentation shows. e.g:

import time class example(object): def __init__(self, sleep_func=time.sleep): self.sleep_func = sleep_func def foo(self): self.sleep_func(10) print('done!')

and pass in dummy sleep function testing or whatever.

if you're trying manipulate library's classes through di, (not can imagine utilize case for, seems you're asking) monkey patch classes alter whatever needed changing. e.g:

import test_module def dummy_sleep(*args, **kwargs): pass test_module.time.sleep = dummy_sleep e = test_module.example() e.foo()

python dependency-injection

php - jQuery AJAX fails to update database after full page is finished loading -



php - jQuery AJAX fails to update database after full page is finished loading -

this first time using jquery ajax bear me. trying create button website similar facebook button. user must logged on via facebook pull userid database. when user clicks on button, inserts row database user info , page info. if there entry user , page, update row.

my code runs fine on localhost. can click on button day , image alter , forth unlike , back. database updates every time no problem.

when upload live server, script runs fine point. 1 time page finishes loading completely, database no longer updates click. images alter usual , receive alert('success') no changes made actual database.

<?php $tempstat = '1'; if ($stmt = $mysqli -> prepare("select count(id) votes businessid=? , status=? ")) { $stmt -> bind_param('ss', $businessid, $tempstat); $stmt -> execute(); $stmt->bind_result($likecount); $stmt->fetch(); $stmt->close(); } if ($likecount == '') { $likecount = 0; } ?> <style> #karmabar { padding-left: 4px; } #counter { margin: 0 auto; text-align: center; width: 50px; height: 25px; background-image: url('/images/karma-counter.png'); } p#counter { font-size: 12px; padding-top: 5px; } .karma { margin: 0 auto; font-size: 16px; color: blue; text-align: center; padding: 5px; } </style> <?php if(login_check($mysqli) == true) { $userid = $_session['userurl']; if ($stmt = $mysqli -> prepare("select status votes userid=? , businessid=? ")) { $stmt -> bind_param('ss', $userid, $businessid); $stmt -> execute(); $stmt -> bind_result($like_status); $stmt->fetch(); $stmt->close(); } if ($like_status == '' or $like_status == null) { $like_status = '0'; } ?> <script type="text/javascript"> $(document).ready(function() { $('#like_post').click(function() { $.ajax({ url: "/includes/like.php", type: "get", data: 'userid=<?php echo $userid; ?>&businessid=<?php echo $businessid; ?>&like_status=1', success: function() { alert("success"); }, error: function() { alert("something went wrong"); } }); $('#counter').html(function(i, val) { homecoming val*1+1 }); $('#like_post').hide(); $('#unlike_post').show(); }); $('#unlike_post').click(function() { $.ajax({ url: "/includes/like.php", type: "get", data: 'userid=<?php echo $userid; ?>&businessid=<?php echo $businessid; ?>&like_status=0', success: function() { alert("success"); }, error: function() { alert("something went wrong"); } }); $('#counter').html(function(i, val) { homecoming val*1-1 }); $('#unlike_post').hide(); $('#like_post').show(); }); }); </script> <div id="karmabar"> <table cellpadding="0px"> <?php if ($like_status == '0') { ?> <tr><td><a href="javascript:;" id="unlike_post" class="hide"><img src="/images/karma-active.png" title="undo karma" /></a><a href="javascript:;" id="like_post"><img src="/images/karma-inactive.png" title="spread karma" /></a><td><p id="counter"><?php echo $likecount; ?></p></td></tr> <?php } else { ?> <tr><td><a href="javascript:;" id="unlike_post"><img src="/images/karma-active.png" title="undo karma" /></a><a href="javascript:;" id="like_post" class="hide"><img src="/images/karma-inactive.png" title="spread karma" /></a></td><td><p id="counter"><?php echo $likecount; ?></p></td></tr> <?php } ?> </table> </div> <?php } else { ?> <div id="karmabar"> <table cellpadding="0px"> <tr><td><a href="#" onclick="alert('login facebook spread karma');" ><img src="/images/karma-inactive.png" title="spread karma" /></a><td><p id="counter"><?php echo $likecount; ?></p></td></tr> </table> </div>

$businessid , $userid both defined higher on page.

like.php

<?php include_once $_server['document_root'].'/includes/db_connect.php'; include_once $_server['document_root'].'/includes/functions.php'; $userid = $_get['userid']; $businessid = $_get['businessid']; $ip = $mysqli->real_escape_string(getclientip()); $like_status = $_get['like_status']; if ($stmt = $mysqli -> prepare("select count(id) votes userid=? , businessid=? ")) { $stmt -> bind_param('ss', $userid, $businessid); $stmt -> execute(); $stmt ->bind_result($count); $stmt ->fetch(); $stmt ->close(); } if ($count == '1') { if ($stmt = $mysqli -> prepare("update votes set ip=?, status=? userid=? , businessid=? ")) { $stmt -> bind_param('ssss', $ip, $like_status, $userid, $businessid); $stmt -> execute(); $stmt -> close(); $mysqli -> close(); } } if ($count == '0') { if ($stmt = $mysqli -> prepare("insert votes (userid, businessid, ip, status) values ( ?, ?, ?, ? ) ")) { $stmt -> bind_param('ssss', $userid, $businessid, $ip, $like_status ); $stmt -> execute(); $stmt -> close(); $mysqli -> close(); } } ?>

i appreciate help guys can give me. said, i'm new kind of coding , looking pointers may have.

mike, i'm not sure what's going on, maybe can seek using type of ajax request / php returns problem shoot:

replace entire ajax function this:

$(document).ready(function() { $('#like_post').click(function() { $.post("/includes/like.php", {userid:<?php echo $userid; ?>, businessid:<?php echo $businessid; ?>, like_status:"1"}, function(data){ alert(data); //check see beingness returned if(data == 1){ //later, can echo "1" in php file on success //this success alert("success"); $('#counter').html(function(i, val) { homecoming val*1+1 }); $('#like_post').hide(); $('#unlike_post').show(); } else { //this failure alert("failure"); } }); }); $('#unlike_post').click(function() { $.post("/includes/like.php", {userid:<?php echo $userid; ?>, businessid:<?php echo $businessid; ?>, like_status:"0"}, function(data){ alert(data); //check see beingness returned if(data == 1){ //later, can echo "1" in php file on success //this success alert("success"); $('#counter').html(function(i, val) { homecoming val*1-1 }); $('#unlike_post').hide(); $('#like_post').show(); } else { //this failure alert("failure"); } }); }); });

and here php - notice, changed $_gets $_posts , added echo @ end. explain why after.

<?php include_once $_server['document_root'].'/includes/db_connect.php'; include_once $_server['document_root'].'/includes/functions.php'; $userid = $_post['userid']; $businessid = $_post['businessid']; $like_status = $_post['like_status']; $ip = $mysqli->real_escape_string(getclientip()); if ($stmt = $mysqli -> prepare("select count(id) votes userid=? , businessid=? ")) { $stmt -> bind_param('ss', $userid, $businessid); $stmt -> execute(); $stmt ->bind_result($count); $stmt ->fetch(); $stmt ->close(); echo "got count: " . $count; } if ($count == '1') { echo "the count 1"; if ($stmt = $mysqli -> prepare("update votes set ip=?, status=? userid=? , businessid=? ")) { $stmt -> bind_param('ssss', $ip, $like_status, $userid, $businessid); $stmt -> execute(); $stmt -> close(); $mysqli -> close(); echo "and post successful (1)"; } } if ($count == '0') { echo "the count 0"; if ($stmt = $mysqli -> prepare("insert votes (userid, businessid, ip, status) values ( ?, ?, ?, ? ) ")) { $stmt -> bind_param('ssss', $userid, $businessid, $ip, $like_status ); $stmt -> execute(); $stmt -> close(); $mysqli -> close(); echo "and post successful (0)"; } } echo "finished"; ?>

basically - i've added in bunch of echos able 'listen' $.post ajax phone call when returns data. if successful, should sentence returned saying "got count: 1thecount 1 , post successful(1)finished". of echos should fire when post successful. if don't 1 of sentences, has gone wrong.

try problem shoot , allow know comes back.

php jquery ajax mysqli

javascript - Display one Drupal block or another if flash is enabled -



javascript - Display one Drupal block or another if flash is enabled -

in drupal 7 site have view 2 block displays. difference between both 1 filter criteria -url aias-: 1 block shows content "/html5" in alias , other shows "/flash" url aliased content

those blocks must dispalyed on certains pages. logic controlled context module based on url. in way, block showed if url "perm/type/man/*"

at url need display 1 block or depending on flash content enabled or not @ device level: if device back upwards flash (like pc) flash content must dislayed. if device doesn't back upwards flash (mobile), html5 content shown.

i found js code observe if flash enabled on device

var hasflash = false; seek { var fo = new activexobject('shockwaveflash.shockwaveflash'); if (fo) { hasflash = true; } } grab (e) { if (navigator.mimetypes && navigator.mimetypes['application/x-shockwave-flash'] != undefined && navigator.mimetypes['application/x-shockwave-flash'].enabledplugin) { hasflash = true; } }

but don't know nor must include code.

can help me?

you may seek add together above code file or inline script drupal_add_js , go on follows:

load both blocks on same page initialy hidden , show 1 meets conditions in js. or load right block's content ajax , dump dom based on desired criteria.

javascript html5 flash drupal-7 drupal-views

c++ - How to add multi digit integers in a reverse polish calculator -



c++ - How to add multi digit integers in a reverse polish calculator -

// file: calc.h #include <iostream> #include <stack> // uses stl #include <string> // uses stl using namespace std; void evaluate_stack_tops(stack<double> & numbers, stack<char> & operations); double read_and_evaluate(string line) { const char right_parenthesis = ')'; stack<double> numbers; // local stack object stack<char> operations; // local stack object double number; char symbol; size_t position = 0; while (position < line.length()) { if (isdigit(line[position])) { number = line[position++] - '0'; // value numbers.push(number); } else if (strchr("+-*/", line[position]) != null) { symbol = line[position++]; operations.push(symbol); } else if (line[position] == right_parenthesis) { position++; evaluate_stack_tops(numbers, operations); } else position++; } if (!operations.empty()) evaluate_stack_tops(numbers, operations); homecoming numbers.top(); } void evaluate_stack_tops(stack<double> & numbers, stack<char> & operations) { double operand1, operand2; operand2 = numbers.top(); numbers.pop(); operand1 = numbers.top(); numbers.pop(); switch (operations.top()) { case '+': numbers.push(operand1 + operand2); break; case '-': numbers.push(operand1 - operand2); break; case '*': numbers.push(operand1 * operand2); break; case '/': numbers.push(operand1 / operand2); break; } operations.pop(); } // file: use_stack.cpp #include <iostream> using namespace std; #include "calc.h" int main() { double answer; string line; cout << "type parenthesized arithmetic look (single digits only!):\n"; getline(cin, line); reply = read_and_evaluate(line); cout << "that evaluates " << reply << endl; system("pause"); homecoming 0; }

everything works , can input simple things "2 4 3 * + 7 – 2 +" if wanted input "123 60 +" not work. separated in 2 header files. can give me hint on how take multi-digit integers?

one way solve problem find number, instead of assuming 1 digit long, utilize loop collect other digits part of number. loop terminate when encounters non-digit, or space.

a improve way tokenize input string using stringstream. in scenario, set entire line of input string , utilize while loop similar following:

stringstream ss(line); string token; while (ss >> token) { // stuff token }

c++ stack calculator postfix-notation

Autowiring of Spring Data Repo fails with Maven Skinny war option -



Autowiring of Spring Data Repo fails with Maven Skinny war option -

my question similar this 1 posted while ago autowiring of spring info repos fail when external libraries in ear's lib folder.

the wiring works fine when jars included in web-inf/lib. tried setting 'skinnywar' false duplicating jars in both ear , war.

the application uses spring batch admin 1.2.2 , spring info 1.1 spring 3.2.2 based. maven version used 3.3. runtime websphere 7.x

i have application works fine skinnywar set true - uses spring-ws, spring-data 4.0.x version.

the war pom

<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <artifactid>batchadmin-web</artifactid> <parent> <groupid>com.xyz.interfaces</groupid> <artifactid>batch-parent</artifactid> <version>1.0.build-snapshot</version> <relativepath>../batch-parent/pom.xml</relativepath> </parent> <packaging>war</packaging> <name>batch admin interface web</name> <dependencies> <!-- application specific jars/modules not included brevity--> </dependencies> <build> <finalname>springbatch-admin</finalname> <outputdirectory>${project.basedir}\src\main\webapp\web-inf\classes</outputdirectory> <testoutputdirectory>${project.basedir}\src\main\webapp\web-inf\classes</testoutputdirectory> <plugins> <plugin> <artifactid>maven-war-plugin</artifactid> <version>2.4</version> <configuration> <archive> <manifest> <addclasspath>true</addclasspath> <classpathprefix>lib/</classpathprefix> </manifest> </archive> <packagingexcludes>web-inf/lib/spring-beans*.jar</packagingexcludes> </configuration> </plugin> </plugins> </build> </project>

the ear pom content:

<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <artifactid>batchadmin-ear</artifactid> <parent> <groupid>com.xyz.interfaces</groupid> <artifactid>batch-parent</artifactid> <version>1.0.build-snapshot</version> <relativepath>../batch-parent/pom.xml</relativepath> </parent> <packaging>ear</packaging> <name>batch admin interface</name> <dependencies> <dependency> <groupid>com.xyz.interfaces</groupid> <artifactid>batchadmin-web</artifactid> <type>war</type> <version>${project.version}</version> </dependency> </dependencies> <build> <finalname>springbatchear</finalname> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-ear-plugin</artifactid> <version>2.9.1</version> <configuration> <skinnywars>true</skinnywars> <defaultlibbundledir>lib/</defaultlibbundledir> <modules> <webmodule> <groupid>com.xyz.interfaces</groupid> <artifactid>batchadmin-web</artifactid> <contextroot>/springbatch-admin</contextroot> <bundlefilename>springbatch-admin.war</bundlefilename> </webmodule> </modules> </configuration> </plugin> </plugins> </build>

update: since ear has 1 web module, used 'single class loader application' 'war class loader policy' in websphere. way, able create work.

i know how create work without changing classloader alternative might not preferred when multiple web modules present.

spring maven spring-data spring-batch-admin

meteor - App is broken after 0.9.4 update: undefined is not a function in dynamic_template.js:371 -



meteor - App is broken after 0.9.4 update: undefined is not a function in dynamic_template.js:371 -

i had meteor 0.9.3 app working.

i ran meteor update. have bunch or errors (60 total):

uncaught typeerror: undefined not function dynamic_template.js:371 uncaught typeerror: cannot read property 'prototype' of undefined helpers.js:140 uncaught typeerror: undefined not function router.js:61 uncaught typeerror: cannot read property 'routecontroller' of undefined iron-router-progress.js?2b52a697e5a2fba4ec827721c08cfdd0a5bae508:25 uncaught typeerror: cannot read property 'routecontroller' of undefined global-imports.js?a26cc176b56b3d2b1df619ec7af99630b0fb6a1f:3 uncaught referenceerror: template not defined template.about.js?3ead3e2cab8a60252235e31f2533c2179f736294:2 uncaught referenceerror: template not defined template.register.js?60e4180bd0193951fab290d41493f5036f66240d:2 ... 53 more errors: ... "template not defined" , "meteor not defined"

line 371 of dynamic_template.js following:

ui.registerhelper('dynamictemplate', template.__create__('dynamictemplatehelper', function () {

what's wierd if seek go meteor update --release 0.9.3 or 0.9.2, still have errors. i'm stuck, have prepare those.

another anoying thing everytime start meteor server, updating bundle catalog progress bar, , server takes while (~10s) start up.

any ideas?

in 0.9.4 there changes templating api. see history.md on gihub/meteor/meteor more details.

the prepare immediate problem replace ui template

template.registerhelper('dynamictemplate', template.__create__('dynamictemplatehelper', function () {

meteor meteor-0.9.4