Is there a shorter way to require a file located in the same directory (as the script being executed)?
require File.expand_path(File.dirname(__FILE__) + '/some_other_script')
I read that require "my_script" and require "./my_script" will actually load the script twice (ruby will not recognize that it is actually the same script), and ...
I'm seeking the most concise way to do this
Given the following Array:
['a','b','c']
how to get this:
{'a'=> 1,'b'=> 2, 'c'=> 3}
and
[['a',1],['b',2],['c',3]]
I have few solutions at mind, just want to see yours :)
...
Given this form (which contains a submit button):
<form id="review_form">
<input type="submit" id="btn_submit" value="Submit with ajax! (submit button)">
</form>
and this link (to submit the same form):
<a href="#" id="lnk_submit">Submit with ajax! (hyperlink)</a>
In the following jQuery code, when the #btn_submit element is clic...
[for those not following along at home, this is the sequel to Rolling My Own Version Control ;)]
So i gave in and installed TortoiseSVN (to work with a friend on a project, my personal version control is alive, well, and working as i want it). Having never seriously used one of these before, can someone give me (a link to a) concise exp...
I have a method that returns the past x days and it currently does the following:
var dates = new List<DateTime>();
for (int i = 0; i < numDays; i++)
{
dates.Add(DateTime.Today.AddDays(-i));
}
return dates;
I feel like there should be a more compact way of doing this, perhaps using LINQ. Suggestions? Also, if I do keep it the ...
In python, one can use printf like formatting with the "%" operator:
"i am %d years old" % 99
or
"%s is %d years old" % ("bob", 101)
Is there a way to get the same concise syntax in Ocaml, for arbitrary numbers of arguments?
For a single argument, the following works:
let (%) = Printf.sprintf in ... "i am %d years old" % 99
Is ...
Is there a more syntactically concise way of writing the following?
gen = (i for i in xrange(10))
index = 5
for i, v in enumerate(gen):
if i is index:
return v
It seems almost natural that a generator should have a gen[index] expression, that acts as a list, but is functionally identical to the above code.
...
How can I write this code more cleanly/concisely?
/// <summary>
/// Creates a set of valid URIs.
/// </summary>
/// <param name="levelVariantURIDicts">A collection of dictionaries of the form:
/// dict["filePath"] == theFilePath </param>
/// <returns></returns>
private ICol...
A fairly basic problem for a change. Given a class such as this:
public class X
{
public T A;
public T B;
public T C;
...
// (other fields, properties, and methods are not of interest here)
}
I am looking for a concise way to code a method that will return all A, B, C, ... that are not null in an enumerable collec...
To make my code more concise, can I do something like
int f(int const x, y, z), g(int const x, y, z);
to declare functions f and g which each take three int const arguments?
Edit:
Perhaps here is a better example:
int f(int const a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z);
How would that not be m...
If you have a boolean variable:
boolean myBool = true;
I could get the inverse of this with an if/else clause:
if (myBool == true)
myBool = false;
else
myBool = true;
Is there a more concise way to do this?
...