This question already has answers here:
Is there a reason that we cannot iterate on "reverse Range" in ruby?
(12 answers)
Closed 7 years ago.
options_for_select(1920..2015)
Howa can get this range in reverse type, 2015..1920 doesn't work,
I think my question is pretty understandable, but this form wants me to write more, so excuse me)))Please help
This produces the options in reverse order:
options_for_select((1920..2015).to_a.reverse)
=> "<option value=\"2015\">2015</option>\n<option value=\"2014\">2014</option>\n<option value=\"2013\">2013</option>\n<option value=\"2012\">2012</option>\n<option value=\"2011\">2011</option>\n<option value=\"2010\">2010</option>\n<option value=\"2009\">2009</option>\n<option value=\"2008\">2008</option>\n<option value=\"2007\">2007</option>\n<option value=\"2006\">2006</option>\n<option value=\"2005\">2005</option>\n<option value=\"2004\">2004</option>\n<option value=\"2003\">2003</option>\n<option value=\"2002\">2002</option>\n<option value=\"2001\">2001</option>\n<option value=\"2000\">2000</option>\n<option value=\"1999\">1999</option>\n<option value=\"1998\">1998</option>\n<option value=\"1997\">1997</option>\n<option value=\"1996\">1996</option>\n<option value=\"1995\">1995</option>\n<option value=\"1994\">1994</option>\n<option value=\"1993\">1993</option>\n<option value=\"1992\">1992</option>\n<option value=\"1991\">1991</option>\n<option value=\"1990\">1990</option>\n<option value=\"1989\">1989</option>\n<option value=\"1988\">1988</option>\n<option value=\"1987\">1987</option>\n<option value=\"1986\">1986</option>\n<option value=\"1985\">1985</option>\n<option value=\"1984\">1984</option>\n<option value=\"1983\">1983</option>\n<option value=\"1982\">1982</option>\n<option value=\"1981\">1981</option>\n<option value=\"1980\">1980</option>\n<option value=\"1979\">1979</option>\n<option value=\"1978\">1978</option>\n<option value=\"1977\">1977</option>\n<option value=\"1976\">1976</option>\n<option value=\"1975\">1975</option>\n<option value=\"1974\">1974</option>\n<option value=\"1973\">1973</option>\n<option value=\"1972\">1972</option>\n<option value=\"1971\">1971</option>\n<option value=\"1970\">1970</option>\n<option value=\"1969\">1969</option>\n<option value=\"1968\">1968</option>\n<option value=\"1967\">1967</option>\n<option value=\"1966\">1966</option>\n<option value=\"1965\">1965</option>\n<option value=\"1964\">1964</option>\n<option value=\"1963\">1963</option>\n<option value=\"1962\">1962</option>\n<option value=\"1961\">1961</option>\n<option value=\"1960\">1960</option>\n<option value=\"1959\">1959</option>\n<option value=\"1958\">1958</option>\n<option value=\"1957\">1957</option>\n<option value=\"1956\">1956</option>\n<option value=\"1955\">1955</option>\n<option value=\"1954\">1954</option>\n<option value=\"1953\">1953</option>\n<option value=\"1952\">1952</option>\n<option value=\"1951\">1951</option>\n<option value=\"1950\">1950</option>\n<option value=\"1949\">1949</option>\n<option value=\"1948\">1948</option>\n<option value=\"1947\">1947</option>\n<option value=\"1946\">1946</option>\n<option value=\"1945\">1945</option>\n<option value=\"1944\">1944</option>\n<option value=\"1943\">1943</option>\n<option value=\"1942\">1942</option>\n<option value=\"1941\">1941</option>\n<option value=\"1940\">1940</option>\n<option value=\"1939\">1939</option>\n<option value=\"1938\">1938</option>\n<option value=\"1937\">1937</option>\n<option value=\"1936\">1936</option>\n<option value=\"1935\">1935</option>\n<option value=\"1934\">1934</option>\n<option value=\"1933\">1933</option>\n<option value=\"1932\">1932</option>\n<option value=\"1931\">1931</option>\n<option value=\"1930\">1930</option>\n<option value=\"1929\">1929</option>\n<option value=\"1928\">1928</option>\n<option value=\"1927\">1927</option>\n<option value=\"1926\">1926</option>\n<option value=\"1925\">1925</option>\n<option value=\"1924\">1924</option>\n<option value=\"1923\">1923</option>\n<option value=\"1922\">1922</option>\n<option value=\"1921\">1921</option>\n<option value=\"1920\">1920</option>"
Reversing a range doesn't really make sense. You could use options_for_select(2015.downto(1920)), as downto returns an Enumerator which is a valid parameter for options_for_select.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a(nother) string of lua code that's obfuscated. I'm wondering if it's possible to deobfuscate it, or to figure out how it was obfuscated, as I've never encountered anything like it before. This string of code is supposedly the main module for a malicious serverside script executor. Knowing what's inside will help us patch the exploit on our platform. I'm told that it would be easy to decipher by getting the constants, because it's VM based obfuscation, we just need a bit of help getting pointed in the right direction.
The code is rather large, so it's in this pastebin.
pastebin com/dtfzBPZk
Deobfuscating this one looks like it will be a slightly more manual process. As usual, the first things you should do are rename variables to have saner names, and add whitespace and indentation to the code. You can see a start to this at https://pastebin.com/eRTGAbTH. Once you do that, you'll see a pattern of functions like this:
(function(...)
local SynapseXen_116 = "hi xen doesn't work on sk8r please help"
local SynapseXen_092 = SynapseXen_100(38909278, 3932326132)
local SynapseXen_069 = {...}
for SynapseXen_109, SynapseXen_043 in pairs(
SynapseXen_069
) do
local SynapseXen_119
local SynapseXen_097 = type(SynapseXen_043)
if SynapseXen_097 == "number" then
SynapseXen_119 = SynapseXen_043
elseif SynapseXen_097 == "string" then
SynapseXen_119 = SynapseXen_043:len()
elseif SynapseXen_097 == "table" then
SynapseXen_119 = SynapseXen_100(4264903821, 30110892)
end
SynapseXen_092 = SynapseXen_092 + SynapseXen_119
end
SynapseXen_140[1171393165] =
SynapseXen_bit_bxor(
SynapseXen_bit_bxor(2179831066, SynapseXen_092),
SynapseXen_bit_bxor(2132161653, SynapseXen_082)
) -
string.len(SynapseXen_116) -
SynapseXen_139 -
#{
2716917292,
2960928816,
2092744992,
3945961999,
2156388474,
2523828292,
534526172
}
return SynapseXen_140[1171393165]
end)({}, {}, 14275, 107, "iIIllIIlIIilillilI", "i", 5327, 3211, 14382, 14643)
Now you can start to eliminate red herrings. For example, any time you see #{ a bunch of stuff in here }, you can just count the elements in the list, and replace the whole thing with the count. In this case, there's one of those near the end we can replace with the number 7. Next, look at SynapseXen_116. The only place it's used is for its length, so you can substitute that in as well. Now, After that, notice that this is declaring a function and then immediately invoking it, so you can substitute in its arguments. Continue going down that path until you uncover the heart of the Lua-in-Lua VM, and from there, it should be easy to plug in the Base64 at the end, and see what bytecode it decodes to.
This question already has answers here:
ruby using the "&:methodname" shortcut from array.map(&:methodname) for hash key strings rather than methodname
(3 answers)
Closed 3 years ago.
I have a rails app that does a lot of JSON parsing (ie using strings as keys rather than symbols).
I have the following code:
ad_source_ids = []
logged_one['migrated'].each { |mig| ad_source_ids << mig['id'] }
I'd like to do
ad_source_ids = logged_one['migrated'].map(&:id)
but don't think I can. What is an alternative? I'd like to removed the ad_source_ids tmp variable.
You're almost there. Try this:
ad_source_ids = logged_one['migrated'].collect { |mig| mig['id'] }
This question already has answers here:
HAML - what does the "!=" operator do?
(3 answers)
Closed 4 years ago.
I discovered the following statement in a haml template:
!= render partial: 'path/to/partial'
What is the purpose of != in this context?
It is used for Unescaping HTML.
example:
= "<Hello>" will give <g;Hello>
but now using
!= "<Hello>" will give <Hello>
This question already has an answer here:
iOS Swift Multiple dimension arrays - compiliing takes ages. What should I change?
(1 answer)
Closed 7 years ago.
I am trying to implement an array that contains multiple arrays of Integers (well, LOTS of Integers) like this...
let arrayOfRanges = [Array(0 ... 299), Array(300 ... 399), Array(400 ... 699), Array(700 ... 799), Array(800 ... 899), Array(900 ... 1199)]
but every time I type it into Xcode, Xcode hangs on indexing. I've searched and found a few older cases of people with a similar problem with Arrays and it seems to be related to Xcode having difficult inferring the type. Swift Array causing indexing issues in Xcode 6.1.1 Does anybody have any ideas as to how I can better code this? I would like...
//Sets magicNumber to the Int 411
let arrayOfRanges = [Array(0 ... 299), Array(300 ... 399), Array(400 ... 699), Array(700 ... 799), Array(800 ... 899), Array(900 ... 1199)]
magicNumber = arrayOfRanges[2][11]
Thanks for your help!
Declare your variable as an array of arrays of Int
let arrayOfRanges: [[Int]] = [Array(0 ... 299), Array(300 ... 399), Array(400 ... 699), Array(700 ... 799), Array(800 ... 899), Array(900 ... 1199)]
let magicNumber = arrayOfRanges[2][11]
There isn’t anything wrong with the posted code except that you haven’t defined magicNumber. Also
magicNumber = arrayOfRanges[2][11]
will be 411 and not 410. Refer to the attached screenshot from playground.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I want to know what will be the best way for a char-char conversion.
I will create some data for the conversion for example teh letter "A" will be converted to "C" and so on.
Shall I use a MySQL DB or files or what?
Note: The application will be a web app and most likely be running ASP or PHP.
EDIT:
I want to create a website or a desktop app that will allow user who work on PCs that only support one language to be able to use any other language something like a translator, yet it is not a translator.
For example, arabic users cannot use the AR keyboard due to system restrictions, I want to help them write in the language without installing the language pack. I`m facing this problem myself, and can`t install language pack without admin access.
I can`t provide output at the moment as the PC I`m using doesn`t support AR.
I guess you mean character / keyboard mapping (or an Input Method Editor as Ignacio Vazquez-Abrams said)...
In this case, create static hash maps / associative arrays that map keys to characters or strings.
That said, however, I think there are some keyboard mapping tools out there that hook into the operating system and can be customized to one's needs.
What about JavaScript?
Here's a simple code for converting the infamous YZ keys to ZY (QWERTY <-> QWERTZ).
<textarea id="txt"></textarea>
<script language="JavaScript" type="text/JavaScript">
document.getElementById("txt").onkeydown = InputKeyDown;
function InputKeyDown(event) {
var shift = event.shiftKey;
var keyCode = (event.which == null) ? event.keyCode : event.which;
//alert(String.fromCharCode(keyCode) + "\\n" + keyCode); return false;
switch (keyCode) {
case 89 /* Y */: InsertAtCursor(event.target, shift ? 'Z' : 'z'); return false;
case 90 /* Z */: InsertAtCursor(event.target, shift ? 'Y' : 'y'); return false;
default: return true;
}
}
</script>
I think you could start something with this. You can also use the event.ctrlKey or event.altKey flags for more complex languages.