61阅读

HOW TO-a spark, a flint:how fire leapt to life

发布时间:2017-09-06 所属栏目:HOW TO

一 : a spark, a flint:how fire leapt to life

spark n.火花 flint n.火石 leap vi.跃向 humanity n.人类 towards prep.向 enhance vt.增强 technology n.科技 divine adj.神赐的 randomly adj.任意的 deliver vt.传送 lightning n.闪电 lava n.熔岩 log n.木柴 alight adj.点燃的 charcoal n.木炭 pot n.器皿 operation n.操作 primitive adj.原始的 society n.社会 suggest vt.表明 friction n.摩擦 peasant n.农民 drill n.钻子 v.钻(孔) hole n.洞 rotate vt.转动 brisk adj.敏捷的 palm n.手掌 process n.步骤 warp vt.弯曲 cord n.(细)绳 pull vi.拉扯 lens n.透镜 concave adj.凹的 mirror n.镜子 concentrate vt.集中 ray n.射线 percussion n.两物相撞 date n.日期 Paleolithic n.旧石器时代 chip vt.切削 technique n.技法 efficient adj.有效力的 Arctic adj.北极的
strike vt.敲击 quartz n.石英 against prep.撞 pyrite n.黄铁矿 compound n.化合物 contain vt.包含 sulphur n.硫磺 porcelain n.瓷器 bamboo n.竹子 combination n.混合 steel n.钢铁 tinder n.易燃物 remain vi.保持、残余 revolutionize vt.改革 phosphorus n.磷 isolate vt.分离 transmute vt.转变 silver n.银 impress vt.留下印象 element n.元素 combustibility n.可燃性 manufacture vt.制造、加工 device n.装置 inflammable adj.易燃的 equivalent adj.(价值)相当的 ounce n.盎司 match n.火柴 quest n.寻求 practical adj.实际的 came up 提出 candle n.蜡烛 ethereal adj.轻的 sealed adj.未知的 tube n.管子 contain vt.包含 twist n.扭曲 tip vt.置于某物顶端 self-combust 自我燃烧 hazardous adj.危险的 instantaneous adj.瞬间的 sulphuric adj.含有大量硫磺的 splints n.夹板 treat vi.处理 dip vt.浸泡
resemble vt.类似 pharmacist n.药剂师 formula n.公式 military adj.军用的 rocket n.火箭 potassium n.钾 chlorate n.氯酸盐 draw vt.提取 flod vt.折叠 patent vt.取得专利 market vt.交易 substitute vt.代替 expose vt.使暴露 fumes n.烟雾 succumb vi.屈服 necrosis n.坏死 disease n.疾病 jaw n.下颚 bone n.骨头 substance n.实质 eventually adv.最终 ban vt.禁止 toxic adj.有毒的 amorphous adj.非结晶的 exploit vt.开发 commercially adv.商业上的 compatriot n.同胞 relatively adv.相对地 ignition n.点火 lag v.落后 diamond n.钻石 properly adv.适当地、完全地 climatic adj.气候上的 condition n.条件 prevail vi.流行 claim vt.要求 pioneer vt.开辟 innovation n.创新 catch on 流行 brewery n.酿酒厂 novel adj.新奇的 hand out 派发 include vt.包含 afterglow n.晚霞
solution n.解答 prevent vt.防止 smouldering n.闷烧 blow v.风吹 waterproof adj.防水

二 : How to use Castle.DynamicProxy-2.1, part 1

PⅠ, Introduction

      最近对AOP比较感兴趣, 下载了一个.net下的AOP框架实现(Castle.DynamicProxy), 关于怎么使用, 网上大部分都是有关1.x版本的, 我们当然倾向于使用最新的2.1版本. 链接[1]是Castle官网推荐的使用说明, 本文主要是记录其核心和我的一些体会.

      DynamicProxy确实非常强大.

PⅡ, On The Way

      2.1, Structure & API revelation

      ---

      2.1.1

      Name: IInterceptor

      When to use: 封装实现一个具体拦截行为类

      Code:

