Search Results

Search found 10930 results on 438 pages for 'self signed'.

Page 23/438 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • rails when to use self.

    - by fenec
    i am developing a rails application and would like to understand when do we use self.for . here is the code of a method that i would like to fully understand.if it is possible i would like to have an alternative to this code so it would make things more clear. enter code here def self.for(facebook_id) User.create_by_facebook_id(facebook_id) end

    Read the article

  • NSTimer as a self-targeting ivar.

    - by Matt Wilding
    I have come across an awkward situation where I would like to have a class with an NSTimer instance variable that repeatedly calls a method of the class as long as the class is alive. For illustration purposes, it might look like this: // .h @interface MyClock : NSObject { NSTimer* _myTimer; } - (void)timerTick; @end - // .m @implementation MyClock - (id)init { self = [super init]; if (self) { _myTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerTick) userInfo:nil repeats:NO] retain]; } return self; } - (void)dealloc { [_myTimer invalidate]; [_myTImer release]; [super dealloc]; } - (void)timerTick { // Do something fantastic. } @end That's what I want. I don't want to to have to expose an interface on my class to start and stop the internal timer, I just want it to run while the class exists. Seems simple enough. But the problem is that NSTimer retains its target. That means that as long as that timer is active, it is keeping the class from being dealloc'd by normal memory management methods because the timer has retained it. Manually adjusting the retain count is out of the question. This behavior of NSTimer seems like it would make it difficult to ever have a repeating timer as an ivar, because I can't think of a time when an ivar should retain its owning class. This leaves me with the unpleasant duty of coming up with some method of providing an interface on MyClock that allows users of the class to control when the timer is started and stopped. Besides adding unneeded complexity, this is annoying because having one owner of an instance of the class invalidate the timer could step on the toes of another owner who is counting on it to keep running. I could implement my own pseudo-retain-count-system for keeping the timer running but, ...seriously? This is way to much work for such a simple concept. Any solution I can think of feels hacky. I ended up writing a wrapper for NSTimer that behaves exactly like a normal NSTimer, but doesn't retain its target. I don't like it, and I would appreciate any insight.

    Read the article

  • Python dictionary key missing

    - by Greg K
    I thought I'd put together a quick script to consolidate the CSS rules I have distributed across multiple CSS files, then I can minify it. I'm new to Python but figured this would be a good exercise to try a new language. My main loop isn't parsing the CSS as I thought it would. I populate a list with selectors parsed from the CSS files to return the CSS rules in order. Later in the script, the list contains an element that is not found in the dictionary. for line in self.file.readlines(): if self.hasSelector(line): selector = self.getSelector(line) if selector not in self.order: self.order.append(selector) elif selector and self.hasProperty(line): # rules.setdefault(selector,[]).append(self.getProperty(line)) property = self.getProperty(line) properties = [] if selector not in rules else rules[selector] if property not in properties: properties.append(property) rules[selector] = properties # print "%s :: %s" % (selector, "".join(rules[selector])) return rules Error encountered: $ css-combine combined.css test1.css test2.css Traceback (most recent call last): File "css-combine", line 108, in <module> c.run(outfile, stylesheets) File "css-combine", line 64, in run [(selector, rules[selector]) for selector in parser.order], KeyError: 'p' Swap the inputs: $ css-combine combined.css test2.css test1.css Traceback (most recent call last): File "css-combine", line 108, in <module> c.run(outfile, stylesheets) File "css-combine", line 64, in run [(selector, rules[selector]) for selector in parser.order], KeyError: '#header_.title' I've done some quirky things in the code like sub spaces for underscores in dictionary key names in case it was an issue - maybe this is a benign precaution? Depending on the order of the inputs, a different key cannot be found in the dictionary. The script: #!/usr/bin/env python import optparse import re class CssParser: def __init__(self): self.file = False self.order = [] # store rules assignment order def parse(self, rules = {}): if self.file == False: raise IOError("No file to parse") selector = False for line in self.file.readlines(): if self.hasSelector(line): selector = self.getSelector(line) if selector not in self.order: self.order.append(selector) elif selector and self.hasProperty(line): # rules.setdefault(selector,[]).append(self.getProperty(line)) property = self.getProperty(line) properties = [] if selector not in rules else rules[selector] if property not in properties: properties.append(property) rules[selector] = properties # print "%s :: %s" % (selector, "".join(rules[selector])) return rules def hasSelector(self, line): return True if re.search("^([#a-z,\.:\s]+){", line) else False def getSelector(self, line): s = re.search("^([#a-z,:\.\s]+){", line).group(1) return "_".join(s.strip().split()) def hasProperty(self, line): return True if re.search("^\s?[a-z-]+:[^;]+;", line) else False def getProperty(self, line): return re.search("([a-z-]+:[^;]+;)", line).group(1) class Consolidator: """Class to consolidate CSS rule attributes""" def run(self, outfile, files): parser = CssParser() rules = {} for file in files: try: parser.file = open(file) rules = parser.parse(rules) except IOError: print "Cannot read file: " + file finally: parser.file.close() self.serialize( [(selector, rules[selector]) for selector in parser.order], outfile ) def serialize(self, rules, outfile): try: f = open(outfile, "w") for rule in rules: f.write( "%s {\n\t%s\n}\n\n" % ( " ".join(rule[0].split("_")), "\n\t".join(rule[1]) ) ) except IOError: print "Cannot write output to: " + outfile finally: f.close() def init(): op = optparse.OptionParser( usage="Usage: %prog [options] <output file> <stylesheet1> " + "<stylesheet2> ... <stylesheetN>", description="Combine CSS rules spread across multiple " + "stylesheets into a single file" ) opts, args = op.parse_args() if len(args) < 3: if len(args) == 1: print "Error: No input files specified.\n" elif len(args) == 2: print "Error: One input file specified, nothing to combine.\n" op.print_help(); exit(-1) return [opts, args] if __name__ == '__main__': opts, args = init() outfile, stylesheets = [args[0], args[1:]] c = Consolidator() c.run(outfile, stylesheets) Test CSS file 1: body { background-color: #e7e7e7; } p { margin: 1em 0em; } File 2: body { font-size: 16px; } #header .title { font-family: Tahoma, Geneva, sans-serif; font-size: 1.9em; } #header .title a, #header .title a:hover { color: #f5f5f5; border-bottom: none; text-shadow: 2px 2px 3px rgba(0, 0, 0, 1); } Thanks in advance.

    Read the article

  • QTreeWidget activate item signals

    - by serge
    Hi everyone, I need to do some actions when item in QTreeWidget activates, but following code doestn't gives me expected result: class MyWidget(QTreeWidget): def __init__(self, parent=None): super(MyWidget, self).__init__(parent) self.connect(self, SIGNAL("activated(QModelIndex)"), self.editCell) def editCell(self, index): print index or class MyWidget(QTreeWidget): def __init__(self, parent=None): super(MyWidget, self).__init__(parent) self.connect(self, SIGNAL("itemActivated(QTreeWidgetItem, int)"), self.editCell) def editCell(self, item, column=0): print item What am i doing wrong or how to hadnle item activation in the right way? Thanks in advance, Serge

    Read the article

  • executable was signed with invalid entitlements ?

    - by balraj
    HI,all I am trying to install an app in the iphone using the adhoc build configuration for this i have made all the things first i created the app id that is enable fort he APNS and then create the profile and certificates and than i download to my system and then in the project i have made a plist name Adhoc_Entitlements.plist and in the code signing entitlements i put it name with extension and in the bundle identifier i put the name of the identifier that is used in the provision file and when i try to install in the device it throws the error i have mentioned,Any solution or anything that i am doing wrong.This is the error message i got when i try to install in the device. Thanks the error message is as -- The entitlements specified in your application's code signing entitlements file do not match those specified in your provisioning profile.

    Read the article

  • Setup SSL (self signed cert) with tomcat

    - by Danny
    I am mostly following this page: http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html I used this command to create the keystore keytool -genkey -alias tomcat -keyalg RSA -keystore /etc/tomcat6/keystore and answered the prompts Then i edited my server.xml file and uncommented/edited this line <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/etc/tomcat6/keystore" keystorePass="tomcat" /> then I go to the web.xml file for my project and add this into the file <security-constraint> <web-resource-collection> <web-resource-name>Security</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> When I try to run my webapp I am met with this: Unable to connect Firefox can't establish a connection to the server at localhost:8443. * The site could be temporarily unavailable or too busy. Try again in a few moments. * If you are unable to load any pages, check your computer's network connection. If I comment out the lines I've added to my web.xml file, the webapp works fine. My log file in /var/lib/tomcat6/logs says nothing. I can't figure out if this is a problem with my keystore file, my server.xml file or my web.xml file.... Any assistance is appreciated I am using tomcat 6 on ubuntu.

    Read the article

  • PyQt Drag and Drop - Nothing happens

    - by Umang
    Hi, I'm trying to get drop a file onto a Window (I've tried the same thing with a QListWidget without success there too) test.py: #! /usr/bin/python # Test from PyQt4 import QtCore, QtGui import sys from qt_test import Ui_MainWindow class MyForm(QtGui.QMainWindow, Ui_MainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.setupUi(self) self.__class__.dragEnterEvent = self.DragEnterEvent self.__class__.dragMoveEvent = self.DragEnterEvent self.__class__.dropEvent = self.drop self.setAcceptDrops(True) print "Initialized" self.show() def DragEnterEvent(self, event): event.accept() def drop(self, event): link=event.mimeData().text() print link def main(): app = QtGui.QApplication(sys.argv) mw = MyForm() sys.exit(app.exec_()) if __name__== "__main__": main() And here's qt_test.py # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'untitled.ui' # # Created: Thu May 20 12:23:19 2010 # by: PyQt4 UI code generator 4.6 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) MainWindow.setAcceptDrops(True) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8)) I've read this email and I've followed everything said there. I still don't get any output except "Initialized" and the drag doesn't seem to get accepted (both for files from a file manager and plain text dragged from a text editor). Do you know what I'm doing wrong? Thanks!

    Read the article

  • Rails class << self

    - by xpepermint
    Hey. I would like to understand what "class << self" stands for in the next example. module Utility class Options #:nodoc: class << self def parse(args) end end end end Thx!

    Read the article

  • Copy **kwargs to self?

    - by Mark
    Given class ValidationRule: def __init__(self, **kwargs): # code here Is there a way that I can define __init__ such that if I were to initialize the class with something like ValidationRule(other='email') then self.other would be "added" to class without having to explicitly name every possible kwarg?

    Read the article

  • Android: how to share code between projects signed with the same certificate

    - by tomash
    In Android documentation concerning code signing we can read: "By signing multiple applications with the same certificate and using signature-based permissions checks, your applications can share code and data in a secure manner." How exactly such code sharing can be done? Is it possible to release main application and multiple exchangeable plugins then discover them at runtime? What does source code looks like and what are advantages over "standard" intents calls from/to different APK packages?

    Read the article

  • python sax error "junk after document element"

    - by user293487
    Hi, I use python sax to parse xml file. The xml file is actually a combination of multiple xml files. It looks like as follows: <row name="abc" age="40" body="blalalala..." creationdate="03/10/10" /> <row name="bcd" age="50" body="blalalala..." creationdate="03/10/09" /> My python code is in the following. It show "junk after document element" error. Any good idea to solve this problem. Thanks. from xml.sax.handler import ContentHandler from xml.sax import make_parser,SAXException import sys class PostHandler (ContentHandler): def __init__(self): self.find = 0 self.buffer = '' self.mapping={} def startElement(self,name,attrs): if name == 'row': self.find = 1 self.body = attrs["body"] print attrs["body"] def character(self,data): if self.find==1: self.buffer+=data def endElement(self,name): if self.find == 1: self.mapping[self.body] = self.buffer print self.mapping parser = make_parser() handler = PostHandler() parser.setContentHandler(handler) try: parser.parse(open("2.xml")) except SAXException:

    Read the article

  • How to set the size of a wx.aui.AuiManager Pane that is centered?

    - by aF
    Hello, I have three panes with the InfoPane center option. I want to know how to set their size. Using this code: import wx import wx.aui class MyFrame(wx.Frame): def __init__(self, parent, id=-1, title='wx.aui Test', pos=wx.DefaultPosition, size=(800, 600), style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) self._mgr = wx.aui.AuiManager(self) # create several text controls text1 = wx.TextCtrl(self, -1, 'Pane 1 - sample text', wx.DefaultPosition, wx.Size(200,150), wx.NO_BORDER | wx.TE_MULTILINE) text2 = wx.TextCtrl(self, -1, 'Pane 2 - sample text', wx.DefaultPosition, wx.Size(200,150), wx.NO_BORDER | wx.TE_MULTILINE) text3 = wx.TextCtrl(self, -1, 'Main content window', wx.DefaultPosition, wx.Size(200,150), wx.NO_BORDER | wx.TE_MULTILINE) # add the panes to the manager self._mgr.AddPane(text1, wx.CENTER) self._mgr.AddPane(text2, wx.CENTER) self._mgr.AddPane(text3, wx.CENTER) # tell the manager to 'commit' all the changes just made self._mgr.Update() self.Bind(wx.EVT_CLOSE, self.OnClose) def OnClose(self, event): # deinitialize the frame manager self._mgr.UnInit() # delete the frame self.Destroy() app = wx.App() frame = MyFrame(None) frame.Show() app.MainLoop() I want to know what is called when we change the size of the panes. If you tell me that, I can do the rest by myself :)

    Read the article

  • 'int' object is not callable

    - by Oscar Reyes
    I'm trying to define a simply Fraction class And I'm getting this error: python fraction.py Traceback (most recent call last): File "fraction.py", line 20, in <module> f.numerator(2) TypeError: 'int' object is not callable The code follows: class Fraction(object): def __init__( self, n=0, d=0 ): self.numerator = n self.denominator = d def get_numerator(self): return self.numerator def get_denominator(self): return self.denominator def numerator(self, n): self.numerator = n def denominator( self, d ): self.denominator = d def prints( self ): print "%d/%d" %(self.numerator, self.denominator) if __name__ == "__main__": f = Fraction() f.numerator(2) f.denominator(5) f.prints() I thought it was because I had numerator(self) and numerator(self, n) but now I know Python doesn't have method overloading ( function overloading ) so I renamed to get_numerator but that's not the problems. What could it be?

    Read the article

  • How do I send signed emails from ActionMailer?

    - by James A. Rosen
    I'm using GMail as my SMTP server. I have that configuration working just fine: # config/initializers/action_mailer.rb: ActionMailer::Base.smtp_settings = { :tls => true, :address => "smtp.gmail.com", :port => "587", :domain => "www.example.org", :authentication => :login, :user_name => "[email protected]", :password => "it's a secret" } I also have a public/private RSA key pair in config/ssl/rsa.public and config/ssl/rsa.private. What do I do to sign the emails before shipping them off to GMail's SMTP server?

    Read the article

  • wxpython: Updating a dict or other appropriate data type from wx.lib.sheet.CSheet object

    - by bvmou
    If I have a notebook with three spreadsheet widgets, what is the best way to have changes to the spreadsheet update a dictionary (or maybe an sqlite file?). Do all wx grid objects come with a built in dictionary related to the SetNumberRows and SetNumberCols? Basically I am looking for guidance on how to work with the user-input data from a spreadsheet widget, as in this example adapted from the tutorial on python.org: class ExSheet(wx.lib.sheet.CSheet): def __init__(self, parent): sheet.CSheet.__init__(self, parent) self.SetLabelBackgroundColour('#CCFF66') self.SetNumberRows(50) self.SetNumberCols(50) class Notebook(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM) self.sheet1 = ExSheet(nb) self.sheet2 = ExSheet(nb) self.sheet3 = ExSheet(nb) nb.AddPage(self.sheet1, "Sheet1") nb.AddPage(self.sheet2, "Sheet2") nb.AddPage(self.sheet3, "Sheet3") self.sheet1.SetFocus() self.StatusBar()

    Read the article

  • add a decorate function to a class

    - by wiso
    I have a decorated function (simplified version): class Memoize: def __init__(self, function): self.function = function self.memoized = {} def __call__(self, *args, **kwds): hash = args try: return self.memoized[hash] except KeyError: self.memoized[hash] = self.function(*args) return self.memoized[hash] @Memoize def _DrawPlot(self, options): do something... now I want to add this method to a pre-esisting class. ROOT.TChain.DrawPlot = _DrawPlot when I call this method: chain = TChain() chain.DrawPlot(opts) I got: self.memoized[hash] = self.function(*args) TypeError: _DrawPlot() takes exactly 2 arguments (1 given) why doesn't it propagate self?

    Read the article

  • WxPython multiple grid instances

    - by randomPythonHacker
    Does anybody know how I can get multiple instances of the same grid to display on one frame? Whenever I create more than 1 instance of the same object, the display of the original grid widget completely collapses and I'm left unable to do anything with it. For reference, here's the code: import wx import wx.grid as gridlib class levelGrid(gridlib.Grid): def __init__(self, parent, rows, columns): gridlib.Grid.__init__(self, parent, -1) self.moveTo = None self.CreateGrid(rows, columns) self.SetDefaultColSize(32) self.SetDefaultRowSize(32) self.SetColLabelSize(0) self.SetRowLabelSize(0) self.SetDefaultCellBackgroundColour(wx.BLACK) self.EnableDragGridSize(False) class mainFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(768, 576)) editor = levelGrid(self, 25, 25) panel1 = wx.Panel(editor, -1) #vbox = wx.BoxSizer(wx.VERTICAL) #vbox.Add(editor, 1, wx.EXPAND | wx.ALL, 5) #selector = levelGrid(self, 1, 25) #vbox.Add(selector, 1, wx.EXPAND |wx.BOTTOM, 5) self.Centre() self.Show(True) app = wx.App() mainFrame(None, -1, "SLAE") app.MainLoop()

    Read the article

  • Rectangle Rotation in Python/Pygame

    - by mramazingguy
    Hey I'm trying to rotate a rectangle around its center and when I try to rotate the rectangle, it moves up and to the left at the same time. Does anyone have any ideas on how to fix this? def rotatePoint(self, angle, point, origin): sinT = sin(radians(angle)) cosT = cos(radians(angle)) return (origin[0] + (cosT * (point[0] - origin[0]) - sinT * (point[1] - origin[1])), origin[1] + (sinT * (point[0] - origin[0]) + cosT * (point[1] - origin[1]))) def rotateRect(self, degrees): center = (self.collideRect.centerx, self.collideRect.centery) self.collideRect.topleft = self.rotatePoint(degrees, self.collideRect.topleft, center) self.collideRect.topright = self.rotatePoint(degrees, self.collideRect.topright, center) self.collideRect.bottomleft = self.rotatePoint(degrees, self.collideRect.bottomleft, center) self.collideRect.bottomright = self.rotatePoint(degrees, self.collideRect.bottomright, center)

    Read the article

  • how to parse self closing tag in xml file

    - by ajay-sharma2
    Hi, I am working on an iphone application in which I am consuming a webservice. So i am parsing the XML file data. any idea about how to parse self closing tag like: State/ and how to read data of self tag like: Contact Email="[email protected]" Name="PhD" Phone="123-521-3388" Source="location"/ I am parsing xml file using NSXMLPARSER class methods and library Thanks,

    Read the article

  • How can I position QDockWidgets as the screen shot shows using code?

    - by Nathan
    I want a Qt window to come up with the following arrangement of dock widgets on the right. Qt allows you to provide an argument to the addDockWidget method of QMainWindow to specify the position (top, bottom, left or right) but apparently not how two QDockWidgets placed on the same side will be arranged. Here is the code that adds the dock widgets. this uses PyQt4 but it should be the same for Qt with C++ self.memUseGraph = mem_use_widget(self) self.memUseDock = QDockWidget("Memory Usage") self.memUseDock.setObjectName("Memory Usage") self.memUseDock.setWidget(self.memUseGraph) self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.memUseDock) self.diskUsageGraph = disk_usage_widget(self) self.diskUsageDock = QDockWidget("Disk Usage") self.diskUsageDock.setObjectName("Disk Usage") self.diskUsageDock.setWidget(self.diskUsageGraph) self.addDockWidget(Qt.DockWidgetArea(Qt.RightDockWidgetArea),self.diskUsageDock) When this code is used to add both of them to the right side, one is above the other, not like the screen shot I made. The way I made that shot was to drag them there with the mouse after starting the program, but I need it to start that way.

    Read the article

  • Python : How to close a UDP socket while is waiting for data in recv ?

    - by alexroat
    Hello, let's consider this code in python: import socket import threading import sys import select class UDPServer: def __init__(self): self.s=None self.t=None def start(self,port=8888): if not self.s: self.s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.s.bind(("",port)) self.t=threading.Thread(target=self.run) self.t.start() def stop(self): if self.s: self.s.close() self.t.join() self.t=None def run(self): while True: try: #receive data data,addr=self.s.recvfrom(1024) self.onPacket(addr,data) except: break self.s=None def onPacket(self,addr,data): print addr,data us=UDPServer() while True: sys.stdout.write("UDP server> ") cmd=sys.stdin.readline() if cmd=="start\n": print "starting server..." us.start(8888) print "done" elif cmd=="stop\n": print "stopping server..." us.stop() print "done" elif cmd=="quit\n": print "Quitting ..." us.stop() break; print "bye bye" It runs an interactive shell with which I can start and stop an UDP server. The server is implemented through a class which launches a thread in which there's a infinite loop of recv/*onPacket* callback inside a try/except block which should detect the error and the exits from the loop. What I expect is that when I type "stop" on the shell the socket is closed and an exception is raised by the recvfrom function because of the invalidation of the file descriptor. Instead, it seems that recvfrom still to block the thread waiting for data even after the close call. Why this strange behavior ? I've always used this patter to implements an UDP server in C++ and JAVA and it always worked. I've tried also with a "select" passing a list with the socket to the xread argument, in order to get an event of file descriptor disruption from select instead that from recvfrom, but select seems to be "insensible" to the close too. I need to have a unique code which maintain the same behavior on Linux and Windows with python 2.5 - 2.6. Thanks.

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >