wrapper

How to safely wrap `console.log`?

强颜欢笑 提交于 2019-12-31 08:43:22
问题 Suppose I want to include some calls to console.log for some legitimate production reason, say for something like a unit test harness. Obviously I would not want this to throw a premature exception if the browser doesn't have a console , or if no console is present. What's the best way to create a simple log function to log stuff to the console, or silently fail without error if no console is present? The accepted answer to the question linked above: var log = Function.prototype.bind.call

How to safely wrap `console.log`?

吃可爱长大的小学妹 提交于 2019-12-31 08:43:10
问题 Suppose I want to include some calls to console.log for some legitimate production reason, say for something like a unit test harness. Obviously I would not want this to throw a premature exception if the browser doesn't have a console , or if no console is present. What's the best way to create a simple log function to log stuff to the console, or silently fail without error if no console is present? The accepted answer to the question linked above: var log = Function.prototype.bind.call

Writing a synchronized thread-safety wrapper for NavigableMap

倖福魔咒の 提交于 2019-12-31 02:57:09
问题 java.util.Collections currently provide the following utility methods for creating synchronized wrapper for various collection interfaces: synchronizedCollection(Collection<T> c) synchronizedList(List<T> list) synchronizedMap(Map<K,V> m) synchronizedSet(Set<T> s) synchronizedSortedMap(SortedMap<K,V> m) synchronizedSortedSet(SortedSet<T> s) Analogously, it also has 6 unmodifiedXXX overloads. The glaring omission here are the utility methods for NavigableMap<K,V>. It's true that it extends

C# deezer native api: adapting to C#

社会主义新天地 提交于 2019-12-30 14:18:11
问题 I'm trying to use a C# class that wraps C++ native api into CLI C# class. It seems that there are some problems (it really near to be working) and would like some help to find the problem. Here is the wrapper's code using System; using System.Collections; using System.Runtime.InteropServices; // make this binding dependent on WPF, but easier to use using System.Windows.Threading; // http://www.codeproject.com/Articles/339290/PInvoke-pointer-safety-Replacing-IntPtr-with-unsaf namespace Deezer

Should the EnumDataTypeAttribute work correctly in .NET 4.0 using Entity Framework?

时光怂恿深爱的人放手 提交于 2019-12-30 07:24:22
问题 I have an enumeration which I'd like to persist as a value of some sort into the underlying database so that I can bring it back and forth. I have read some articles that suggest to create a enumeration wrapper with static implicit operators defined, mapped using a ComplexType object mapping as described in the link below. How to fake Enums in EF4 This solution works flawlessly! My thanks to Alex James. Aside, I discovered of the EnumDataTypeAttribute Class which purpose seems to handle enums

Making decorators with optional arguments [duplicate]

Deadly 提交于 2019-12-29 10:13:07
问题 This question already has answers here : How to create a Python decorator that can be used either with or without parameters? (11 answers) Closed 4 months ago . from functools import wraps def foo_register(method_name=None): """Does stuff.""" def decorator(method): if method_name is None: method.gw_method = method.__name__ else: method.gw_method = method_name @wraps(method) def wrapper(*args, **kwargs): method(*args, **kwargs) return wrapper return decorator Example: The following decorates

How to wrap existing function in C

夙愿已清 提交于 2019-12-29 07:48:07
问题 I am trying to wrap existing function. below code is perfectly worked. #include<stdio.h> int __real_main(); int __wrap_main() { printf("Wrapped main\n"); return __real_main(); } int main() { printf("main\n"); return 0; } command: gcc main.c -Wl,-wrap,main output: Wrapped main main So i have changed main function with temp. my goal is to wrap temp() function. Below is the code temp.c #include<stdio.h> int temp(); int __real_temp(); int __wrap_temp() { printf("Wrapped temp\n"); return __real

Composite Stream Wrapper providing partial MemoryStream and full original Stream

放肆的年华 提交于 2019-12-29 01:38:32
问题 Does anyone know of a composite stream solution that will pre-load the first portion of a Stream in to a MemoryStream and keep the remainder as the original Stream which will be accessed when subsequent parts are required as necessary? I should imagine some wrapper class would implement the Stream interface and transparently juggle the access between the two streams depending upon which part is accessed. I'm hoping this is a solution someone may have solved before, maybe to optimize

Removing wrapper div without Jquery (raw javascript)

為{幸葍}努か 提交于 2019-12-29 01:15:22
问题 I know there is a solution with Jquery called unwrap, but I am writing "raw" JavaScript. I didn't find any solution without jQuery. I'd like to remove a div like so: <div><div id="mydiv">Important text here</div></div> After removal of "mydiv": <div>Important text here</div> What should I do, I'd like to know the theory. Thanks in advance. 回答1: shouldn't this line work document.getElementById("mydiv").outerHTML = document.getElementById("mydiv").innerHTML See this JSBin Example (inspect the

Use class member as WNDPROC/DLGPROC with or without global

て烟熏妆下的殇ゞ 提交于 2019-12-28 07:08:54
问题 I'll go ahead and give a summary to this, how can I use a dialog procedure that is a member of a class? I am creating a window wrapper class, but CreateDialogParam needs a global dialog procedure, so I tried this workaround: I have done a bit of searching on this topic. I am making a Dialog class which I am subclassing to make a CMainWnd and then instantiating that. In the Dialog class I have a member function defined as INT_PTR CALLBACK Dialog::cb_proc(HWND,UINT,WPARAM,LPARAM) . Now, I know