1tyrael How to use Castle.DynamicProxy-2.1, part 1public interface IInterceptor
2tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1{
3tyrael How to use Castle.DynamicProxy-2.1, part 1    void Intercept(IInvocation invocation);
4tyrael How to use Castle.DynamicProxy-2.1, part 1}

       所有的'拦截器'都必须实现IInterceptor, 因为在代码生成派生的代理类时, 其构造函数参数为IInterceptor, 依靠构造器动态'注入'具体拦截行为.

      2.1.2

      Name: IInvocation

      When: 回访调用方法属性

     Code:

 1tyrael How to use Castle.DynamicProxy-2.1, part 1public interface IInvocation
 2tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1{
 3tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1    object Proxy tyrael How to use Castle.DynamicProxy-2.1, part 1{ get; }
 4tyrael How to use Castle.DynamicProxy-2.1, part 1
 5tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1    object InvocationTarget tyrael How to use Castle.DynamicProxy-2.1, part 1{ get; }
 6tyrael How to use Castle.DynamicProxy-2.1, part 1    
 7tyrael How to use Castle.DynamicProxy-2.1, part 1    tyrael How to use Castle.DynamicProxy-2.1, part 1                         //Others
 8tyrael How to use Castle.DynamicProxy-2.1, part 1
 9tyrael How to use Castle.DynamicProxy-2.1, part 1    void Proceed();
10tyrael How to use Castle.DynamicProxy-2.1, part 1}

      IInvocation可以看做指向原始方法的delegate的封装, 在代码动态生成期间, 原始方法会挂钩一个IInvocation, IInvocation中的Proxy指向生成的代理类对象, Proceed()委托执行原始方法.

扩展:castle.dynamicproxy / castle dynamic proxy / castle.dynamicproxy2

      2.1.3

      Name: IProxyGenerationHook

      When: 定制代码生成期间的Method/Interceptor匹配对(ShouldInterceptMethod()), 检查通知不能拦截的方法(NonVirutalMemberNotification()), 以及在完成匹配后的扫尾工作, 比如释放资源(MethodsInspected()).

      How:

      var options = new ProxyGenerationOptions(new XXXProxyGenerationHook());

      Code: 

      public interface IProxyGenerationHook
      {
          bool ShouldInterceptMethod(Type type, MethodInfo methodInfo);

         void NonVirtualMemberNotification(Type type, MemberInfo memberInfo);

         void MethodsInspected();
      }

       作为CreateProxyXXX系列方法的option参数传入, 其实现类所有的方法调用都是在代理类对象生成期间完成(对比下面的对象执行期匹配).

      2.1.4

      Name: IInterceptorSelector

      When: 定制对象执行期间的Method/Interceptor匹配对

      How:

      IInterceptorSelector selector = new FreezableInterceptorSelector();

      var options = new ProxyGenerationOptions(new XXXProxyGenerationHook()) {Selector = selector};

      Code:

1tyrael How to use Castle.DynamicProxy-2.1, part 1public interface IInterceptorSelector
2tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1{
3tyrael How to use Castle.DynamicProxy-2.1, part 1    IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors);
4tyrael How to use Castle.DynamicProxy-2.1, part 1}

      作为对象执行期间的匹配原则, 只有通过IProxyGenerationHook规则(代码类生成期间)的方法才能进一步进行匹配筛选.

      2.1.5

      Name: IProxyTargetAccessor

      When: 从伪对象取得真正的代理对象(DynProxyGetTarget()), 取得所有的拦截器(GetInterceptors())

      How:

      var object = ProxyGenerator.CreateProxyXXX(...);

      IInterceptor[] interceptorList = (object as IProxyTargetAccessor).GetInterceptors();

      Code:

1tyrael How to use Castle.DynamicProxy-2.1, part 1public interface IProxyTargetAccessor
2tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1{
3tyrael How to use Castle.DynamicProxy-2.1, part 1    object DynProxyGetTarget();
4tyrael How to use Castle.DynamicProxy-2.1, part 1
5tyrael How to use Castle.DynamicProxy-2.1, part 1    IInterceptor[] GetInterceptors();
6tyrael How to use Castle.DynamicProxy-2.1, part 1}

      一看就知道非常有用.

      2.1.6

      Name: IChangeProxyTarget

      When: 使用CreateInterfaceProxyWithTargetInterface创建proxy, 并需要改变代理的实际对象时.

扩展:castle.dynamicproxy / castle dynamic proxy / castle.dynamicproxy2

      How:

      var changeProxyTarget = invocation as IChangeProxyTarget;

      changeProxyTarget.ChangeInvocationTarget(otherImp);

      Code:

1tyrael How to use Castle.DynamicProxy-2.1, part 1public interface IChangeProxyTarget
2tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1tyrael How to use Castle.DynamicProxy-2.1, part 1{
3tyrael How to use Castle.DynamicProxy-2.1, part 1    void ChangeInvocationTarget(object target);
4tyrael How to use Castle.DynamicProxy-2.1, part 1}

     因为IInvocation接口包含部分属性(关键是其引用了具体的Proxy). 注意, 转换后的具体对象必须也实现了代理接口.

      2.1.7Contrast with four types of proxy creation

      在方法重载中, 少参数方法多半是委托调用多参数方法实现, 并设置额外参数为默认. 所以我们只考虑完全参数的方法实现.

      Code:  

      1. public object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, object[]constructorArguments, params IInterceptor[] interceptors);

      2. public object CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, params IInterceptor[] interceptors);

      3. public object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, object target, ProxyGenerationOptions options, params IInterceptor[] interceptors);

      4. public object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, Type[] additionalInterfacesToProxy, object target, ProxyGenerationOptions options, params IInterceptor[] interceptors);

     通用参数:

      Type classToProxy or interfaceToProxy, 代理对象类型.

      ProxyGenerationOptions options, 这里定义methods/interceptors匹配规则, 混合多接口(Minix) 以及其他选项.

      object[] constructorArguments, 代理对象类型的构造函数参数. 

      IInterceptor[] interceptors, 一组拦截器对象.

      特殊参数:

      @3@4, object target, 接口(interfaceToProxy)的一个具体实现对象.

      其他:

      关于CreateInterfaceProxyWithoutTarget的调用, 因为接口是不可能创建对象的, 代码会自动生成一个实现类, 但该类却不会产生任何逻辑(这是理所当然的), 所以这种情况下我们不能在拦截器的Intercept方法中调用invocation.Process().

      CreateClassProxy()与CreateInterfaceProxyWithTarget类似. 由于Proxy对象的生成本质上是继承(实现)classToProxy(interfaceToProxy)类型, 并override其中的virtual method, 达到改变行为的目的('修改代码的艺术'中的子类化并重写手法). 所以当欲代理对象类型不可继承时(sealed), 我们就不能使用CreateClassProxy()了. 这种情况下, 我们可以提取代理方法接口, 并使用CreateInterfaceProxyWithTarget()方法创建proxy. 我猜想使用CreateInterfaceproxyWithTarget(Type interfaceToProxy, ..., object target, ...)创建的proxy是实现了interfaceToProxy类型的对象, 并内部包含target成员, 各方法委托其实现.   

      使用CreateInterfaceProxyWithTargetInterface创建proxy时, 我们可以在任何可以访问IInvocation对象时转换具体的代理对象(常用做法是在拦截器中保存真实的对象引用, 并在其拦截行为中选择进行替换工作). 需要注意的是, 如果代理对象拥有多组拦截器, 在某一层拦截并替换后, 其后拦截器访问到的invocation对象引用的都是替换后的对象, 但是, 在一轮操作过后(某一个方法的所有拦截行为与其具体行为执行), 代理指向的实际对象会被重置, 即指向原始对象. 我们可以发现, 其实这是符合逻辑的(AOP). 在典型的OO设计中, 我们若进行了接口对象的替换操作, 因为不管之前还是之后的对象, 我们都会重写需要(需要仅对于基于基类的继承)的虚方法, 所以我们得到的对象都是一个个'自完全'的. 但在AOP中, 拦截的切入只能基于一种情况的约定, 可以看做一种契约形式, 如果真实的代理对象被替换后, 我们仍用原始的拦截器拦截, 那么首先就违背这个拦截器的使用约定. 如果此时需要维持逻辑上的正确, 我们就得配置一个与新对象适配的新拦截器来替换, 这等效于替换OO对象, 改写所有的虚方法.

扩展:castle.dynamicproxy / castle dynamic proxy / castle.dynamicproxy2

      ---

      2.2 将介绍应用demo, 2.3 是源代码分析.

 

-----------------------------------------------

Ref:

[1], Castle dynamic proxy tutorial,http://kozmic.pl/archive/2009/04/27/castle-dynamic-proxy-tutorial.aspx

扩展:castle.dynamicproxy / castle dynamic proxy / castle.dynamicproxy2

三 : How to Use A Condom

How to Use A Condom

1. Condoms should be put on the penis when it is erect, before there is any contact between the penis from the other body. Note that fluids discharged from the penis during the early stages of an erection can cause sexually transmitted infections.

2. Tearing along one side of the foil and being sure not to rip the condom inside. Carefully remove the condom. Handle with care. Condoms can be torn by fingernails and sharp objects such as jewelry, zips and buckles.

3. Using your forefinger and thumb, squeeze the tip of the condom and place it over the erect penis. Be sure that roll is outside, so it can be pulled downward.

4. While still squeezing the tip of the condom with one hand, use your other hand to unroll the condom gently down the full length of the penis. Make sure the condom stays in place during sex. If the condom comes off, withdraw the penis and put on a new condom before intercourse continues.

