|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On May 23 2014 00:55 Manit0u wrote:I need some help with JS. I'm designing a custom rating widget because all of the available jQuery plugins either don't meet the specs or are under shitty license. Code (mixed with pseudocode): <div class="x"> // ----- before <span class="y" onclick="func(this)"></span> <span class="y" onclick="func(this)"></span> // ----- here we call func (for example) <span class="y" onclick="func(this)"></span> // ----- after <span class="y" onclick="func(this)"></span> <span class="y" onclick="func(this)"></span> </div>
<script> function func(elem) { if (!elem.hasClass("z")) { elem.addClass("z"); }
$var belems = elements before called element; $var aelems = elements after called element;
for belems as elem { if (elem.hasClass("z")) { elem.removeClass("z"); } } for aelems as elem { if (!elem.hasClass("z")) { elem.addClass("z") } } } </script>
The problem I'm facing is actually getting the required elements. <div> "x" is not unique on the page (there are many of them), neither are its children ("y") but I must find specific y's in specific x... With getElementById it would be piss simple, like this it's not and unfortunately I can't give unique id to the x divs (very ugly). Any help?
Something like that?
http://jsfiddle.net/hJZZK/
|
On May 23 2014 04:58 darkness wrote: So in this case, [[Bisu, Nada]] U [[Nada -> 3]] is kind of like [[Bisu, Nada]] ⊕ {Nada -> 3}? In your original case, S U {Nada -> 3} = S ⊕ {Nada -> 3} because S doesn't contain Nada, I think. When S contains Nada it's different, because you keep the max of their multiplicity for the union (contrary to the sum of their multiplicity for the multiset sum).
|
On May 23 2014 06:10 Encdalf wrote:Show nested quote +On May 23 2014 00:55 Manit0u wrote:I need some help with JS. I'm designing a custom rating widget because all of the available jQuery plugins either don't meet the specs or are under shitty license. Code (mixed with pseudocode): <div class="x"> // ----- before <span class="y" onclick="func(this)"></span> <span class="y" onclick="func(this)"></span> // ----- here we call func (for example) <span class="y" onclick="func(this)"></span> // ----- after <span class="y" onclick="func(this)"></span> <span class="y" onclick="func(this)"></span> </div>
<script> function func(elem) { if (!elem.hasClass("z")) { elem.addClass("z"); }
$var belems = elements before called element; $var aelems = elements after called element;
for belems as elem { if (elem.hasClass("z")) { elem.removeClass("z"); } } for aelems as elem { if (!elem.hasClass("z")) { elem.addClass("z") } } } </script>
The problem I'm facing is actually getting the required elements. <div> "x" is not unique on the page (there are many of them), neither are its children ("y") but I must find specific y's in specific x... With getElementById it would be piss simple, like this it's not and unfortunately I can't give unique id to the x divs (very ugly). Any help? Something like that? http://jsfiddle.net/hJZZK/
Exactly, thanks.
Another question then... Is there a way to make "rated" have different color on hover? (preferably through css alone)
http://jsfiddle.net/ks3H9/3/
|
On May 23 2014 15:19 Manit0u wrote:Show nested quote +On May 23 2014 06:10 Encdalf wrote:On May 23 2014 00:55 Manit0u wrote:I need some help with JS. I'm designing a custom rating widget because all of the available jQuery plugins either don't meet the specs or are under shitty license. Code (mixed with pseudocode): <div class="x"> // ----- before <span class="y" onclick="func(this)"></span> <span class="y" onclick="func(this)"></span> // ----- here we call func (for example) <span class="y" onclick="func(this)"></span> // ----- after <span class="y" onclick="func(this)"></span> <span class="y" onclick="func(this)"></span> </div>
<script> function func(elem) { if (!elem.hasClass("z")) { elem.addClass("z"); }
$var belems = elements before called element; $var aelems = elements after called element;
for belems as elem { if (elem.hasClass("z")) { elem.removeClass("z"); } } for aelems as elem { if (!elem.hasClass("z")) { elem.addClass("z") } } } </script>
The problem I'm facing is actually getting the required elements. <div> "x" is not unique on the page (there are many of them), neither are its children ("y") but I must find specific y's in specific x... With getElementById it would be piss simple, like this it's not and unfortunately I can't give unique id to the x divs (very ugly). Any help? Something like that? http://jsfiddle.net/hJZZK/ Exactly, thanks. Another question then... Is there a way to make "rated" have different color on hover? (preferably through css alone) http://jsfiddle.net/ks3H9/3/
not sure what you think of exactly, but.. http://jsfiddle.net/ks3H9/7/
|
In C#, if I want to create a dictionary that maps Strings to Funcs that return one type but have one parameter of different objects, why can't I just specify the argument as an Object?
i.e. I have
var dictionary = new Dictionary<String, Func<ParameterType, ResultType>>(); ... public ResultType foo(ParameterType param) { ... } ... dictionary.Add("foo", foo); // this works
/* ------ */ var dictionary = new Dictionary<String, Func<ParameterType, object>>(); ... public ResultType foo(ParameterType param) { ... } ... dictionary.Add("foo", foo); // this doesn't work
I find it a little bit inconvenient :/
|
Damn my C# is rusty as hell, but is Delegate the answer you're looking for?
|
On May 24 2014 11:13 Blisse wrote:In C#, if I want to create a dictionary that maps Strings to Funcs that return one type but have one parameter of different objects, why can't I just specify the argument as an Object? i.e. I have var dictionary = new Dictionary<String, Func<ParameterType, ResultType>>(); ... public ResultType foo(ParameterType param) { ... } ... dictionary.Add("foo", foo); // this works
/* ------ */ var dictionary = new Dictionary<String, Func<ParameterType, object>>(); ... public ResultType foo(ParameterType param) { ... } ... dictionary.Add("foo", foo); // this doesn't work
I find it a little bit inconvenient :/
This might be why, if your ResultType is a value type: http://stackoverflow.com/questions/9688268/why-cannot-ienumerablestruct-be-cast-as-ienumerableobject
|
On May 24 2014 11:13 Blisse wrote: In C#, if I want to create a dictionary that maps Strings to Funcs that return one type but have one parameter of different objects, why can't I just specify the argument as an Object?
...
I find it a little bit inconvenient :/ Didn't care to think your code through in detail, but it's most likely an issue of covariance/contravariance: http://msdn.microsoft.com/en-us/library/dd799517(v=vs.110).aspx
Basically you can only assign a Func type to another Func type with more derived generic arguments. It actually makes sense too, once you wrap your head around it.
I've had to deal with this problem recently. When you want to cast a Func to a less derived type, you need to "manually" do the cast like so:
Func<object, object> CastFunc(Func<int, string> f) { return a => (object) f ((int) a); }
Of course you then need to make sure that you only ever call the resulting func with the appropriate arguments.
Then again it is early in the morning and this might not be the case for the return type of Func...
|
Does anyone know if there is a way for a SyncAdapter to get the date_last_modified of an event from the Android Calendar Provider?
|
On May 24 2014 16:24 urboss wrote: Does anyone know if there is a way for a SyncAdapter to get the date_last_modified of an event from the Android Calendar Provider?
Are you the one asking the questions on stack overflow? It doesn't appear according to their api that such a field exists (in a 5 minute scan)
Even though it feels a little funny, you might consider using their http API for calendars. At least that api shows the updated date as a response, unlike the calendar provider.
https://developers.google.com/google-apps/calendar/v3/reference/events/list
Does anyone have experience with android and wifi roaming with multiple access points with the same ssid, different bssids, and different channels/frequencies? It feels really weird that android seems to have issues with this.
|
Thanks, I need to use the calendar provider for my own calendar, not Google Calendar. The way sync is seemingly supposed to work is that there is a DIRTY flag and a DELETED flag instead of a date_last_modified. The DIRTY flag works, but if I delete an appointment, it gets deleted without the DELETED flag ever being set.
Edit: Problem solved: You need to set a _SYNC_ID, otherwise the DELETED flag is not set. Great documentation as always, that is to say "none".
I don't know anything about wifi roaming unfortunately.
|
On May 24 2014 11:13 Blisse wrote:In C#, if I want to create a dictionary that maps Strings to Funcs that return one type but have one parameter of different objects, why can't I just specify the argument as an Object? i.e. I have var dictionary = new Dictionary<String, Func<ParameterType, ResultType>>(); ... public ResultType foo(ParameterType param) { ... } ... dictionary.Add("foo", foo); // this works
/* ------ */ var dictionary = new Dictionary<String, Func<ParameterType, object>>(); ... public ResultType foo(ParameterType param) { ... } ... dictionary.Add("foo", foo); // this doesn't work
I find it a little bit inconvenient :/ Please don't do this. I don't know why you would ever design something like this. This is extremely difficult to maintain, debug and test. Please refactor it.
|
I agree, but I dont have a good grasp on exactly how I should design my architecture.
Basically I parse string input into objects via a json-rpc implementation. The objects tell me exactly what to transform the object contents into via string commands because they can be arbitrary, so i map the string commands to the transforming function like i've described above. it works but i am running into a few limitations.
i want to avoid cascading if-else or switch statements, but if you can convince me that a switch is the way to go, i'm open to that
|
On May 27 2014 14:41 Blisse wrote:I agree, but I dont have a good grasp on exactly how I should design my architecture. Basically I parse string input into objects via a json-rpc implementation. The objects tell me exactly what to transform the object contents into via string commands because they can be arbitrary, so i map the string commands to the transforming function like i've described above. it works but i am running into a few limitations. i want to avoid cascading if-else or switch statements, but if you can convince me that a switch is the way to go, i'm open to that 
Not really sure what you are trying to do but it would make it a lot easier if you submitted the whole code with an explanation. Although right now this looks like a suboptimal implementation, regardless of what the code is supposed to do. 
For the parameter type thing you might wanna look into the double-dispatch pattern, again without seeing the implementation I'm not sure how you are going about this and whether this is appropriate. Also the strategy pattern might be useful, for the string/function mapping part of it.
What is the purpose of mapping strings into funcs? Maybe that will make it easier to understand.
|
can't really post code (not allowed) so i'll try to explain it
basically trying to emulate the dispatching in a switch rather than using a long if statement. the input isn't user defined, but selected from a known dictionary, and the input is runtime dependent.
imagine in a commandline program you could type PULL to call a pullFunction and PUSH to call a pushFunction, while passing in arbitrary container objects. the function could then take the container object and because you called that exact function, cast the contents inside the container object to the proper type. so pullFunction(Container container) will have a method like var pullObject = container.Contents as pullObject. it then passed this object to another library and returns a variable container object with the results of that library call and the description of what the container contains.
i simplified things a bit, there is a lot more logic inbetween and 10-20 different inputs that should be handled. i could always just write an if-statement too, i don't have a specific reason between the two except that this runs faster and the mapping between "PULL" and "pullFunction" is enforced a bit more strictly and visually.
|
On May 27 2014 16:29 Blisse wrote: can't really post code (not allowed) so i'll try to explain it
basically trying to emulate the dispatching in a switch rather than using a long if statement. the input isn't user defined, but selected from a known dictionary, and the input is runtime dependent.
imagine in a commandline program you could type PULL to call a pullFunction and PUSH to call a pushFunction, while passing in arbitrary container objects. the function could then take the container object and because you called that exact function, cast the contents inside the container object to the proper type. so pullFunction(Container container) will have a method like var pullObject = container.Contents as pullObject. it then passed this object to another library and returns a variable container object with the results of that library call and the description of what the container contains.
i simplified things a bit, there is a lot more logic inbetween and 10-20 different inputs that should be handled. i could always just write an if-statement too, i don't have a specific reason between the two except that this runs faster and the mapping between "PULL" and "pullFunction" is enforced a bit more strictly and visually.
Ok, I now understand the method, but without knowing why and for what purpose it makes it a bit difficult. For example, it sounds like what you really want to do is write a DSL, there are lots of ways of doing this including creating a parser grammar + interpreter which may be the best way, again with this little information there is no way of knowing what's best. Let's stick with pure C# for now.
There is probably also no need to pass in a container and return a container object with descriptions of what the container contains. You can just use JSON, an anonymous object or models, have a look at how ODM works. Though it would be best to try to limit the functionality to not return anything except true/false, this should be entirely possible if you design it correctly. Behaviour on the models should be run on the models itself, having to pass objects in and out is usually sign of a "code smell".
C# is not the best language for this because of lack of Metaprogramming features, but again without knowing why I can't really say much else.
So the best answer I can come up is that what you really need to research on is Metaprogramming in C#. I know features like Reflection is available in C#, maybe through the use of a statement like "eval".
The simplest way I can think of is, to call a method at runtime with an anonymous (infinite) number of parameters. This method dynamically calls methods at runtime using "eval" or stricter reflection method (preferred). The methods able to be called should be able to be declared normally in your code, it is self contained within its own class. Or you could emulate something like "method_missing" in order to return control to the dispatcher and iterate through multiple objects.
The dispatcher then calls the method with the string, without use of a dictionary. Runtime errors should occur when the method signature does not match (e.g too many parameters).
No switch statements or dictionary necessary.
|
How would one go about writing a program to print a document either from Microsoft Word 2013, or from a google doc once every 12 seconds until X copies have been printed? I don't know if this is actually at all possible but if it is, I would love to learn how.
|
On May 28 2014 00:35 3FFA wrote: How would one go about writing a program to print a document either from Microsoft Word 2013, or from a google doc once every 12 seconds until X copies have been printed? I don't know if this is actually at all possible but if it is, I would love to learn how.
Auto Hotkey. Make a macro. Don't do evil!
|
On May 27 2014 16:29 Blisse wrote: can't really post code (not allowed) so i'll try to explain it
basically trying to emulate the dispatching in a switch rather than using a long if statement. the input isn't user defined, but selected from a known dictionary, and the input is runtime dependent.
imagine in a commandline program you could type PULL to call a pullFunction and PUSH to call a pushFunction, while passing in arbitrary container objects. the function could then take the container object and because you called that exact function, cast the contents inside the container object to the proper type. so pullFunction(Container container) will have a method like var pullObject = container.Contents as pullObject. it then passed this object to another library and returns a variable container object with the results of that library call and the description of what the container contains.
i simplified things a bit, there is a lot more logic inbetween and 10-20 different inputs that should be handled. i could always just write an if-statement too, i don't have a specific reason between the two except that this runs faster and the mapping between "PULL" and "pullFunction" is enforced a bit more strictly and visually. So, what I get from this: 1. The functions that are available to the users are known to your program 2. Each function has one argument 3. The return value of each function is known and can be generalized (that is, made the same for all functions)
Design an interface, create classes for each function that implement said interface, and create a factory class that creates the function classes.
For example:
internal interface IFunction { string Execute(object parameter); }
internal sealed class PullFunction : IFunction { public string Execute(object parameter) { MyCustomClassForThisFunction c = parameter as MyCustomClassForThisFunction; if(c == null) return string.Empty;
// do stuff // return result } }
internal interface IFunctionFactory { IFunction Create(string functionName); }
internal sealed class FunctionFactory : IFunctionFactory { public IFunction Create(string functionName) { switch(functionName.ToUpper()) { case "PULL": return new PullFunction(); default: throw new NotImlementedException(); } } }
// In your command handling code, find a way to inject the factory via constructor injection private readonly IFunctionFactory functionFactory; return this.functionFactory.Create("pull").Execute(arbitraryContainerObject);
Now you can get cutesy and still have a dictionary mapping a function name to a type in the Factory, without altering the rest of your code:
private readonly IDictionary<string, Type> functionMapping = new Dictionary<string, Type> { new KeyValuePair<string, Type>("PULL", typeof(PullFunction)) }
// In Create method // be sure to check if the key exists etc. return Activator.CreateInstance(this.functionMapping[functionName.ToUpper()]);
Sidenote: I've been making more factories lately and have become a fan
|
On May 28 2014 00:49 bangsholt wrote:Show nested quote +On May 28 2014 00:35 3FFA wrote: How would one go about writing a program to print a document either from Microsoft Word 2013, or from a google doc once every 12 seconds until X copies have been printed? I don't know if this is actually at all possible but if it is, I would love to learn how. Auto Hotkey. Make a macro. Don't do evil! Actually not meant to do evil lol. K time to google how to do this sort of thing…
|
|
|
|
|
|