Tagged Questions
3
votes
4answers
132 views
Why are Python and Ruby so slow, while Lisp implementations are fast? [on hold]
I find that simple things like function calls and loops, and even just loops incrementing a counter take far more time in Python and Ruby than in Chicken Scheme, Racket, or SBCL.
Why is this so? I ...
0
votes
0answers
13 views
PERL5LIB, LD_LIBRARY_CONF, PYTHONPATH - tutorial to tie these all together? [on hold]
My question isn't nearly so much "how to use these environmental variables" but rather, where can I find a good tutorial that will introduce and explain these topics to a newcomer.
I'm a systems ...
1
vote
2answers
62 views
How to use together!? Python, Lua, and Ruby?
I'm started programming not too long ago. I use a little of Python, Lua, and Ruby. Is it possible to compile all three scripts into one executable using py2exe, py2app, or py2deb?
If not, which one ...
0
votes
2answers
26 views
Iterating over multidimensional list in Python
I am trying to iterate over a multidimensional list in Python but it is not acting as I would expect.
POIs = {'GTA': {'areas': [{'lat': 43.7, 'range': '40km', 'long': -79.416}]}, 'Montreal': ...
2
votes
2answers
56 views
Linking and Loading in interpreted languages
In compiled languages, the source code is turned into object code by the compiler and the different object files (if there are multiple files) are linked by the linker and loaded into the memory by ...
0
votes
2answers
36 views
Stripping headers and footers
What would be the most elegant way to do this (which I do in Ruby) in python.
private_key = base64data.to_s.sub('-----BEGIN RSA PRIVATE KEY-----', '')
private_key = private_key.sub('-----END RSA ...
1
vote
3answers
51 views
What's the Ruby equivalent of Python's defaultdict?
In Python, I can make a hash where each element has a default value when it's first referenced (also know as "autovivification"). Here's an example:
from collections import defaultdict
d = ...
0
votes
0answers
49 views
Tornado vs eventmachine
To get good performance in ruby eventmachine you need to apply rules like:
don't block reactor
using em drivers to everything that system uses
Does similar rules apply to Python's Tornado library?
...
1
vote
2answers
40 views
Clean up string extracted from csv file
I am extracting certain data from a csv file using Ruby and I want to cleanup the extracted string by removing the unwanted characters.
This is how I extract the data so far:
CSV.foreach(data_file, ...
1
vote
1answer
48 views
RubyPython imports
I'm fairly new to both python and ruby.
I've created a python script that imports it's dependencies like this:
import sys
sys.path.append("/usr/share/anki")
from anki import Collection
from ...
4
votes
1answer
69 views
AES Python encryption and Ruby encryption - different behaviour?
From this site I have this code snippet:
>>> from Crypto.Cipher import AES
>>> obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
>>> message = "The answer ...
2
votes
2answers
128 views
Is the stream splitting from bash transposable to other languages?
By stream splitting I mean the ability to:
filter on the fly the stream content by a first function
one part of the stream is processed by a second function
the rest of the stream is processed by a ...
0
votes
0answers
61 views
How does Ruby's handling of socket output streams differ from Java's?
I have a Python server that listens for json requests. The "receiving" section of the code looks like this:
while True:
next_message = conn.recv(1024)
response = ...
1
vote
0answers
23 views
How to add terminal-notifier when packaging with py2app
I am making an app on mac osx 10.8.2. using python script. I am using terminal-notifier-1.5.1.gem for pop-ups notifications. It is installed on /Library/Ruby. Issue is how to include this while making ...
2
votes
1answer
57 views
ruby equivalent of python izip_longest [closed]
I am trying to learn ruby.
At this moment I have a list of lists, and I would like to the equivalent of the following python code:
import itertools
l = [[1,2], [3], [10, 20, -4, 5]]
...
1
vote
1answer
28 views
How to include terminal-notifier when packaging with py2app
I am making an app in python on mac osx. I am using py2app for making myapp.app from myapp.py python script file and setup.py. In my myapp.py code, I am using terminal-notifier as
def notify(title, ...
5
votes
2answers
143 views
Integer division by negative number
What should integer division -1 / 5 return? I am totally confused by this behaviour. I think mathematically it should be 0, but python and ruby are returning -1.
Why are different languages behaving ...
0
votes
1answer
55 views
how to pass params as json in ajax call from ruby?
I am making ajax rest call from ruby and its going to python to do rest call proccess. when i trying to call rest and passing params in json formate, i think its may not passing this as json data.
My ...
0
votes
2answers
41 views
Python like Ruby inheritance [closed]
In python, I can do something like this:
# say.py
class Speaker:
def speak(self,word):
pass
def Do(self):
self.speak("hello")
Speaker().Do()
If I run this, it would do ...
0
votes
0answers
30 views
Why does reinstalling and uninstalling Homebrew fail?
It has been taking me a long time, and I still don't have a solution to solve a problem I have installing Homebrew.
When I type ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)", I ...
0
votes
3answers
76 views
Converting a Ruby hash string to a Python dictionary
I'm working with some command output that's returned as the string of a Ruby hash. (From something called mcollective).
Here is an example string I'm receiving:
{:changes=>{"total"=>0}, ...
1
vote
3answers
78 views
Recording url redirections
Does anyone know whether there is a simple way to record all urls on a path of url redirections?
For example: the url: (url 1) redirects to (url 2) which redirects to (url 3).
I would like to write ...
0
votes
1answer
52 views
Python equivalent of a ruby Gem file
So I have a ruby sinatra program that runs on a server and I have a Gem file to ensure all its dependancies are installed. However it calls a python script which has its own python module ...
0
votes
1answer
103 views
Programmatically check a website's SSL certificate for expiration
How can this be done with a common scripting language such as python, ruby, or bash? I.e., I'd like to write a script that will either return a "valid" or "expired" result. It looks like the openssl ...
-2
votes
1answer
76 views
How do I ACTUALLY learn to program? [closed]
For the past two years or so, I've messed around with Python, PHP, Ruby, and Rails. But now, I'm really trying to get serious with Rails.
I keep buying books, screencasts, tutorials, etc., but I ...
0
votes
2answers
76 views
Why the distinction between single-line and multi-line comments? [closed]
In the languages like python, ruby, javascript, there is separate syntax for single-line and multi-line comments. I don't see the benefit of this complexity. Why, from a language design perspective, ...
0
votes
0answers
149 views
Comparison of parsing data in Ruby using Nokogiri and Python using lxml and xpath
I am trying to convert Ruby syntax into its Python equivalent:
Here is the Ruby code:
collection_action :updateBackPlayers, :method => :get do
...
2
votes
3answers
78 views
Python equivalent to Ruby Array.each method
In Python what is equivalent to Ruby's Array.each method? Does Python have a nice and short closure/lambda syntax for it?
[1,2,3].each do |x|
puts x
end
1
vote
1answer
40 views
Pythons getattr in Ruby
In python, it has getattr for example I could do:
class test:
def say(word):
return word
Doing,
getattr(test,'say')('something')
returns this:
'something'
Because you ...
0
votes
0answers
31 views
Ruby interval scheduler ported from python
I'm trying to make a type of interval that does x process every x amount of times depending on what was specified I have no idea how to really do this in ruby but, I did make on in python recently and ...
0
votes
1answer
123 views
Convert Python code into Ruby
Okay, I'm new to ruby and I need some good advice on this.
Python code:
return [x for x in list if x == something]
Sorry for not filling in the stuff, but I can't really since I this question ...
-3
votes
1answer
75 views
Translating python code to ruby [closed]
Alright, I'm new to ruby and I have this ID generator that Generates an ID based off of the Time.now.to_f/time.time() and then a 8 length id, for example this is the working python version
def ...
1
vote
2answers
46 views
How to split array of strings into sub-arrays according to special starting character? [closed]
Can you simplify this code from Python into Ruby? Lets say I have this data
data = ['hello', 'person', ';hello', 'otherperson']
print([x.split("@") for x in "@".join(data).split(";")])
When I ...
0
votes
2answers
99 views
Is there an eval in ruby
Does ruby have something like pythons eval? I'm searching google and I don't know if it's how i'm searching but I can't find anything on it or how to use it if there is one
In python I would ...
1
vote
1answer
47 views
How do I get a sum of a list or array?
I have a list/array and I want to get the sum of all the values. I have been trying this:
@w12,@sv2,@sv4,@sv6,@sv8,@sv10,@sv12=75,95,110,104,101,110,116
@supers = [["5", @w12], ["6", @w12], ["7", ...
1
vote
2answers
48 views
Assistance with ruby def
So, I'm new to ruby and very curious about it. I'm comming from python. in python I would do this to see if something was present in a dictionary.
dictionary = dict()
dictionary['key'] = 5
def ...
0
votes
1answer
45 views
Ruby class and def
I started learning Ruby today, coming from Python.
I have a few Python examples I'm trying to use in Ruby:
def id():
return random.randrange(10**15,10**16)
class test:
def __init__(self):
...
-1
votes
2answers
94 views
ruby draw color specific pixels from source image to new image
how can i take all the whitish pixels from an image and draw them on to a new image with a new color. the code below is how i would do it with python but the majority of the project has been written ...
1
vote
0answers
239 views
Optimize code for nth prime number Ruby/Python
I need to find the nth prime number, in the fastest way possible in Ruby or Python:
require "prime"
puts Prime.first(n).join("")
This takes a lot of time for numbers >= 100000.
How do I ...
4
votes
2answers
82 views
Ruby equivalent for python try
I am a major noob at coding. I started to learn Python, but wasn't a fan and switched to Ruby, which I love. Now I'm trying to convert some python code into ruby and I am stuck at python's "try" is ...
0
votes
2answers
52 views
Data Mining: grouping based on two text values (IDs) and one numeric (ratio)
For a music project I want to find what which groups of artists users listens to. I have extracted three columns from the database: the ID of the artist, the ID of the user, and the percentage of all ...
2
votes
2answers
120 views
It is possible to create compilers for dynamic languages without losing his dynamic characteristics? [closed]
Are there some set of reasons that make it impossible for dynamic languages such as Python or Ruby to be compiled instead of interpreted without losing any of his dynamics characteristics?
Of ...
-2
votes
2answers
130 views
Get Links From Web Page [closed]
I need to get all the item links(URLs) from this webpage into a text file delimited by breaks (in other words a list like so: "Item #1" "Item #2" etc.
http://dota-trade.com/equipment?order=name is ...
1
vote
3answers
97 views
Call python script from ruby
For example, I can use Python scripts in PHP like there:
exec("python script.py params",$result);
, where "script.py" - script name and var $result save output data.
How I can make it with Ruby? I ...
0
votes
0answers
77 views
How do I split messages between different queues evenly?
I want to change a RabbitMQ cluster I created. I want to have one node that would hold a stats/disck. And I want to have two more nodes that would work in RAM.
How do I create a queue on each ...
1
vote
1answer
99 views
how to write a script to edit a JSON file? [closed]
For example I have a file called people.json. Its content is:
[
{"name": "Paul",
"age": 29,
},
{"name": "Kathy",
"age": 101,
},
{"name": "Paula",
"age": 12,
},
{"name": "Bruce",
...
0
votes
2answers
114 views
Why Ruby and Python long division differs from GMP and Java BigInteger?
I'm developing a Big Integer class(didactic purpose) and I have been using Ruby to generate test cases. My class fails in the following test:
a = ...
0
votes
1answer
170 views
How can I use Python to output a certificates-only PKCS#7
I'm implementing a SCEP server in Python. The SCEP spec calls for me to respond to a PKIOperation with a "a certificate-only PKCS#7". Apple has a reference implementation in Ruby that does the ...
3
votes
0answers
95 views
Using laptop's light sensor in Linux [closed]
My laptop is a VAIO VPCF1 and has a light sensor to lighten the keyboard when it's dark. I want to use this sensor as a security tool. As a password. For example, I execute an script and put my finger ...
0
votes
1answer
56 views
I need a script that searches files for SSI and replaces the include with the actual HTML
I am developing the front end code of a website which I will be handing over to some developers for them to integrate it with the backend. The site will be written in .NET but I'm developing the front ...