5. Soon after ejaculation, withdraw the penis while it is still erect by holding the condom firmly in place. Remove the condom only when the penis is fully withdrawn. Keep both penis and condom clear from contact with your partner’s body.

condom How to Use A Condom

6. Dispose of the used condom hygienically. Wrap the condom in a tissue and place it in a wastebasket. Don’t flush condoms down the toilet.

(The condom is for single use,Do not re-use.)

Notices: No method of contraception can provide 100% protection against pregnancy of the transmission of HIV and /or sexually transmitted infections. When used properly, latex condoms will help to reduce the risk of HIV/AIDS transmission, as well as other sexually transmitted infections.

扩展:use a woman s condom / put on a condom / condom

四 : How to deal with Difficult People

How to deal with Difficult People

Digg Story:Dealing with Difficult People

Can you recall the last time you had to deal with a negative or difficult person? Or the last time someone said something with the intention of hurting you? How did you handle it? What was the result? What can you do in the future to get through these situations with peace and grace?

No matter where we go, we will face people who are negative, people who oppose our ideas, people who piss us off or people who simply do not like us. There are 6.4 billion people out there and conflict is a fact of life. This fact isn’t the cause of conflict but it is the trigger n.触发器 to our emotions and our emotions are what drive us back to our most basic survival instinct; react and attack back to defend ourselves.

In these instinctual moments, we may lose track of 失去控制、联系our higher selves and become the human animal with an urge to protect ourselves when attacked. This too is natural. However, we are the only animal blessed with intelligence and having the ability to control our responses. So how can we do that?

I regularly get asked “How do you deal with the negative comments about your articles? They are brutal野蛮的. I don’t think I could handle them.” My answer is simple, “I don’t let it bother me to begin with.” It wasn’t always this simple, and took me some time before overcoming this natural urgency to protect myself and attack back.

I know it’s not easy, if it was easy, there wouldn’t be difficult or negative people to begin with.

Why Bother Controlling Our Responses?

? Hurting Ourselves - One of my favorite sayings is “Holding a

other person to die.” The only person we hurt is ourselves. When we react to negativity, we are disturbing our inner space and mentally creating pain within ourselves.

? It’s Not About You, It’s About Them - I’ve learned that when people

initiate [i'ni?ieit] 开始 negativity, it is a reflection of their inner state expressed externally[eks't?:n?li] 外表上 and you just happen to be in front of that

expression. It’s not personal, so why do we take it personally? In short: Because our ego自我 likes problems and conflict. People are often so bored and unhappy with their own lives that they want to take others down with them. There have been

many times when a random person has left a purposefully hurtful comment on TSN, and regularly checked back to see if anyone else responded to their comment, waiting eagerly to respond with more negativity.

