camelcasing

have jQuery ignore case in attribute/data names?

好久不见. 提交于 2019-11-30 08:52:53
We're using HTML5's data-* attributes for some of our client side interaction set up. jQuery uses these to do its thing. The catch is that the HTML coming in may vary. Obviously this is the problem that should be fixed but I'm not always in control of the HTML being produced, unfortunately. The question: Given these two tags: <a data-sampleAttributeName="example"> <a data-sampleattributename="example"> Is there a clever way to treat them as one and the same? The best I've come up with is something like this: var theAttribute = ($myobject).data('sampleAttributeName'); if (($myobject).data(

Converting nested hash keys from CamelCase to snake_case in Ruby

大憨熊 提交于 2019-11-30 08:09:43
I'm trying to build an API wrapper gem, and having issues with converting hash keys to a more Rubyish format from the JSON the API returns. The JSON contains multiple layers of nesting, both Hashes and Arrays. What I want to do is to recursively convert all keys to snake_case for easier use. Here's what I've got so far: def convert_hash_keys(value) return value if (not value.is_a?(Array) and not value.is_a?(Hash)) result = value.inject({}) do |new, (key, value)| new[to_snake_case(key.to_s).to_sym] = convert_hash_keys(value) new end result end The above calls this method to convert strings to

camel case method names

我的未来我决定 提交于 2019-11-30 03:03:07
问题 I understand the reason to camel case variable names, but I've always wondered why you would camel case a method name? why is it toString() and not ToString()? What purpose does it serve? 回答1: A lot of conventions say you capitalize the first letter of types (classes, structs, enums, etc.), and use lowercase otherwise (functions, members, etc.). If you follow that convention, you can then tell just by looking that MyStruct.MyType refers to a nested type, and MyStruct.myData refers to some

Default camel case of property names in JSON serialization

一世执手 提交于 2019-11-30 02:56:46
I have a bunch of classes that will be serialized to JSON at some point and for the sake of following both C# conventions on the back-end and JavaScript conventions on the front-end, I've been defining properties like this: [JsonProperty(PropertyName="myFoo")] public int MyFoo { get; set; } So that in C# I can: MyFoo = 10; And in Javascript I can: if (myFoo === 10) But doing this for every property is tedious. Is there a quick and easy way to set the default way JSON.Net handles property names so it will automatically camel case unless told otherwise? You can use the provided class Newtonsoft

camelCase to dash - two capitals next to each other

二次信任 提交于 2019-11-30 02:52:42
问题 I'm using this function to convert CamelCase to dashed string: function camel2dashed($className) { return strtolower(preg_replace('/([^A-Z-])([A-Z])/', '$1-$2', $className)); } it kinda works but theres problem when I have for ex. this string: getADog . It returns get-adog but I want get-a-dog how should I change my code? Thanks 回答1: Use a lookahead assertion: function camel2dashed($className) { return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $className)); } See it working

Why True/False is capitalized in Python?

吃可爱长大的小学妹 提交于 2019-11-30 01:10:24
All members are camel case, right? Why True/False but not true/false, which is more relaxed? James Sulak From Pep 285 : Should the constants be called 'True' and 'False' (similar to None) or 'true' and 'false' (as in C++, Java and C99)? => True and False. Most reviewers agree that consistency within Python is more important than consistency with other languages. This, as Andrew points out, is probably because all (most)? built-in constants are capitalized . All of python's built-in constants are capitalized or [upper] CamelCase: Here's a possible explaination : I see that naming conventions

Acronyms in Camel Back

一笑奈何 提交于 2019-11-29 22:53:20
I often see Java class names like XmlReader instead of XMLReader My gut feeling is to completely upper case acronyms, but apparently many people think differently. Or maybe it's just because a lot of code generators are having trouble with acronyms... So i would like to hear the the public opinion. How do you capitalize your class names containing acronyms? We use the camel case convention like Java and .NET do. Not for reasons of code generators, but for readability. Consider the case of combining two acronyms in one name, for example a class that converts XML into HTML. XMLHTMLConverter or

Javascript/jQuery: Split camelcase string and add hyphen rather than space

徘徊边缘 提交于 2019-11-29 20:44:47
I would imagine this is a multiple part situation with regex, but how would you split a camelcase string at the capital letters turning them in to lowercase letters, and then adding a hyphen between each new string? For example: thisString would become: this-string Wouter J Try something like: var myStr = 'thisString'; myStr = myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); Late to answer, but this solution will work for cases where a single letter is camel cased. 'thisIsATest'.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase(); // this-is-a-test Try the following: var token =

Splitting CamelCase in R

北慕城南 提交于 2019-11-29 17:57:50
问题 Is there a way to split camel case strings in R? I have attempted: string.to.split = "thisIsSomeCamelCase" unlist(strsplit(string.to.split, split="[A-Z]") ) # [1] "this" "s" "ome" "amel" "ase" 回答1: string.to.split = "thisIsSomeCamelCase" gsub("([A-Z])", " \\1", string.to.split) # [1] "this Is Some Camel Case" strsplit(gsub("([A-Z])", " \\1", string.to.split), " ") # [[1]] # [1] "this" "Is" "Some" "Camel" "Case" Looking at Ramnath's and mine I can say that my initial impression that this was

MVC JsonResult camelCase serialization [duplicate]

别来无恙 提交于 2019-11-29 15:59:45
问题 This question already has an answer here: Proper JSON serialization in MVC 4 3 answers I am trying to make my action return a JsonResult where all its properties are in camelCase. I have a simply model: public class MyModel { public int SomeInteger { get; set; } public string SomeString { get; set; } } And a simple controller action: public JsonResult Index() { MyModel model = new MyModel(); model.SomeInteger = 1; model.SomeString = "SomeString"; return Json(model, JsonRequestBehavior