? Battle of the Ego - When we respond impulsively [im'p?lsiv]冲动的, it is a

natural and honest response. However, is it the smart thing to do? What can be resolved by doing so? The answer: Nothing. It does however feed our ego’s need for conflict. Have you noticed that when we fight back, it feels really satisfying in our heads? But it doesn’t feel very good in our soul? Our stomach becomes tight, and we start having violent thoughts? When we do respond irrationally [i'r???nli] 不合理的, it turns the conversation from a one-sided negative expression into a battle of two egos. It becomes an unnecessary and unproductive battle for Who is Right?

? Anger Feeds Anger. Negativity Feeds Negativity. - Rarely can any good

come out of reacting against someone who is in a negative state. It will only trigger anger and an additional reactive 反应性的 response from that person. If we do

respond impulsively, we’ll have invested energy in the defending of ourselves and we’ll feel more psychologically compelled 强迫 to defend ourselves going forward. Have you noticed that the angrier our thoughts become, the angrier we become? It’s a negative downward spiral 螺旋.

? Waste of Energy - Where attention goes, energy flows. What we focus on

tends to expand itself. Since we can only focus on one thing at a time, energy spent on negativity is energy that could have been spent on our personal wellbeing. ? Negativity Spreads - I’ve found that once I allow negativity in one area of

my life, it starts to subtly 敏锐地 bleed into other areas as well. When we are in a negative state or holding a grudge against someone, we don’t feel very good. We

carry that energy with us as we go about our day. When we don’t feel very good, we lose sight of clarity 清楚 and may react unconsciously to matters in other areas of our lives, unnecessarily.

? Freedom of Speech - People are as entitled 有资格的 to their opinions as

you are. Allow them to express how they feel and let it be. Remember that it’s all relative and a matter of perspective. What we consider positive can be perceived 认为、理解 by another as negative. When we react, it becomes me-versus-you, who is right? Some people may have a less than eloquent ['el?kw?nt] 雄辩、有口才 way of expressing themselves - it may even be offensive, but they are still entitled to do so. They have the right to express their own opinions and we have the right and will power to choose our responses. We can choose peace or we can choose conflict. You piss me off. 你气死我了。

15 Tips for Dealing with Difficult People

While I’ve had a lot of practice dealing with negativity, it is something I find myself having to actively work on. When I’m caught off guard and end up resorting to a defensive position, the result rarely turns out well.

The point is, we are humans after all, and we have emotions and egos. However, by keeping our egos in-check and inserting emotional intelligence, we’ll not only be doing a favor for our health and mental space, but we’ll also have intercepted a situation that would have gone bad, unnecessarily.

Here are some tips for dealing with a difficult person or negative message:

1. Forgive - What would the Dali Lama do if he was in the situation? He would most likely forgive. Remember that at our very core, we are good, but our judgment becomes clouded and we may say hurtful things. Ask yourself, “What is it about this situation or person that I can seek to understand and forgive?“

2. Wait it Out - Sometimes I feel compelled to instantly send an email defending myself. I’ve learned that emotionally charged emails never get us the result we want; they only add oil to the fire. What is helpful is inserting time to allow

ourselves to cool off. You can write the emotionally charged email to the person, just don’t send it off. Wait until you’ve cooled off before responding, if you choose to respond at all.

3. “Does it really matter if I am right?” - Sometimes we respond with the

intention of defending the side we took a position on. If you find yourself arguing for the sake of being right, ask “Does it matter if I am right?” If yes, then ask “Why do I need to be right? What will I gain?“

4. Don’t Respond - Many times when a person initiates a negative message or difficult attitude, they are trying to trigger a response from you. When we react, we are actually giving them what they want. Let’s stop the cycle of negative

snowballing and sell them short on what they’re looking for; don’t bother

responding.

5. Stop Talking About It - When you have a problem or a conflict in your life, don’

t you find that people just love talking about it? We end up repeating the story to

anyone who’ll listen. We express how much we hate the situation or person. What

we fail to recognize in these moments is that the more we talk about

something, the more of that thing we’ll notice. Example, the more we talk about

how much we dislike a person, the more hate we will feel towards them and the

more we’ll notice things about them that we dislike. Stop giving it energy, stop

thinking about it, and stop talking about it. Do your best to not repeat the story to

others.

6. Be In Their Shoes - As cliché as this may sound, we tend to forget that we

become blind sighted in the situation. Try putting yourself in their position and

consider how you may have hurt their feelings. This understanding will give you a

new perspective on becoming rational again, and may help you develop compassion for the other person.

7. Look for the Lessons - No situation is ever lost if we can take away from it some

lessons that will help us grow and become a better person. Regardless of how

negative a scenario may appear, there is always a hidden gift in the form of a lesson.

Find the lesson(s).

8. Choose to Eliminate Negative People In Your Life - Negative people can be a

source of energy drain. And deeply unhappy people will want to bring you down

emotionally, so that they are not down there alone. Be aware of this. Unless you have a lot of time on your hands and do not mind the energy drain, I recommend that you cut them off from your life. Cut them out by avoiding interactions with them as much as possible. Remember that you have the choice to commit to being surrounded by people who have the qualities you admire: optimistic, positive,

peaceful and encouraging people. As Kathy Sierra said, “Be around the change you want to see in the world.”

9. Become the Observer - When we practice becoming the observer of our feelings, our thoughts and the situation, we separate ourselves away from the emotions. Instead of identifying with the emotions and letting them consume us, we observe them with clarity and detachment. When you find yourself identifying with emotions and thoughts, bring your focus on your breathe.

10. Go for a Run … or a swim, or some other workout. Physical exercise can help to release the negative and excess energy in us. Use exercise as a tool to clear your mind and release built up negative energy.

11. Worst Case Scenario - Ask yourself two questions, “If I do not respond, what is the worst thing that can result from it?“, “If I do respond, what is the worst thing that can result from it?” Answering these questions often adds perspectives to the situation, and you’ll realize that nothing good will come out of reacting. Your energy will be wasted, and your inner space disturbed.

12. Avoid Heated Discussions - When we’re emotionally charged, we are so much in our heads that we argue out of an impulse to be right, to defend ourselves, for

本文标题:HOW TO-a spark, a flint:how fire leapt to life
本文地址: http://www.61k.com/1068451.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1