theme switch custom minimal, volledige herwerking site

This commit is contained in:
wgroeneveld 2018-04-27 12:00:07 +02:00
parent 260f77f791
commit dcdfdf7689
294 changed files with 711 additions and 32577 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "themes/minimal"]
path = themes/minimal
url = https://github.com/calintat/minimal.git

View File

@ -2,76 +2,59 @@ languageCode = "en-us"
title = "Brain Baking"
baseurl = "https://brainbaking.com/"
enableEmoji = true
theme = "beautifulbaking"
theme = "minimal"
pygmentsUseClasses = true
pygmentCodeFences = true
disqusShortname = "brainbaking"
googleAnalytics = "UA-45748221-1"
publishDir = "docs"
[taxonomies]
tag = "tags"
tag = "tags"
[Params]
subtitle = "Freshly baked thoughts"
logo = "img/avatar-icon.png"
favicon = "img/favicon.ico"
commit = false
[params]
description = "Freshly baked thoughts."
# see single.html, DisqusShortname also needed
disableComments = true
accent = "purple"
showBorder = true
backgroundColor = "white"
highlight = true
highlightStyle = "paraiso-dark"
highlightLanguages = ["c#", "java", "scala", "javascript"]
font = "Open Sans"
copyright = "No <i class='fa fa-copyright'></i> reserved - sharing is caring. <i class='fa fa-github'></i> <a href='https://github.com/wgroeneveld/brainbaking/'>Hack away</a>! <i class='fa fa-lightbulb-o'></i> <a href='/'>Brainbaking</a>"
[Author]
name = "Wouter Groeneveld"
email = "wouter.groeneveld@gmail.com"
#facebook = "username"
github = "wgroeneveld"
#twitter = "woutergroenev"
#linkedin = "username"
#stackoverflow = "users/XXXXXXX/username"
#soundcloud = "username"
#instagram = "username"
#youtube = "user/username" # or channel/channelname
#spotify = "username"
#itchio = "username"
pinterest = "woutergroenev"
goodreads = "5451893-wouter"
[[menu.main]]
name = "Menu"
url = "/"
weight = 1
pre = "<i class='fa fa-home'></i>"
[[menu.main]]
name = "Wiki"
parent = "Menu"
url = "/wiki/"
pre = "<i class='fa fa-wikipedia-w'></i>"
name = "Tech Blog"
pre = "<i class='fa fa-file-code-o'></i>"
url = "/post"
weight = 1
[[menu.main]]
name = "Tags"
parent = "Menu"
url = "/tags"
pre = "<i class='fa fa-tags'></i>"
name = "Essays"
pre = "<i class='fa fa-book'></i>"
url = "/essays"
weight = 2
[[menu.main]]
name = "About me"
parent = "Menu"
url = "/about"
pre = "<i class='fa fa-address-card-o'></i>"
name = "Tags"
pre = "<i class='fa fa-tags'></i>"
url = "/tags"
weight = 3
[[menu.main]]
name = "Teaching"
pre = "<i class='fa fa-graduation-cap'></i>"
parent = "Menu"
url = "/teaching"
[[menu.mainright]]
name = "About Me"
pre = "<i class='fa fa-user'></i>"
url = "/about"
weight = 4
[[menu.main]]
name = "Books"
pre = "<i class='fa fa-book' aria-hidden='true'></i>"
parent = "Menu"
url = "/books"
[[menu.mainright]]
name = "Teaching"
pre = "<i class='fa fa-graduation-cap'></i>"
url = "/teaching"
weight = 5

View File

@ -1,10 +1,12 @@
---
bigimg: /img/About Me.jpg
title: About Me
icontag: "fa-user"
---
# About Me
## Hi, Im Wouter Groeneveld
Hi, Im Wouter Groeneveld, and I have a deep passion to inspire others on everything that drives me. I like to think of myself as one of those Rennaissance Men:
And I have a deep passion to inspire others on everything that drives me. I like to think of myself as one of those Rennaissance Men:
> Renaissance man (noun) - a person with many talents or areas of knowledge.
@ -18,16 +20,32 @@ Those areas of knowledge include:
* I love dynamic languages. I also love converting the haters to the dark side. I teach javascript as a dynamic and functional language - it helps to create your own funky labs to people get more engaged.
* Pair programming used as a tool to learn from each other and to improve code quality are two values I believe in.
Take a look at my [<i class='fa fa-github'></i>&nbsp;Github account](https://github.com/wgroeneveld).
#### Baking
* I hold a [professional bread baker's degree](/post/learning-to-become-a-baker/) so naturally I love to think of myself as a real baker.
* My passion within baking is sourdough, spreading the word by organizing workshops to repopularize it's use.
* My passion within baking is [<i class='fa fa-flask'></i>&nbsp;sourdough bread](https://redzuurdesem.be), spreading the word by organizing workshops to repopularize it's use.
#### Writing and philosophizing
* A [fountain pen addict](/post/fountain-pens-first-look/) and avid [journaler](/post/journaling-in-practice/)
* A [fountain pen addict](/post/fountain-pens-first-look/) and avid [<i class='fa fa-pencil'></i>&nbsp;journaler](/post/journaling-in-practice/)
* This blog is the ideal base for writing down my thoughts about virtually anything, primarly intended to amuse myself and not others.
#### Drawing
* Starting out to [learn](/post/drawing-week-01) how to use ink other than writing.
## Where good ideas come from: Books
I keep an active <a href="https://www.goodreads.com/user/show/5451893-wouter" target="_blank"><i class='fa fa-book'></i>&nbsp;Goodreads</a> account where I manage everything I've read and want to read. I invite you to join the community there. Marking a book as read and writing a (short) review never was that satisfying...
I used to be almost exclusively a fantasy reader. Now I mostly read non-fiction on the most diverse topics, but I do have a soft spot for things like philosophy, art, mindful food and software engineering.
These are the latest 52 books I've read:
<div id="gr_grid_widget_1496758344">
</div>
</div>
<script src="https://www.goodreads.com/review/grid_widget/5451893.Wouter's%20bookshelf:%20read?cover_size=medium&hide_link=&hide_title=&num_books=52&order=d&shelf=read&sort=date_added&widget_id=1496758344" type="text/javascript" charset="utf-8"></script>

View File

@ -1,15 +0,0 @@
# Books
I keep an active <a href="https://www.goodreads.com/user/show/5451893-wouter" target="_blank">Goodreads</a> account where I manage everything I've read and want to read. I invite you to join the community there. Marking a book as read and writing a (short) review never was that satisfying...
I used to be almost exclusively a fantasy reader. Now I mostly read non-fiction on the most diverse topics, but I do have a soft spot for things like philosophy, art, mindful food and software engineering.
These are the latest 52 books I've read:
<div id="gr_grid_widget_1496758344">
</div>
</div>
<script src="https://www.goodreads.com/review/grid_widget/5451893.Wouter's%20bookshelf:%20read?cover_size=medium&hide_link=&hide_title=&num_books=52&order=d&shelf=read&sort=date_added&widget_id=1496758344" type="text/javascript" charset="utf-8"></script>

View File

@ -2,6 +2,7 @@
title: 2017 in books
date: '2018-01-27'
bigimg: /img/2017inbooks.png
url: /post/2017-in-books/
subtitle: Pattern recognition in books
tags:
- journaling

26
content/essays/_index.md Normal file
View File

@ -0,0 +1,26 @@
---
title: Essays
icontag: fa-book
---
> Filosofie is voor het vinden van een baan misschien het minst bruikbaar van alle studies, maar het is niettemin de beste studie. - Aristoteles
De essentie van [Brain Baking](/) bevindt zich hier, het bakken van in eerste instantie **mijn** hersenen, met het reflectieve karakter van de filosofie als aroma. Ik schrijf voor mezelf, om mijzelf te helpen anderen te kunnen helpen. _Baked brains_ met een krokante korst zijn goed verteerbare verhoudingen tussen mijzelf en de wereld, geïnspireerd op de Groten als Kant (_Kritik der reinen Vernunft_), Wittgenstein (_tractatus logico-philosophicus_) en Montaigne (_Essais_).
Ik ontdekte lang geleden de stereotypische "positieve psychologie" boeken die mij aanzetten om te beginnen met [_journaling_](/post/journaling-in-practice/) en dus [_meta-denken_](/post/healing-creative-scars/). De essentie van deze psychologie bracht mij tot de "lifestyle filosofie" van onder andere [The School of Life](https://www.theschooloflife.com/). Het was slechts een kwestie van tijd om mijn eigen Ockham's scheermes toe te passen en uit te komen op pure filosofie.
<div class="row">
<div class="col-md-6"><strong>Nederlands</strong></div>
<div class="col-md-6"><strong>English</strong></div>
</div>
<div class="row">
<div class="col-md-6">
De Werken van bovenstaande grote filosofen zijn allemaal geschreven in de moedertaal van de auteur. Ik heb jaren geprobeerd om mijn denken om te zetten in de gewenste Internet taal (Engels), en ben tot de conclusie gekomen dat dit niet werkt. Daarom zijn onderstaande werken geschreven in het Nederlands vanaf 2018.
</div>
<div class="col-md-6">
The works of big philosophers I admire are all written in their own native language. For years I've tried to convert my thinking into the widely-accepted Internet language (English), and I've concluded that this simply does not work. That's why the works below are all written in Dutch since 2018.
</div>
</div>
</div>

View File

@ -2,6 +2,7 @@
title: A samurai learning mindset
date: '2017-06-20'
bigimg: /img/musashi.jpg
url: /post/a-samurai-learning-mindset/
subtitle: Bushido and the ever learning spirit, techniques for 1600 and 2017?
tags:
- learning

View File

@ -2,8 +2,10 @@
title: Ending your day with happy thoughts
date: '2013-08-13'
bigimg: /img/Ending your day with happy thoughts.jpg
url: /post/can-i-haz-happy-thoughts/
aliases:
- /ending-your-day-with-happy-thoughts/
- /post/ending-your-day-with-happy-thoughts/
subtitle: Or how a tiny thing can really help you sleep better
tags: ['self improvement', 'journaling']
---

View File

@ -2,11 +2,12 @@
title: 'Are you handing over enough when inspiring someone?'
date: '2017-05-30'
subtitle: What info to convey, when to stop?
url: /post/handing-over-enough-when-inspiring/
tags:
- teaching
- inspiring
- giving
- brain dump
- braindump
published: true
---

View File

@ -2,6 +2,7 @@
title: Healing creative scars
date: '2017-06-25'
bigimg: /img/boekjesheader.png
url: /post/healing-creative-scars/
subtitle: My ultimate secret weapon for self improvement
tags:
- learning

View File

@ -0,0 +1,91 @@
---
title: I'm jealous of my dog
date: '2017-08-17'
bigimg: /img/woef.jpg
url: /post/i-am-jealous-of-my-dog/
subtitle: Getting rid of garbage in your head
tags:
- self improvement
published: true
---
My dog, Miel (yes, like the French word for honey. It's a Golden Retriever, get the link?), loves to walk. He also likes playing a lot, but as soon as I put on my shoes or get near the garden gate, he starts to freak out, thinking it's that time again. Since I have no idea what is going on in is head, I said "thinking", because we humans associate animals with our own behavior - because that's what we're familiar with. Have you ever walked a dog? Have you noticed the dog's "state of mind"? How would you notice such a thing? Pay attention to what your dog is doing and you'll know what I mean.
Miel is not thinking. He's walking. Sniffing. He's present in that very moment. <br/>
On the other hand, I'm pondering something that happened to me today. I might be distracted. After a few blocks, I might think "oh wow, now where was I". I might have missed the waving neighbor, the sunny weather or the absence of noisy cars. I am not present in that very moment at all - I'm either in the past ("why did that person say this to me") or in the future ("I need to do this and that and that after I get back"). Why is it so hard to be in the present, if Miel can do this so easily?
![Mind full-ness](/img/mindfull.jpg)
Image copyright socksofdoom
It seems that I'm [not the only one with that problem](https://trudymorgancole.wordpress.com/2014/03/02/dogs-walks-and-mindfulness/). After taking an eight week long mindfulness course, it seems that I'm still practicing mind-**full**ness instead of mindfulness. We humans are blessed and cursed with a thinking brain but luckily Buddhists have proven that it can be temporary shut down. There's only one way to achieve this state of mind: practice. I love reading about this subject and recently finished the extremely popular "[zen mind, beginners mind](https://www.goodreads.com/book/show/402843.Zen_Mind_Beginner_s_Mind)" by Shunryu Suzuki. It's a very practical book that explains the basics of Zen-Buddhism. One major recurring subject is practicing versus studying the philosophy behind Zen. The more you read and know things about Zen, the more poisoned your mind is. So start doing and stop reading.
Miel isn't the only "person" (whoops) that loves his daily walk. Ever since we got the dog, I too started to enjoy breaking out of my comfortable living room, doing the usual nothing. Dog walking gives me an excuse to get up and walk, and to try to be in the moment, to try to notice the weather, to smell the air, to feel the raindrops and to simply walk. Failing implies getting up and doing it again. When I catch myself thinking about something or worrying, I friendly but firmly redirect myself to the present: walking. Most of the times, Miel does this for me with a pull of the leach. In that sense, it could be a bit like meditating. That's one of the reasons I like drawing so much: I can't do anything else but to study the subject, and start laying done line per line. Study it more closely, start seeing details within details as Tommy Kane would say. I usually need a few minutes to get myself into that (drawing-) mode and that's one of the reasons I am having difficulties drawing in urban regions where a lot of people distract me.
In one of the lessons in the mindfulness course, we had to do a walking meditation. That implied focusing on the contact of the earth and your foot, feeling where you land each foot and concentrating on walking alone. I like to do this when I'm biking. You start to notice how your knee joints work, and where that heavy pushing on the petals is going when you cross a steep bridge. This sounds like it's easy but it's not: I'd say those moments are rare for me. I usually catch myself thinking stuff about my work when I'm biking to and from work a few minutes after attempting to concentrate on biking alone. But that's alright: I'm learning from my dog.
I'm grateful for my dog reminding me I need to "take a walk", to "clear my head". So why don't you clear your head when you're walking but fill it even more?
- Does it make you feel better?
- Are the problems resolved when pondering them at that time?
- Can't you focus on your dog instead of your "stuff"? He'd appreciate it.
![Multi tasking sucks](/img/multitaskingsucks.jpg)
Image copyright [privatebarking](https://www.privatebarking.com/puplifting-quotes-multitasking-sucks/)
The thinking most certainly still needs to be done but you'll make it yourself a lot easier if you think when you need to think and walk when you need to walk. It's called **single tasking** and we should all do it more often. The myth of multitasking that gets more work done is a very short sighted view on economical capitalism. Context switching costs precious time - even up to 20 minutes to get back into what you were doing. That is one of the main reasons you should not check your mail every hour but once in the morning and once in the evening. I'm starting to resent people who cling to their iPhones, instead of focus sing on the person in front of them. It's all part of the same problem.
If you're having trouble, remember this: if your dog is playing, it's playing, not playing and managing his backlog. If your dog is eating, it's eating, not playing with his ball next to his supper. So keep that cellphone off the dinner table and try to mimic his behavior. <br/>
I know this sounds easy, but it takes a lifetime to fully master. I still wake up most days with too much scrambled thoughts about what happened yesterday and what will happen today, having difficulties letting go of them. It's so easy to **get lost within your own thoughts** and it does have it's purpose to do a "thought walk" and mix and mash ideas to get to another one. But it's also vital that you have a working STOP button.
I have to stop typing and think about that for a moment now.
What was I saying?
The common problem of noise in your head has not been solved just yet. In fact, it has only gotten worse. A lot worse. The garbage thinking problem spread like a disease, clinging onto everything in it's way inside me. It has reached my ears and my mind. I'd like to make a distinction between "head" and "mind" as "head" might be a temporary problem, getting something to stick in your "mind" sounds a lot more definitive to me. Allow me to elaborate.
### Pollution in my ears
Are you also fed up with this noise generating world? The louder the better. You're only cool if you are able to stand the music beating your ears in your plugs at level 15 or higher. It's awesome to drill a hole in an exhaust pipe so your motor doesn't get unheard. Yelling usually provides you with the direct attention you need, whether at the checkout or in a meeting.
Does this sound familiar to you? I'm not even talking about people who are highly sensitive or introverts vs extroverts, but in general. Just, in general, at every single level. Getting to work makes my body take more decibels than it used to thanks to the increased traffic full of ignorant people who like to listen to the (loud) radio and have the comfort of a leather chair instead of a bike. The absurd concept of open work spaces makes my day at work barely productive. A beginning headache by 3h PM is normal. Shopping for groceries in a mall or supermarket doesn't make my day any better as the non stop stream of commercials rolls out of speakers and mounted televisions. The end of an exhausting day marks watching television because my wife thinks that's the best way to relax. Don't forget to crank up that volume, otherwise you won't be able to follow that quiz.
At last, in bed. I greet the ever present buzz inside my mind and sigh.
Something has to be done. And so I did:
1. When I'm driving, the radio is __always__ off. I love that bubble of silence.
2. Take your foot off the clutch if you have an engine that stops automatically at a red light. Ahhhh.
3. Get rid of everything that ticks and whirrs in your living room.
4. Bike around traffic even if that means a couple of minutes extra commute.
5. Try to use headphones that block out noise of others at work.
6. Turn off the TV.
7. Turn the TV back on after your wife gets angry.
8. Read somewhere else where there's no TV on.
9. Go back to the room with the TV because your wife is lonely.
The above has only seen partial success. Traffic is everywhere, you can't bike around it that easily. Thanks to the nature of my job, as a software engineer working inside teams, I'm constantly disturbed - headphones or not. However, we introduced a "silent period" of 1.5hrs twice a week in an attempt to reduce the general noise overhead. That does mean we need the cooperation of our colleagues...
### Pollution in my mind
Getting obsessed with something can prove to be dangerous too. Let's call it "unhealthy". When I get excited about something, like fountain pens or more recently my reintroduction into Magic: the Gathering, I can get a bit too obsessed with it. Searching for the perfect pen, watching videos, looking around for the better shop, reading about what others think and say. Looking at what cards are played at tournaments, thinking about strategies, trying out different combinations inside my head. That sounds innocent, but can cause me to put all other things to hold. Suddenly, I lose interest in other things I was a lot more interested in, in the first place. Biking from and to work happens pseudo-automatically, pondering the right combination of killer combo cards to put into my deck. Oh, did I pass this street already? How time flies.
My mind saves all ongoing progress of different stuff and loads up one single program: Magic.
That'll mean I'll probably dream about it and talk about it until everyone thinks I'm obsessed (at that point, I might very much well be).
Until something else comes along, Magic probably will get stored as ongoing progress and something else (completely) occupies my mind.
Sounds like mind-full-ness or mind-fool-ness to me. Every time I catch myself thinking "I should meditate more and try to clear my head", I end up surfing to some Magic-related website again. The cards or the game aren't the problem, but my occupation with those temporary things is. And I'm convinced the only solution will be to __slow down and take a deep breath__. The more I'm upset with something like the repetitiveness of my work, the more I delve into that ever ready stream of happy Magic-thoughts. Yay!
Less thinking, more being.
### Pollution in general
Think about the amount of images that burn in our retinas daily, the amount of unneeded refresh rates it has to take for your eyes to read a stupid Facebook page of a distant friend you're not even remotely interested in in the first place. The amount of things you have to do each day because they're part of a weird ritual made up by your local government or employer. The amount of noise you have to dig through in order to reach the data that is actually relevant to you in order to get your job done. The ridiculous amount of mails you send and receive each day because you think you have to or otherwise others won't find you that productive. The amount of times you have to say "I know what you mean" and "really? How cool!" to someone, when, in fact, that person is very irritating and you just want to go home. The amount of hours you spend watching a television show that could be spent walking your dog, drawing or reading instead.
The amount of hours you waste sitting in a chair thinking you could do something else right now. I might have a feeling of melancholy typing this, and you know that I might overreact, or not based on your situation, but you also know that time is better spent if you're in that very moment you're spending it. Maybe
Like bicycling instead of thinking about games. Or just trying to sincerely help others instead of complaining about noise and receiving positive feedback on your way out. Or actively engaging into a conversation when you're committing yourself to it instead of thinking about games. Or honestly saying that you're not interested and simply going home. That'll do.
I'm still (not) working on a solution to this problem.
<br/>I'll probably figure it out just before I die.

View File

@ -2,6 +2,7 @@
title: Inventing - for the worse?
date: '2017-12-30'
bigimg: /img/craftheader.png
url: /post/inventing-for-the-worse/
subtitle: Is inventing always a good thing?
tags:
- self improvement

View File

@ -2,6 +2,7 @@
title: Journaling in practice
date: '2017-07-10'
bigimg: /img/journalingpratice.jpg
url: /post/journaling-in-practice/
subtitle: My guide to keeping a journal
tags:
- journaling

View File

@ -2,12 +2,19 @@
title: Learning to become a baker
bigimg: /img/baker.jpg
date: '2013-10-13'
url: /post/learning-to-become-a-baker/
subtitle: Why there are more and more industrial bakers who dont care what they sell.
tags: ['braindump', learning', 'baking', 'bread' ]
tags: ['braindump', 'learning', 'baking', 'bread' ]
---
Originally posted on [Medium](https://medium.com/this-happened-to-me/learning-to-become-a-baker-99c0d2c3388a).
#### Addendum
[Red Zuurdesem](https://redzuurdesem.be), my website about baking with sourdough, has been active since 2012, and still is. I hold a _professional bread baker's degree_ since 2016 - this article was written during the first year when I enrolled in the course.
<hr/>
Sometimes people tell me Im obsessed with bread. Thats not entirely my fault. (I like to blame others, who doesnt?) When I was little, my father always baked our own bread on sunday, every single sunday. I cant remember anytime we actually bought bread, except on vacation. At a young age I had no idea how creating something out of nothing actually worked, but I knew it was intriguingthe addition of yeast which caused the dough to bubble up within a short period of time, wow!
When I grew older, I lost my interest in food in generalI had other worries such as studying. (well, and girlfriends, but thats a part of studying!) I have two sisters and we never cooked, our parents always did that. The only thing that remained was the joy of eating a freshly baked slice of bread at sunday after all the breads have been cut and packagedmy father baked enough for the freezer to use throughout the week.

View File

@ -2,6 +2,7 @@
title: Nuts about local nuts
date: '2017-07-03'
bigimg: /img/pines.jpg
url: /post/nuts-about-local-nuts/
subtitle: A case for local food
tags:
- cooking

View File

@ -1,6 +1,7 @@
---
title: On finding your inner zen in big cities
bigimg: /img/innerzenheader.jpg
url: /post/on-finding-your-inner-zen-in-big-cities/
date: '2013-08-29'
subtitle: Coping with crowded places when youre used to peaceful villages
tags: ['braindump', learning', 'zen' ]

View File

@ -2,6 +2,7 @@
title: Concentrating on serendipitous creativity
date: '2018-03-25'
bigimg: /img/tea.png
url: /post/serendipitous-creativity/
subtitle: Focused or collaborative attention?
tags:
- self improvement

View File

@ -2,6 +2,7 @@
title: Take your time.
date: '2018-02-16'
bigimg: /img/takeyourtime.jpg
url: /post/take-your-time/
subtitle: Stop rushing. Start watching.
tags:
- journaling

View File

@ -0,0 +1,183 @@
---
title: Teaching yourself to draw
date: '2017-02-01'
subtitle: A year of spilling lots of ink
url: '/post/teaching-yourself-to-draw/'
tags:
- Teaching yourself to draw
published: true
---
Inspired by Noah Bradley's [Don't go to art school](https://medium.com/i-m-h-o/dont-go-to-art-school-138c5efd45e9#.aul09q3wr) blog at Medium.com.
Drawing and art in general has always been something I didn't quite grasp or try to understand. I was a software development guy, a technical guy, used to writing code, looking at text, spending days and years in text editors others call IDE's. Software development and art aren't that different actually: they both require an open mindset and an extreme creative approach at solving problems. That's one of the reasons I became interested in drawing.
Another is to get some color into my journals. I've been journaling for about 7 years now and it's been my most important tool in life. It helps me understand myself, collect and execute ideas and to keep the chaos in the world and my mind contained. Writing pages isn't a problem, doodling either, but the page never really pops. Sketching is something I like to do now and then but after hearing things like "you can't draw at all!" my motivation completely disappears.
### [How to really master a skill](http://www.makeuseof.com/tag/10000-hour-rule-wrong-really-master-skill/)?
* Deliberate practice
* Getting down the pyramid chain: <br/>teaching > practicing > group discussion > reading > lecture
* "10.000 hours" (it's an average, I know)
* Quantify yourself by using a **feedback loop**
### My Feedback loop is this very blog.
It should be that simple. I intent to learn to draw within a year, without enrolling in a traditional school. To be successful, I will turn to books, online courses, experts in art by visiting expo's/museums, experts in art by going to short term workshops, and above all: by lot's of practicing. Noah states that $10k could be spent wisely within one year. I have no idea how much it will cost me but my intention is to keep it as low as possible.
Each learning 'session' will be another blog post. I have a general idea on what I like (ink, watercolor, anything physical, journals) and what I don't like (acrylic paint, anything digital) but since there is so much I don't know, this might change during the course of the coming year. Since Pinterest is so inspiring I'd like to upload as much of the artwork as possible. Sharing via pins makes it easier for people to try it themselves.
Take a look at my Pinterest profile by clicking on the icon on the bottom of the page.
If you're looking for all blog posts about learning to draw, check out the **'[Teaching yourself to draw](/tags/teaching-yourself-to-draw/)' tag**.
Are you familiar with the frustrated feeling you get while visting an art supply store and staring at all the equipment but having no idea what does what? That's me. So, I figured...
### Start with the beginning.
[Snow&Rose workshop: Illustrative techniques](http://snow-and-rose.com/nl/workshop/) was my entrypoint. It's a 10-week (once a week) workshop to cover the basics of drawing illustrative creatures, flowers, landscape, anything. No realistic drawing, no up-front knowledge required and each week it covers another medium:
1. charcoal and pencil
2. bistre, reedpen
3. pastel
4. aquarel
5. acrylic paint
6. aquarellable colorpencils
7. ecoline
8. ink with fineliners
9. collage/scrapbooking
10. mixed media
Price is 390 EUR. As it's only once a week, it creates the perfect opportunity for me to practice drawing "stuff" between the lessons and to experiment a bit with the different mediums.
These are some christmas-themed cards I made with cheap pastels during the third lesson:
{{< pin "308707749442493529" >}}
{{< pin "308707749442493506" >}}
{{< pin "308707749442493510" >}}
It starts out very simple, as you can see. I'm still having difficulties buying the right equipment. The pastels used above are very hard and grainy, and don't contain a lot of pigment. That is clearly visible in the gameboy one on the far left: the brown paper shouldn't be that visible. Small steps, small steps...
### But I suck at drawing!
So do I.
Each week (this sounds like a promise I'll have to make to myself) I'll post a new blog post summarizing what I've learned about drawing, art ant painting. Hopefully, after 52 posts, others who are thinking about making the step won't be that intimidated as I am right now. I've already felt that looking too much at work of others (in Pinterest for example) completely demotivates me. You'll always find someone who completely outperforms you. It's not about their work, it's about your own, and **the progress you make**, however small that might be. If it's going forward, it's going forward. There is no hardwired limit on where to go to. Let's just keep on trying, failing, getting up and trying again! It looks like 2017 is going to be an interesting year for me.
### Week 1
As you might already have read, I started the drawing adventure with a 10-week 'illustrative techniques' course. It sounds complicated but it wasn't really: it's more of a gentle introduction in different mediums (pencil, ink, acrylic paint, ...) than a crash course in drawing techniques. I didn't know then that to draw illustrations, you still have to be able to draw. (I'm reading "drawing at the right side of the brain" and I know better now). But still, thse drawings might be fun to look at or to compare to the other weeks.
{{< pin "308707749443972926" >}}
{{< pin "308707749443972958" >}}
{{< pin "308707749443972977" >}}
These are all random drawings I did between the lessons to get myself familiar with a pencil. That sounds awful, doesn't it? Who uses pencils anyway. The left scan contains some color: that's an experiment. The brown is **bistre**, something we had to work with in the second class. The other colors are very cheap **pastels**.
So, what did I learn this week:
1. Bistre can be a bit of a mess. You absolutely cannot wait, edges will form and it'll be worse than watercolor.
2. Expensive tools **are** better than cheap ones. Pastels are softer and contain a lot more pigment than the ones you can find in sale bins.
3. I know the difference between a **HB** and a **B4** pencil. I know how to sharpen one. Yay.
4. These drawings look like doodles because they are a lot like doodles. I like drawing that but I have the feeling I'm missing a lot background info (will be continued...)
5. Patience looks like an important skill to aid me in learning how to draw.
6. **Do not look at the work of others!**
I warned you:
{{< pin "568720259163636687" >}}
This also is bistre.
Ouch.
## Week 2
After the illustration course, I'm not ashamed to admit I completely dropped the pencil out of the game. It creates lines easy to remove and that means I'm working on a drawing forever. I need something to commit myself to. That something is called ink.
It also seems that I already have stuff to get ink on a paper: pens. Ballpoint pens. Black, blue, whatever. Just simple pens you use to write with - the cheaper, the better. I came across **Danny Gregory**'s work [Art before breakfast](https://dannygregorysblog.com/books/art-before-breakfast/) and [The Creative Licence](http://www.dannygregory.com/author) (buy the latter one if you can). These are very inspirational books that get you kickstarted drawing from zero by learning how to see, explaning negative space and other simple techniques. It doesn't go into detail, it simply helps you get drawing.
And Danny is a fan of ink + watercolor. I immediately fell in love and knew that was what I wanted. So yes, put that pencil back where it belongs. I started trying to draw what I see:
{{< pin "308707749443972993" >}}
{{< pin "308707749443973015" >}}
{{< pin "308707749443973029" >}}
It looks a lot brighter than [week 1](/post/drawing-week-01). After drawing with a pen a few times, it felt better and better. I tried to copy Danny's style a bit by giving it some (water)color but that might be too much new stuff within a few weeks.
I'm particulary fond of the yellow post-it note: an impression of my left foot while waiting for my wife to finish shopping. I keep pen & paper with me at all times: that's a healthy habit I developed 7 years ago when starting journaling.
The first foot trace was a complete disaster by the way.
So, what did I learn this week:
1. Pen > pencil.
2. Danny Gregory rocks. He has tons of books and is co-founder of the [Sketchbook Skool](http://sketchbookskool.com/). Once I knew that, I enrolled in the "beginning" kourse.
3. I like sketching more than doodling.
4. "Seeing" is incredibly hard: I constantly mess up proportions.
5. Adding watercolor seems to add a lot of dimension.
Let's take a look at what Danny does:
{{< pin "381609768399365667" >}}
{{< pin "233976143118067754" >}}
Awesome.
## Week 3
I wanted to continue my quest of finding my own style within ink and watercolor boundaries. After the amazing discovery of [Skillshare.com](https://www.skillshare.com), I switched to using Artline fineliners. I also have some Steadlers but hardly notice any difference between different felt tip pens if they have the same thickness. I found a short course by Shirish Deshpande on drawing with ink and creating some contrast and texture. The drawings in the videos are amazing and I tried to copy them to my best abilities:
{{< pin "308707749443973054" >}}
{{< pin "308707749443973073" >}}
{{< pin "308707749443973094" >}}
The ink flowing from a technical pen is much more intense than a standard ballpoint pen as seen in [week 2](/post/drawing-week-02). I like that a lot. It also enables me to be much more precise and that is something that I tend to do a lot. I usually draw (too) small and try to cram in as much details as possible. The thinner the felt tip pen, the better for me. (Although I borked a 005 one, those guys are very sensitive!).
During the snow & rose course, the lesson with the fineliners suited me the most, and now I have that same feeling. I finally give (cross-)hatching a shot and it really looks a lot better. Thanks Shirish, for building up my confidence in drawing with ink!
So, what did I learn this week:
1. Intensity of ink matters.
2. Contrast is extermely important and gives your drawing an "oomph"
3. I learned the "hatching", "stipling", and "random" technique.
4. Fineliners > ballpoint pens > pencils (sensing a trend here, fountain pen coming up)
Let's take a look at what Shirish does with his pens (and added colored ink):
{{< pin "394698354817739793" >}}
{{< pin "364299057333088725" >}}
He usually doesn't color with watercolor but with (diluted) colored ink. I have yet to try that.
## Week 4
As I'm slowly getting a tiny bit better at drawing things I see, I still don't have a fundamental basis to rely on. Until I've read "[Drawing at the right side of the brian](http://drawright.com/)" from Betty Edwards. Everything I've read in there came as a complete revelation to me. She explains how you should "look" at things, what is important to look out for when realisticly drawing and how values/tones work. It's an amazing book and I'm very glad I've added it to my toread list (a few years ago, I finally got around to actually reading it.)
Can you spot the difference between the portraits below?
{{< pin "308707749447642788" >}}
{{< pin "308707749447642793" >}}
Yes, I am well aware that the second portrait still looks like crap but come on, at least it shows highlights, it has a decent contour and my skull isn't "chopped off". Both drawings took me 45 minutes. I'd say that's a definitive improvement here.
Other exercises in the books concentrate on hands, interiour, chairs, ...:
{{< pin "308707749447642796" >}}
{{< pin "308707749447642801" >}}
Everything is done with a pencil. My preference is starting to lean towards 2B and 4B instead of HB.
So, what did I learn this week: (these are some quick oneliners that summarize each important chapter in the book)
1. Draw (shared) edges of stuff: call them contours.
2. Draw spaces between stuff: call it negative space.
3. Draw relationships between stuff: call them angles and proportions.
4. Draw lights and shadows on stuff: call them tonal differences.
5. Do not draw the appearance of stuff: call it "the gestalt".
The last point is an interesting one. It's also called "making it come together" and is usually achieved by simply focusing on the other 4 points.
Doing these exercises gave me a real boost in confidence and motivated me to draw even more. I even started enjoying the use of a pencil - soft shading is nice and not doable with a pen!
Read more on how to draw better in Jen Review's [How to Draw Better](https://www.jenreviews.com/how-to-draw-better/) blog post.

View File

@ -2,6 +2,7 @@
title: No, vegetarians do not eat fish!
bigimg: /img/peppersheader.jpg
date: '2013-09-06'
url: /post/no-vegetarians-do-not-eat-fish/
subtitle: The sad state of knowledge in your typical restaurant
tags: ['braindump', 'vegetarian' ]
---

10
content/post/_index.md Normal file
View File

@ -0,0 +1,10 @@
---
title: Tech Blog
icontag: fa-file-code-o
---
> No Art and Science serve alone; Patience must in the work be shown. - Goethe
A pursuit of knowledge for either personal or professional reasons is called [Lifelong learning](https://en.wikipedia.org/wiki/Lifelong_learning). As a great deal of my life is dedicated to Computer Science, so it's only natural to do some heavy [_Brain Baking_](/) work in the technical area of expertise. I discovered that in order for me to teach and inspire others, I first had to teach and inspire myself. You are looking at the result of that work.
I wanted to make the profound difference clear between a [technical blog](/post) and [essayistic works](/essays) by separating them in different categories, each with their own intention and language.

View File

@ -1,34 +0,0 @@
---
title: 'Drawing week 01 - pencil illustrations'
date: '2017-03-01'
subtitle: Gotta start somewhere...
tags:
- Teaching yourself to draw
published: true
---
Also read [Teaching yourself to draw](/post/teaching-yourself-to-draw/).
As you might already have read, I started the drawing adventure with a 10-week 'illustrative techniques' course. It sounds complicated but it wasn't really: it's more of a gentle introduction in different mediums (pencil, ink, acrylic paint, ...) than a crash course in drawing techniques. I didn't know then that to draw illustrations, you still have to be able to draw. (I'm reading "drawing at the right side of the brain" and I know better now). But still, thse drawings might be fun to look at or to compare to the other weeks.
{{< pin "308707749443972926" >}}
{{< pin "308707749443972958" >}}
{{< pin "308707749443972977" >}}
These are all random drawings I did between the lessons to get myself familiar with a pencil. That sounds awful, doesn't it? Who uses pencils anyway. The left scan contains some color: that's an experiment. The brown is **bistre**, something we had to work with in the second class. The other colors are very cheap **pastels**.
So, what did I learn this week:
1. Bistre can be a bit of a mess. You absolutely cannot wait, edges will form and it'll be worse than watercolor.
2. Expensive tools **are** better than cheap ones. Pastels are softer and contain a lot more pigment than the ones you can find in sale bins.
3. I know the difference between a **HB** and a **B4** pencil. I know how to sharpen one. Yay.
4. These drawings look like doodles because they are a lot like doodles. I like drawing that but I have the feeling I'm missing a lot background info (will be continued...)
5. Patience looks like an important skill to aid me in learning how to draw.
6. **Do not look at the work of others!**
I warned you:
{{< pin "568720259163636687" >}}
This also is bistre.
Ouch.

View File

@ -1,41 +0,0 @@
---
title: 'Drawing week 02 - Art before breakfast'
date: '2017-03-07'
subtitle: So ballpoint pens are useful after all
tags:
- Teaching yourself to draw
published: true
---
Also read [Teaching yourself to draw](/post/teaching-yourself-to-draw/).
After the illustration course, I'm not ashamed to admit I completely dropped the pencil out of the game. It creates lines easy to remove and that means I'm working on a drawing forever. I need something to commit myself to. That something is called ink.
It also seems that I already have stuff to get ink on a paper: pens. Ballpoint pens. Black, blue, whatever. Just simple pens you use to write with - the cheaper, the better. I came across **Danny Gregory**'s work [Art before breakfast](https://dannygregorysblog.com/books/art-before-breakfast/) and [The Creative Licence](http://www.dannygregory.com/author) (buy the latter one if you can). These are very inspirational books that get you kickstarted drawing from zero by learning how to see, explaning negative space and other simple techniques. It doesn't go into detail, it simply helps you get drawing.
And Danny is a fan of ink + watercolor. I immediately fell in love and knew that was what I wanted. So yes, put that pencil back where it belongs. I started trying to draw what I see:
{{< pin "308707749443972993" >}}
{{< pin "308707749443973015" >}}
{{< pin "308707749443973029" >}}
It looks a lot brighter than [week 1](/post/drawing-week-01). After drawing with a pen a few times, it felt better and better. I tried to copy Danny's style a bit by giving it some (water)color but that might be too much new stuff within a few weeks.
I'm particulary fond of the yellow post-it note: an impression of my left foot while waiting for my wife to finish shopping. I keep pen & paper with me at all times: that's a healthy habit I developed 7 years ago when starting journaling.
The first foot trace was a complete disaster by the way.
So, what did I learn this week:
1. Pen > pencil.
2. Danny Gregory rocks. He has tons of books and is co-founder of the [Sketchbook Skool](http://sketchbookskool.com/). Once I knew that, I enrolled in the "beginning" kourse.
3. I like sketching more than doodling.
4. "Seeing" is incredibly hard: I constantly mess up proportions.
5. Adding watercolor seems to add a lot of dimension.
Let's take a look at what Danny does:
{{< pin "381609768399365667" >}}
{{< pin "233976143118067754" >}}
Awesome.

View File

@ -1,34 +0,0 @@
---
title: 'Drawing week 03 - Fineliners and texture'
date: '2017-03-12'
subtitle: The fine discovery of Skillshare
tags:
- Teaching yourself to draw
published: true
---
Also read [Teaching yourself to draw](/post/teaching-yourself-to-draw/).
I wanted to continue my quest of finding my own style within ink and watercolor boundaries. After the amazing discovery of [Skillshare.com](https://www.skillshare.com), I switched to using Artline fineliners. I also have some Steadlers but hardly notice any difference between different felt tip pens if they have the same thickness. I found a short course by Shirish Deshpande on drawing with ink and creating some contrast and texture. The drawings in the videos are amazing and I tried to copy them to my best abilities:
{{< pin "308707749443973054" >}}
{{< pin "308707749443973073" >}}
{{< pin "308707749443973094" >}}
The ink flowing from a technical pen is much more intense than a standard ballpoint pen as seen in [week 2](/post/drawing-week-02). I like that a lot. It also enables me to be much more precise and that is something that I tend to do a lot. I usually draw (too) small and try to cram in as much details as possible. The thinner the felt tip pen, the better for me. (Although I borked a 005 one, those guys are very sensitive!).
During the snow & rose course, the lesson with the fineliners suited me the most, and now I have that same feeling. I finally give (cross-)hatching a shot and it really looks a lot better. Thanks Shirish, for building up my confidence in drawing with ink!
So, what did I learn this week:
1. Intensity of ink matters.
2. Contrast is extermely important and gives your drawing an "oomph"
3. I learned the "hatching", "stipling", and "random" technique.
4. Fineliners > ballpoint pens > pencils (sensing a trend here, fountain pen coming up)
Let's take a look at what Shirish does with his pens (and added colored ink):
{{< pin "394698354817739793" >}}
{{< pin "364299057333088725" >}}
He usually doesn't color with watercolor but with (diluted) colored ink. I have yet to try that.

View File

@ -1,42 +0,0 @@
---
title: 'Drawing week 04 - Using the brain'
date: '2017-05-09'
subtitle: Drawing at the right side of the brain
tags:
- Teaching yourself to draw
published: true
---
Also read [Teaching yourself to draw](/post/teaching-yourself-to-draw/).
As I'm slowly getting a tiny bit better at drawing things I see, I still don't have a fundamental basis to rely on. Until I've read "[Drawing at the right side of the brian](http://drawright.com/)" from Betty Edwards. Everything I've read in there came as a complete revelation to me. She explains how you should "look" at things, what is important to look out for when realisticly drawing and how values/tones work. It's an amazing book and I'm very glad I've added it to my toread list (a few years ago, I finally got around to actually reading it.)
Can you spot the difference between the portraits below?
{{< pin "308707749447642788" >}}
{{< pin "308707749447642793" >}}
Yes, I am well aware that the second portrait still looks like crap but come on, at least it shows highlights, it has a decent contour and my skull isn't "chopped off". Both drawings took me 45 minutes. I'd say that's a definitive improvement here.
Other exercises in the books concentrate on hands, interiour, chairs, ...:
{{< pin "308707749447642796" >}}
{{< pin "308707749447642801" >}}
Everything is done with a pencil. My preference is starting to lean towards 2B and 4B instead of HB.
So, what did I learn this week: (these are some quick oneliners that summarize each important chapter in the book)
1. Draw (shared) edges of stuff: call them contours.
2. Draw spaces between stuff: call it negative space.
3. Draw relationships between stuff: call them angles and proportions.
4. Draw lights and shadows on stuff: call them tonal differences.
5. Do not draw the appearance of stuff: call it "the gestalt".
The last point is an interesting one. It's also called "making it come together" and is usually achieved by simply focusing on the other 4 points.
Doing these exercises gave me a real boost in confidence and motivated me to draw even more. I even started enjoying the use of a pencil - soft shading is nice and not doable with a pen!
Read more on how to draw better in Jen Review's [How to Draw Better](https://www.jenreviews.com/how-to-draw-better/) blog post.

View File

@ -1,42 +0,0 @@
---
title: I'm jealous of my dog
date: '2017-08-17'
bigimg: /img/woef.jpg
subtitle: Getting rid of garbage in your head
tags:
- self improvement
published: true
---
My dog, Miel (yes, like the French word for honey. It's a Golden Retriever, get the link?), loves to walk. He also likes playing a lot, but as soon as I put on my shoes or get near the garden gate, he starts to freak out, thinking it's that time again. Since I have no idea what is going on in is head, I said "thinking", because we humans associate animals with our own behavior - because that's what we're familiar with. Have you ever walked a dog? Have you noticed the dog's "state of mind"? How would you notice such a thing? Pay attention to what your dog is doing and you'll know what I mean.
Miel is not thinking. He's walking. Sniffing. He's present in that very moment. <br/>
On the other hand, I'm pondering something that happened to me today. I might be distracted. After a few blocks, I might think "oh wow, now where was I". I might have missed the waving neighbor, the sunny weather or the absence of noisy cars. I am not present in that very moment at all - I'm either in the past ("why did that person say this to me") or in the future ("I need to do this and that and that after I get back"). Why is it so hard to be in the present, if Miel can do this so easily?
![Mind full-ness](/img/mindfull.jpg)
Image copyright socksofdoom
It seems that I'm [not the only one with that problem](https://trudymorgancole.wordpress.com/2014/03/02/dogs-walks-and-mindfulness/). After taking an eight week long mindfulness course, it seems that I'm still practicing mind-**full**ness instead of mindfulness. We humans are blessed and cursed with a thinking brain but luckily Buddhists have proven that it can be temporary shut down. There's only one way to achieve this state of mind: practice. I love reading about this subject and recently finished the extremely popular "[zen mind, beginners mind](https://www.goodreads.com/book/show/402843.Zen_Mind_Beginner_s_Mind)" by Shunryu Suzuki. It's a very practical book that explains the basics of Zen-Buddhism. One major recurring subject is practicing versus studying the philosophy behind Zen. The more you read and know things about Zen, the more poisoned your mind is. So start doing and stop reading.
Miel isn't the only "person" (whoops) that loves his daily walk. Ever since we got the dog, I too started to enjoy breaking out of my comfortable living room, doing the usual nothing. Dog walking gives me an excuse to get up and walk, and to try to be in the moment, to try to notice the weather, to smell the air, to feel the raindrops and to simply walk. Failing implies getting up and doing it again. When I catch myself thinking about something or worrying, I friendly but firmly redirect myself to the present: walking. Most of the times, Miel does this for me with a pull of the leach. In that sense, it could be a bit like meditating. That's one of the reasons I like drawing so much: I can't do anything else but to study the subject, and start laying done line per line. Study it more closely, start seeing details within details as Tommy Kane would say. I usually need a few minutes to get myself into that (drawing-) mode and that's one of the reasons I am having difficulties drawing in urban regions where a lot of people distract me.
In one of the lessons in the mindfulness course, we had to do a walking meditation. That implied focusing on the contact of the earth and your foot, feeling where you land each foot and concentrating on walking alone. I like to do this when I'm biking. You start to notice how your knee joints work, and where that heavy pushing on the petals is going when you cross a steep bridge. This sounds like it's easy but it's not: I'd say those moments are rare for me. I usually catch myself thinking stuff about my work when I'm biking to and from work a few minutes after attempting to concentrate on biking alone. But that's alright: I'm learning from my dog.
I'm grateful for my dog reminding me I need to "take a walk", to "clear my head". So why don't you clear your head when you're walking but fill it even more?
- Does it make you feel better?
- Are the problems resolved when pondering them at that time?
- Can't you focus on your dog instead of your "stuff"? He'd appreciate it.
![Multi tasking sucks](/img/multitaskingsucks.jpg)
Image copyright [privatebarking](https://www.privatebarking.com/puplifting-quotes-multitasking-sucks/)
The thinking most certainly still needs to be done but you'll make it yourself a lot easier if you think when you need to think and walk when you need to walk. It's called **single tasking** and we should all do it more often. The myth of multitasking that gets more work done is a very short sighted view on economical capitalism. Context switching costs precious time - even up to 20 minutes to get back into what you were doing. That is one of the main reasons you should not check your mail every hour but once in the morning and once in the evening. I'm starting to resent people who cling to their iPhones, instead of focus sing on the person in front of them. It's all part of the same problem.
If you're having trouble, remember this: if your dog is playing, it's playing, not playing and managing his backlog. If your dog is eating, it's eating, not playing with his ball next to his supper. So keep that cellphone off the dinner table and try to mimic his behavior. <br/>
I know this sounds easy, but it takes a lifetime to fully master. I still wake up most days with too much scrambled thoughts about what happened yesterday and what will happen today, having difficulties letting go of them. It's so easy to **get lost within your own thoughts** and it does have it's purpose to do a "thought walk" and mix and mash ideas to get to another one. But it's also vital that you have a working STOP button.
I have to stop typing and think about that for a moment now.
What was I saying?

View File

@ -1,58 +0,0 @@
---
title: Noise
date: '2017-10-24'
bigimg: /img/noise.jpg
subtitle: Getting rid of noise, part 2
tags:
- self improvement
published: true
---
The meanwhile common problem of [noise in your head](/post/i-am-jealous-of-my-dog/) has not been solved just yet. In fact, it has only gotten worse. A lot worse. The garbage thinking problem spread like a disease, clinging onto everything in it's way inside me. It has reached my ears and my mind. I'd like to make a distinction between "head" and "mind" as "head" might be a temporary problem, getting something to stick in your "mind" sounds a lot more definitive to me. Allow me to elaborate.
### Pollution in my ears
Are you also fed up with this noise generating world? The louder the better. You're only cool if you are able to stand the music beating your ears in your plugs at level 15 or higher. It's awesome to drill a hole in an exhaust pipe so your motor doesn't get unheard. Yelling usually provides you with the direct attention you need, whether at the checkout or in a meeting.
Does this sound familiar to you? I'm not even talking about people who are highly sensitive or introverts vs extroverts, but in general. Just, in general, at every single level. Getting to work makes my body take more decibels than it used to thanks to the increased traffic full of ignorant people who like to listen to the (loud) radio and have the comfort of a leather chair instead of a bike. The absurd concept of open work spaces makes my day at work barely productive. A beginning headache by 3h PM is normal. Shopping for groceries in a mall or supermarket doesn't make my day any better as the non stop stream of commercials rolls out of speakers and mounted televisions. The end of an exhausting day marks watching television because my wife thinks that's the best way to relax. Don't forget to crank up that volume, otherwise you won't be able to follow that quiz.
At last, in bed. I greet the ever present buzz inside my mind and sigh.
Something has to be done. And so I did:
1. When I'm driving, the radio is __always__ off. I love that bubble of silence.
2. Take your foot off the clutch if you have an engine that stops automatically at a red light. Ahhhh.
3. Get rid of everything that ticks and whirrs in your living room.
4. Bike around traffic even if that means a couple of minutes extra commute.
5. Try to use headphones that block out noise of others at work.
6. Turn off the TV.
7. Turn the TV back on after your wife gets angry.
8. Read somewhere else where there's no TV on.
9. Go back to the room with the TV because your wife is lonely.
The above has only seen partial success. Traffic is everywhere, you can't bike around it that easily. Thanks to the nature of my job, as a software engineer working inside teams, I'm constantly disturbed - headphones or not. However, we introduced a "silent period" of 1.5hrs twice a week in an attempt to reduce the general noise overhead. That does mean we need the cooperation of our colleagues...
### Pollution in my mind
Getting obsessed with something can prove to be dangerous too. Let's call it "unhealthy". When I get excited about something, like fountain pens or more recently my reintroduction into Magic: the Gathering, I can get a bit too obsessed with it. Searching for the perfect pen, watching videos, looking around for the better shop, reading about what others think and say. Looking at what cards are played at tournaments, thinking about strategies, trying out different combinations inside my head. That sounds innocent, but can cause me to put all other things to hold. Suddenly, I lose interest in other things I was a lot more interested in, in the first place. Biking from and to work happens pseudo-automatically, pondering the right combination of killer combo cards to put into my deck. Oh, did I pass this street already? How time flies.
My mind saves all ongoing progress of different stuff and loads up one single program: Magic.
That'll mean I'll probably dream about it and talk about it until everyone thinks I'm obsessed (at that point, I might very much well be).
Until something else comes along, Magic probably will get stored as ongoing progress and something else (completely) occupies my mind.
Sounds like mind-full-ness or mind-fool-ness to me. Every time I catch myself thinking "I should meditate more and try to clear my head", I end up surfing to some Magic-related website again. The cards or the game aren't the problem, but my occupation with those temporary things is. And I'm convinced the only solution will be to __slow down and take a deep breath__. The more I'm upset with something like the repetitiveness of my work, the more I delve into that ever ready stream of happy Magic-thoughts. Yay!
Less thinking, more being.
### Pollution in general
Think about the amount of images that burn in our retinas daily, the amount of unneeded refresh rates it has to take for your eyes to read a stupid Facebook page of a distant friend you're not even remotely interested in in the first place. The amount of things you have to do each day because they're part of a weird ritual made up by your local government or employer. The amount of noise you have to dig through in order to reach the data that is actually relevant to you in order to get your job done. The ridiculous amount of mails you send and receive each day because you think you have to or otherwise others won't find you that productive. The amount of times you have to say "I know what you mean" and "really? How cool!" to someone, when, in fact, that person is very irritating and you just want to go home. The amount of hours you spend watching a television show that could be spent walking your dog, drawing or reading instead.
The amount of hours you waste sitting in a chair thinking you could do something else right now. I might have a feeling of melancholy typing this, and you know that I might overreact, or not based on your situation, but you also know that time is better spent if you're in that very moment you're spending it. Maybe
Like bicycling instead of thinking about games. Or just trying to sincerely help others instead of complaining about noise and receiving positive feedback on your way out. Or actively engaging into a conversation when you're committing yourself to it instead of thinking about games. Or honestly saying that you're not interested and simply going home. That'll do.
I'm still (not) working on a solution to this problem.
<br/>I'll probably figure it out just before I die.

View File

@ -1,62 +0,0 @@
---
title: Teaching yourself to draw
date: '2017-02-01'
subtitle: A year of spilling lots of ink
tags:
- Teaching yourself to draw
published: true
---
Inspired by Noah Bradley's [Don't go to art school](https://medium.com/i-m-h-o/dont-go-to-art-school-138c5efd45e9#.aul09q3wr) blog at Medium.com.
Drawing and art in general has always been something I didn't quite grasp or try to understand. I was a software development guy, a technical guy, used to writing code, looking at text, spending days and years in text editors others call IDE's. Software development and art aren't that different actually: they both require an open mindset and an extreme creative approach at solving problems. That's one of the reasons I became interested in drawing.
Another is to get some color into my journals. I've been journaling for about 7 years now and it's been my most important tool in life. It helps me understand myself, collect and execute ideas and to keep the chaos in the world and my mind contained. Writing pages isn't a problem, doodling either, but the page never really pops. Sketching is something I like to do now and then but after hearing things like "you can't draw at all!" my motivation completely disappears.
### [How to really master a skill](http://www.makeuseof.com/tag/10000-hour-rule-wrong-really-master-skill/)?
* Deliberate practice
* Getting down the pyramid chain: <br/>teaching > practicing > group discussion > reading > lecture
* "10.000 hours" (it's an average, I know)
* Quantify yourself by using a **feedback loop**
### My Feedback loop is this very blog.
It should be that simple. I intent to learn to draw within a year, without enrolling in a traditional school. To be successful, I will turn to books, online courses, experts in art by visiting expo's/museums, experts in art by going to short term workshops, and above all: by lot's of practicing. Noah states that $10k could be spent wisely within one year. I have no idea how much it will cost me but my intention is to keep it as low as possible.
Each learning 'session' will be another blog post. I have a general idea on what I like (ink, watercolor, anything physical, journals) and what I don't like (acrylic paint, anything digital) but since there is so much I don't know, this might change during the course of the coming year. Since Pinterest is so inspiring I'd like to upload as much of the artwork as possible. Sharing via pins makes it easier for people to try it themselves.
Take a look at my Pinterest profile by clicking on the icon on the bottom of the page.
If you're looking for all blog posts about learning to draw, check out the **'[Teaching yourself to draw](/tags/teaching-yourself-to-draw/)' tag**.
Are you familiar with the frustrated feeling you get while visting an art supply store and staring at all the equipment but having no idea what does what? That's me. So, I figured...
### Start with the beginning.
[Snow&Rose workshop: Illustrative techniques](http://snow-and-rose.com/nl/workshop/) was my entrypoint. It's a 10-week (once a week) workshop to cover the basics of drawing illustrative creatures, flowers, landscape, anything. No realistic drawing, no up-front knowledge required and each week it covers another medium:
1. charcoal and pencil
2. bistre, reedpen
3. pastel
4. aquarel
5. acrylic paint
6. aquarellable colorpencils
7. ecoline
8. ink with fineliners
9. collage/scrapbooking
10. mixed media
Price is 390 EUR. As it's only once a week, it creates the perfect opportunity for me to practice drawing "stuff" between the lessons and to experiment a bit with the different mediums.
These are some christmas-themed cards I made with cheap pastels during the third lesson:
{{< pin "308707749442493529" >}}
{{< pin "308707749442493506" >}}
{{< pin "308707749442493510" >}}
It starts out very simple, as you can see. I'm still having difficulties buying the right equipment. The pastels used above are very hard and grainy, and don't contain a lot of pigment. That is clearly visible in the gameboy one on the far left: the brown paper shouldn't be that visible. Small steps, small steps...
### But I suck at drawing!
So do I.
Each week (this sounds like a promise I'll have to make to myself) I'll post a new blog post summarizing what I've learned about drawing, art ant painting. Hopefully, after 52 posts, others who are thinking about making the step won't be that intimidated as I am right now. I've already felt that looking too much at work of others (in Pinterest for example) completely demotivates me. You'll always find someone who completely outperforms you. It's not about their work, it's about your own, and **the progress you make**, however small that might be. If it's going forward, it's going forward. There is no hardwired limit on where to go to. Let's just keep on trying, failing, getting up and trying again! It looks like 2017 is going to be an interesting year for me.

8
content/tags/_index.md Normal file
View File

@ -0,0 +1,8 @@
---
title: Tags
icontag: fa-tags
---
> The good life is one inspired by love and guided by knowledge. - Russell
Not finding what you're looking for? Behold a list of alphabetically sorted tags used in every article on this very website. Related articles share a set of tags.

View File

@ -2,11 +2,11 @@
aliases = [
"/talks/"
]
title = "Teaching"
icontag = "fa-graduation-cap"
+++
# Teaching
#### 2018
- [Software design in Java](https://www.uhasselt.be/documents/BROCHURES/2018-2019/Masterflyer-Elektronica-ICT-2018-web.pdf), KULeuven &amp; UHasselt industrial engineering<br/>

View File

@ -1,13 +0,0 @@
+++
title = "__template"
draft = false
tags = [
"__template"
]
date = "2013-03-12"
+++
# @NS@ >> @!PAGE@
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>

View File

@ -1,12 +0,0 @@
+++
title = "appendix"
draft = false
tags = [
"appendix"
]
date = "2013-03-12"
+++
~~NOTOC~~
<img style='' src='/img/alphaindex>|'>

View File

@ -1,20 +0,0 @@
+++
title = "home"
draft = false
tags = [
"books",
"home"
]
date = "2013-03-12"
+++
# books >> Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>
## Links
#### Online digitale resources
* http:*www.scribd.com/ (bvb [jQuery novice to Ninja](http:*www.scribd.com/doc/36486402/jQuery-novice-to-Ninja)) (betalend)

View File

@ -1,26 +0,0 @@
+++
title = "ddd"
draft = false
tags = [
"books",
"ddd"
]
date = "2013-03-12"
+++
# Domain Driven Design
## Samenvatting
[Zie Kristof's Wiki](http://www.butskri.comuf.com/wiki/doku.php?id=boeken:ddd)
## Top reasons Why DDD Fails
Schema's gebaseerd op conferentie: http://architects.dzone.com/advice-for-ddd
Klik op images om te vergroten.
<img style='margin-left: auto; margin-right: auto; width: 400px;' src='/img//books/whydddfails_1.jpg'>
Deel twee:
<img style='margin-left: auto; margin-right: auto; width: 400px;' src='/img//books/whydddfails_2.jpg'>

View File

@ -1,103 +0,0 @@
+++
title = "dont_make_me_think"
draft = false
tags = [
"books",
"dont_make_me_think"
]
date = "2013-03-12"
+++
# Don't Make me Think
Author: Steve Krug<br/><br/>
Subtitle: A common sense approach to Web usability (SE)
[Librarything link](http://www.librarything.com/work/12322)
#### 1. Don't make me Think
> If something is hard to use, I just don't use it as much.
Duidelijkheid is belangrijker bij een website overzicht dan iets wat denkwerk vereist - vandaar de titel van het boek. Niet moeten nadenken *hoe* exact iets gebruikt moet worden, maar iets als vanzelfsprekend aanzien.
#### 2. How we really use the Web
Niemand leest een hele webpagina, men scant sommige tekst blokken en werpt een snelle "blik" op elke pagina. <br/><br/> Facts of life:
1. We don't read pages, we scan them.
2. We don't make optimal choices, we satisfice. (We klikken niet altijd op de beste link maar de meest aannemelijke)
3. We don't figure out how things work, we muddle through. (Als we iets vinden dat werkt, blijven we dit gebruiken)
#### 3. Billboard design 101
1. Maak een duidelijke visuele hiërarchie op de website:
* Hoe belangrijker iets, hoe meer aanwezig (groter lettertype bvb)
* dingen die logischerwijze samenhoren ook effectief samen plaatsen (menu groepen)
* Visueel dingen "nesten"
2. Gebruik conventies in plaats van alles opnieuw uit te vinden.
3. Maak duidelijk wat klikbaar is
4. Vermijd een te "drukke" website (door bvb te veel borders rond menu's te plaatsen)
#### 5. Omit needless words
> Vigorous writing is concise. A sentence should contain no unnecessary words, a paragraph no unnecessary sentences, for the same reason that a drawing should have no unnecessary lines and a machine no unnecessary parts. ((William Strunk Jr. and E.B. White, *The elements of style*))
* Happy talk must die (welkom op onze blablabla website die blablablayawn doet)
* Instructions must die (klik hier en volg stap 1 tot en met 224 blabla)
#### 6. Street signs and Breadcrumbs
> People won't use your website if they can't find their way around it.
Vergelijk op een website iets zoeken met in een warenhuis iets zoeken. Je kan ofwel "browsen" door te navigeren met plaatjes in de rijen, ofwel direct aan personeel vragen waar object x ligt. Als je na een tijdje nog altijd niet gevonden hebt wat je zoekt verlaat je de winkel. Plaats daarom een zoek formulier zo zichtbaar mogelijk, en zorg voor correcte en duidelijke navigatie.
Extra problemen met internet browsen: we hebben geen idee van schaalbaarheid, geen idee van directie of locatie... Een website zou 5 basis elementen altijd aanwezig moeten hebben:
1. Site ID (linksboven, kan op een homepage meer plaats innemen)
2. Een manier om naar de homepage te gaan (buiten klikken op het logo)
3. Een manier om te zoeken
4. "Utilities" (basis links zoals hoe x doen)
5. Secties (de navigatie)
De homepage is hierop een uitzondering (zie volgend stuk)<br/><br/>
Pagina benaming is ook heel belangrijk: consistent, op de juiste plaats en altijd aanwezig.
##### Navigatie
"You are here" -> breadcrumbs (best bovenaan te plaatsen)
* Altijd bovenaan plaatsen
* Gebruik &gt; tussen levels in
* Gebruik een kleiner lettertype
* Gebruik "you are here" prefix
* Zet laatste item in bold (huidige pagina dus)
* Dit is geen vervanging voor een volledige pagina naam!
Tabs als navigatie
* Leggen zichzelf uit
* Moeilijk om te missen
* Mooi met de juiste style (evt JS)
* Ze stellen een fysieke fichebak voor (geven de illusie dat een actieve tab "naar voren" komt, met extra contrast)
#### 7. Home Page
De homepage zou voor de volgende zaken moeten zorgen:
* Site identiteit, missie (waar dient de site voor?)
* Site hiërarchie (wat kan ik hier vinden? Wat doe ik hier?)
* Zoeken!
* Stukjes om te *teasen*, content promo (stukken van een artikel, tijd-gerelateerde content)
* Promotie, reclame deals, ...
* Snelkoppelingen naar bepaalde (belangrijkere) secties buiten de navigatie om
* Registratie indien nodig
Aangezien iedereen iets anders zoekt op een website, maar er slechts één homepage is, moet deze zo robuust mogelijk gemaakt worden zodat alle surfers specifiek voor hun voldoende informatie kunnen verzamelen om te beslissen of ze op de juiste pagina zitten of niet, en dan eventueel over te gaan naar zoeken of navigatie zelf.
Het moet duidelijk zijn vanaf de home page wat de site doet, wat ze te bieden heeft, en ook wat niet! Gebruik hiervoor als hulp een **tagline**.
Home page navigatie kan uniek zijn ten opzichte van de rest van de webpagina. Het logo kan bijvoorbeeld ook groter en duidelijker aanwezig zijn. Het is wel de bedoeling dat alles consistent samen loopt.
Vermijd overmatig gebruik van comboboxen, zeker als navigatie! (Of pulldown menu's). Ze verbergen de eigenlijke menu items, zijn snel onoverzichtelijk en moelijk om te scannen voor onze ogen.

View File

@ -1,168 +0,0 @@
+++
title = "getting_real"
draft = false
tags = [
"books",
"getting_real"
]
date = "2013-03-12"
+++
# Getting real
http://gettingreal.37signals.com/toc.php
#### The Starting Line
1. Build Less ("underdo your competetion")
2. What's your problem? (Stratch your own itch, zie Rework, "born out of necessity")
3. Fund Yourself
4. Fix Time and Budget, Flex Scope
5. Have an Enemy ("Figure out your app's enemy and use it as a motivator to what it shouldn't be)
6. It shouldn't be a Chore (your passion, or lack thereof, shines through)
> How does a project get to be a year behind schedule? One day at a time. (Fred Brooks)
#### Stay Lean
Agile reclame...
1. Less Mass
2. Lower your Cost of Change
3. The Three Musketeers ("use only three people")
4. Embrace Constraints ("let limitations guide you to creative solutions")
5. Be Yourself
> Differentiate yourself from bigger companies by being personal and friendly.
#### Priorities
1. What's the big Idea (Define the **one-point vision** for your app) -> elevator pitch, 140chars tweet?
2. Ignore details Early on
3. It's a problem when it's a problem
4. Hire the Right Customers
5. Scale Later
6. Make Opinionated software
#### Feature Selection
> **Take whatever you think your product should be and cut it in half**. Pare featuers down until you're left with only the most essential version. Then do it again.
1. Half, not half-assed
2. It just doesn't matter
3. Start with No (make featuers work hard to be implemented)
4. Hidden Costs
5. Can you Handle it? (build something you can handle, not because the competitor also does it)
6. Human solutions (build software for **general concepts** to let people create their own solutions)
7. Forget Feature Requests
8. Hold the Mayo (ask people what they don't want)
#### Process
Impliciete XP reclame...
1. Race the Running Software
2. Rinse and Repeat
3. From Idea to Implementation (brainstorm - paper sketches - HTML screens/CSS mockups - code it)
4. Avoid Preferences
5. "done"!
6. Test in the Wild
7. Shrink your Time
> Decide on the little details so your customers don't have to.
Bvb. maak gewoon 50 units per tabel ipv daar een `property` van te maken.
:exclamation: **Be an executioner**:
> It's so funny when I hear people being so protective of ideas (they want me to sign an NDA to tell me the simplest idea). To me, ideas are worth nothing unless executed. They are just a multiplier. Execution is worth millions. Weak idea ###### 1. Good idea 10. No execution ###### $1. Weak execution $1000. (Derek Sivers)
#### The Organisation
Impliciete scrum team reclame... (Niet UI en backend team, generalists > specialists etc)<br/><br/>
Bijna zelfde stuff als [books/rework]({{< relref "wiki/books/rework.md" >}})?
1. Unity
2. Alone Time (people need uninterrupted time to get things done) vb make half the day "alone time"
3. Meetings are Toxic
4. Seek and Celebrate Small Victories (release something today, 4hour quick wins)
#### Staffing
1. Hire Less & later
2. Kick the Tires
3. Actions, not words
4. Get well rounded individuals
5. You can't fake enthousiasm
6. Wordsmiths (hire good writers)
#### Interface Design
> Another reason to design first is that **the interface is your product**. What people see is what you're selling. If you just slap an interface on at the end, the gaps will show.
1. Interface First
2. [Epicenter design](http://gettingreal.37signals.com/ch09_Epicenter_Design.php)
3. Three State solution
4. The Blank Slate
5. Get Defensive (design for when things go wrong)
6. Context over consistency
7. Copywriting is interface design (every letter matters! Karel stijl)
8. One Interface (incorporate admin functions into the main site design)
#### Code
Impliciete XP practices reclame...
1. Less Software
2. Opinionize for happiness
3. Code Speaks
4. Manage Debt
5. Open Doors (get data out to the world via RSS, APIs etc)
> A happy programmer is a productive programmer. **Choose tools that keep your team excited and motivated**.
#### Words
1. There's nothing functional about a functional spec
2. Don't do dead documents
3. tell me a quick story
4. use real words
5. personify your product
#### Pricing and Signup
1. Free Samples
2. Easy On, Easy off
3. Silly Rabbit, tricks are for kids
4. A Softer Bullet
#### Promotion
1. Hollywood launch
2. A powerful promo site
3. ride the blog wave
4. solicit early
5. promote through education
6. feature food
7. track your logs
8. inline upsell
9. name hook
#### Support
1. Feel the pain
2. Zero Training
3. Answer Quick
4. Through Love
5. In Fine Forum
6. Publicize your Screwups
#### Post-Launch
1. One Month Tuneup
2. Keep the Posts Coming
3. Better, not Beta
4. All Bugs are not created equal
5. Ride Out the storm
6. Keep Up with the Joneses
7. Beware the Bloat Monster
8. Go with the flow

View File

@ -1,166 +0,0 @@
+++
title = "inspiraties"
draft = false
tags = [
"books",
"inspiraties"
]
date = "2014-03-06"
+++
# Inspirerende Boeken
### Specifieke skills/Organisatorisch
##### Switch
{{< lib "Switch: How to Change Things When Change Is Hard" >}}
> "Inability to change is not lazyness but simply exhaustion". Self control is an exhaustable resource! Spreek zowel de 'olifant' (emotioneel, feeling, smelling) aan als de 'rider' (thinking, reflecting, planning) om mensen te overtuigen.
Komen gelijkenissen in terug van het "director on stage" concept van "Your Brain at Work".
##### Purple Cow: Transform Your Business by Being Remarkable
{{< lib "Purple Cow: Transform Your Business by Being Remarkable" >}}
> Het grootste probleem van bedrijven is angst. Durf net in deze tijden wél opmerkelijk te zijn! Het is niet erg om kritiek te krijgen, het valt net extra op. Een "Opmerkelijk" idee is beter dan een "heel goed" idee!
##### Presentation Zen
{{< lib "Presentation Zen" >}}
> Minder, eenvoudiger, duidelijker en doelmatiger slides opbouwen en presenteren is beter dan meer, gedetailleerder en ingewikkelder slides opbouwen en presenteren.
##### Rework
{{< lib "Rework" >}}
> o.a. "Scratch your own Itch": ontwikkel software voor uw eigen noden en breng het dan naar buiten: zo hecht je veel meer aandacht aan de kwaliteit.
##### Team Geek
{{< lib "Team Geek" >}}
> "Software development is a team sport". Show respect (is there anything you need?), trust (mission statements) & humility (admitting to making mistakes) to yourself, your team, your collaborators, the organization and your users.
En ook: *underpromise, overdeliver.*
##### Peopleware
{{< lib "Peopleware" >}}
> "The fundamental response to change is not logical but emotional!" en ook dit: managing = het team afschermen van interrupts en volledig hun gang laten gaan. Een Manager is nooit "lid" van het team maar zorgt ervoor dat een groep mensen tot een team omgevormd kan worden door diezelfde mensen zelf hun eigen skills te laten ontplooien!
### Self Improvement
##### Search Inside Yourself
{{< lib "Search Inside Yourself" >}}
> Save the world and increase your humble Emotional Intelligence by breathing mindful a few minutes a day.
##### Yes-but, what if everything works out?
{{< lib "Ja-maar wat als alles lukt ?" >}}
> The true voyage of discovery is not in the looking for new landscape, but in looking with different eyes. (Marcel Proust, p73)
Stop met ja-maar te zeggen en begin met ja-en te zeggen. Kijk naar problemen met een andere blik, die nieuwe mogelijkheiden aanbiedt. (Zie Power Thinking). Durf verlangens te hebben (een "vraag gevoel", kan soms 20j duren voor het concreet wordt), banale verlangens hebben ook een positief effect. Focus op wat je wél kan en verbeter dat, in plaats van af te geven op wat je minder kan en dat proberen te verbeteren.
##### The art & Science of remembering everything
{{< lib "Moonwalking with Einstein: The Art and Science of Remembering Everything" >}}
> Monotomy collapses time. Novelty unfolds it. (Michel Siffre, nieuwe ervaringen geven psychologisch de tijdsindruk dat alles sneller gaat)
Onthouden door middel van trucjes (het "geheugenpaleis" e.a.) kan iedereen, ook iemand die niet "intelligent" is. Spreek het holistisch deel van uw hersenen aan, dat nog niet hiervoor getraind is, dus het kan even (tot een jaar) duren. Het aantal dingen dat iemand max. kan onthouden zonder is zelfs lager dan het mythisch cijfer 7.
##### Quiet
{{< lib "Quiet: The Power of Introverts in a World That Can't Stop Talking" >}}
> It's not that I'm smarter, it's that I stick with problems longer. (A. Einstein)
Introverten hebben veel meer focus en persistence, maar zijn sneller angstig dan bored, hebben minder prikkels nodig. Kunnen zich als extraverten gedragen maar dat vergt veel energie, zorg voor relax spots! Zoek meer balans voor beide persoonlijkheden.
#### Zelf-hulp
##### Power Thinking
{{< lib "Learn to Power Think" >}}
> Blik regematig terug op uw eigen leven, stuur bij, sta open voor nieuwe zaken, wijk af en leer anderen kennen, schrijf op wat je voelt.
##### Het heeft Zin
[Els De Schepper - Het heeft Zin](http://www.elsdeschepper.be/boeken/zin/)
> Één grote bevestiging dat reapprisal dé meest kritieke skill is om het leven positief door te komen: bekijk niet alles met uw kortzichtige vooroordelen maar sta toe dat anderen niet dezelfde mening hebben als jou!
#### Gedragstherorie
##### Slaap Lekker
{{< lib "Dreamland: Adventures in the Strange Science of Sleep" >}}
> Tijdens R.E.M. gedeelte van onze slaap zijn de hersenen nog superactief, het is belangrijk om dan op ideeën te kunnen komen. Logische dingen worden onsamenhangend terug doorlopen zonder diepere betekenis.
Ons bioritme volgt de zon, licht is de grootste boosdoener van slaapgebrek van de moderne tijd. Probeer een halfuur tot een uur op voorhand niet meer naar verlichtende schermen te staren! Ontspannen daarvoor werkt ook. Afkoeling is ook belangrijk.
##### Where good Ideas come From
{{< lib "Where good ideas come from" >}}
> De beste ideeën worden jarenlang met zorg uitgebroed en gerealiseerd door andere gelijkaardige mogelijkheden, in de juiste omgeving te ontspruiten en genoeg ruimte te laten om fouten te kunnen en durven maken.
##### Mojo
{{< lib "Mojo how to get it|Mojo" >}}
> Mojo is de positieve uitstraling waarmee we nu iets doen die vanbinnen komt en naarbuiten uitstraalt. Optimism is fuel for change!
##### Your brain at Work
{{< lib "Your brain at Work" >}}
> Merk het gedrag van uw eigen brein op en stel uzelf in staat dit te veranderen, gegeven de kennis over de interne werking van uzelf.
##### Getting Things Done
{{< lib "Getting Things Done" >}}
> Speel véél sneller in op projecten en todo's door een efficiënte manier op te bouwen om direct gedachtes, ideeën en dingen neer te schrijven en wekelijks bij te werken.
##### Pragmatic Thinking & Learning
{{< lib "Pragmatic Thinking & Learning" >}}
> Activeer uw heel brein (L en R mode) door hersenspinsels neer te schrijven, mind maps te tekenen, gedachtenwandelingen te maken, en overal papier dichtbij te hebben.
##### Blink
{{< lib "Blink" >}}
> Leer ook te vertrouwen op uw intuïtie die constant oordelen velt zonder dat je je ervan bewust bent. Combineer dit met logisch denken, en regaeer dan pas!
##### Outliers
{{< lib "Outliers: The Story of Success" >}}
> Succesvolle mensen bouwen succes niet vanaf 0 op: culturele erfenis speelt een enorme rol, samen met het juiste "moment" waarop je je idee de wereld in wil brengen.
### Computer Related
##### Don't make me Think
{{< lib "Don't make me Think" >}}
> Eenduidige en eenvoudige navigatie is van extreem belang om mensen aandacht te laten vestigen op uw website.
### Environmental
##### The story of Stuff
{{< lib "The story of Stuff" >}}
> Reduce, reuse, and then recycle! Plastiek is énorm giftig en deze stoffen zitten reeds in ongeboren baby's!

View File

@ -1,183 +0,0 @@
+++
title = "mojo"
draft = false
tags = [
"books",
"mojo"
]
date = "2013-03-12"
+++
# Mojo
Auteur: Marshall Goldsmith<br/><br/>
{{< lib "Mojo how to get it|Librarything link" >}}
> Het is beter te springen dan geduwd te worden.
1. Marshall Goldsmith
### Jij en je Mojo
##### Wat is mojo?
De **positieve instelling**<br/><br/>
Waarmee we **nu iets doen**<br/><br/>
wat **van binnenuit** komt, <br/><br/>
en **naar buiten uitstraalt**.
##### Jou Mojo meten
Door middel van 2 pijlers:
* Professionele Mojo*
* Motivatie
* Kennis
* Kunde
* Zelfvertrouwen
* Oprechtheid
* Persoonlijke Mojo*
* Geluk
* Beloning
* Betekenis
* Lessen
* Dankbaarheid
Zie http://www.mojothebook.com/about-mojo-book/ voor de persoonlijke mojo score kaart in te vullen en details over elke pijler.
### De mojo-paradox
Onze standaardhouding in het leven is niet om *geluk* (korte termijn) of *betekenis* (lange termijn) te ervaren.<br/><br/>
Onze standaardhouding in het leven is om *inert* ((Embrace change hé)) te zijn.
Vraag u altijd af, op het einde van een dag bijvoorbeeld, bij *alle activiteiten* die je gedaan hebt:
1. Hoeveel voordeel of betekenis op lange termijn heb ik hiermee ervaren?
2. Hoeveel bevrediging of geluk op korte termijn heb ik hiermee ervaren?
De kracht van deze oefening is **zelfevaluatie**! Het vereist doorzettingsvermogen om dingen te veranderen.
> Ik ben wakker.
*- Boeddha*
### Ingrediënten van Mojo
#### Identiteit
1. Herinnerde identiteit: we bouwen verder op onszelf door ons activiteiten te herinneren van hoe we waren.
2. Weerspiegelde identiteit: Andere mensen herinneren zich gebeurtenissen over ons in het verleden.
3. Geprogrammeerde identiteit: Boodschappen die andere mensen uitzenden over wie je bent of wie je zult worden ((Brainwash stijl. Opvoeding, omgeving, werkdruk, ...))
4. Gecreëerde identiteit: waar we in de toekomst aan onszelf gaan werken
#### Presentatie
Pas op voor de **kloof tussen definities van prestaties** - tussen die van u en van anderen. Dit kan uw eigen mojo potentiëel negatief beïnvloeden.
De vraag "*Wat heb jij de laatste tijd bereikt?*" wordt vaak in ons gezicht gesmeerd, en we liegen meestal ook - doordat mensen hun eigen prestaties overschatten. Mensen denken vaak dat ze beter dan de gemiddelde persoon zijn.
#### Reputatie
*Wie denken mensen dat je bent?*. Ben je liever slim dan doeltreffend? Wil je gezien worden als iemand die dingen gedaan krijgt (doeltreffend) of als iemand die enorm goed formules kan bedenken maar er nooit iets mee doet?
Om een reputatie op te bouwen dien je je acties voldoende te **herhalen**. Het roer volledig omgooien stuurt de eerste 2-3 keer een volledig *verkeerd signaal* uit naar mensen die je vorige gedrag gewoon zijn. Mensen met een sterke mojo zijn een kei in het herhalen en na een tijd nemen mensen aan dat die persoon zo is.
#### Aanvaarding
**Leer loslaten**! Zie your brain @ work.
### Mojo-killers
1. Te veel hooi op de vork (leer nee zeggen!)
2. Wachten tot feiten veranderen (handel nu!)
3. Logica zoeken op de verkeerde plaatsen (probeer niet altijd alles te linken en er over na te denken!)
4. Klagen over de baas (zie aanvaarding)
5. Niet willen veranderen vanwege *sunk costs*
6. Vergeten in welke modus we zitten (val niet uit je "werk" rol als het te ontspannen bij collega's wordt)
> Verander jezelf of verander het
2. *Marshall Goldsmith*
### Identiteit: helder krijgen wie je bent
<img style='float: left; width: direct&500|px;' src='/img//books/mojo.jpg'>
#### Tool 1: bepaal welke maatstaven voor jou belangrijk zijn
Geen duidelijke doelen hebben, niet precies zijn, ... Allemaal killers.
Bepaal zelf wat jij belangrijk vindt en handel daarnaar.
#### Tool 2: zoek uit waar je woont
T.o.v. betekenis en geluk en onze dagelijkse activiteiten.
Zie http://www.mojothebook.com/about-mojo-book/ en de "mojo study" voor de mojo enquête. (zie image)
#### Tool 3: Wees de optimist van het stel
Optimisme is aanstekelijk. En belangrijker nog:
> Optimisme is brandstof voor verandering
2. *Marshall Goldsmith*
#### Tool 4: schrap één ding
Denk eens na over het dagelijks leven en schrap één essentiëel ding hiervan. Hoe zou jij je leven verder zetten zonder dat éne?
### Prestatie: maak het makkelijker om dingen gedaan te krijgen
#### Tool 5: bouw op met één steen tegelijk
> Een stapje met een keer!
1. *Bart Gauquie*
Vergeet niet 2 keer nee te zeggen en dán een keer ja.
#### Tool 6: beleef je missie ook in kleine momenten
Blijf met uw "missie" of groot doel in het achterhoofd handelen, ook op momenten waar je het niet verwacht, kleine dingen die grotere veranderingen teweeg brengen, kan het énorm handig zijn.
#### Tool 7: zwem in blauw water
Als de concurrentie te groot is (de vijver is al vol), schakel dan over naar een andere! Wees creatief!
### Reputatie: jouw eigen verhaal in handen nemen
#### Tool 8: wanneer blijven, wanneer weggaan
Gebruik bvb. de mojo scorekaart om te beslissen wat je wil veranderen aan je leven, of om die extra push te krijgen.
Vergeet niet dat zelf beslissen altijd beter is dan die door iemand anders te laten maken!
#### Tool 9: afscheid nemen
Weggaan doe je **altijd in stijl**. Punt aan de lijn.
#### Tool 10: gebruik een statistiek
Reclame voor mojoness...
#### Tool 11: verlaag dat percentage
*Welk percentage* van alle onderliggende communicatietijd wordt besteed aan
1. mensen die vertellen hoe slim, geweldig ze wel niet zijn of die luisteren naar iemand die dat doet of
2. mensen die vertellen hoe stom of ongeschikt iemand wel niet is, of die luisteren naar iemand die dat doet
Het antwoord is **65%**!
### Aanvaarding: verander wat je kunt veranderen, laat los wat je niet kunt veranderen
#### Tool 12: gebruik jouw invloed ook naar boven
Met name als verkoper trucjes ook toepassen op "de baas" om dingen gedaan te krijgen.
#### Tool 13: benoem het en beheers het
Zie your brain @ work
#### Tool 14: geef je vrienden een vrijbrief voor het leven
Het sleutelwoord is hier **vergeving**.

View File

@ -1,295 +0,0 @@
+++
title = "presentation_zen"
draft = false
tags = [
"books",
"presentation_zen"
]
date = "2013-03-12"
+++
# Presentation Zen
Auteur: Garr Reynolds<br/><br/>
{{< lib "presentation zen|Librarything link" >}}
Leonardo da Vinci:
> Eenvoud is de ultime perfectie
### Presenteren in de wereld van Vandaag
Algemeen idee:
* Teveel tekst in PowerPoint presentaties. Mensen nemen het niet op en raken er niet door geboeid. Resultaat: iedereen geeuwt en valt in slaap
* Bouw uw presentatie rond een geloofwaardig verhaal op met de nodige humor. Hou de slides als verduidelijking maar laat ze **niet** op zichzelf staan!
* Hou het kort. Bedenk wat dé boodschap is om over te brengen. Stel uzelf in plaats van de kijker. Maak het duidelijk, spreek met klare taal.
* Gebruik images om uw verhaal aan te sterken: mensen herinneren hun beter het doel afhankelijk van iets visueel. Maak daar gebruik van.
#### Opbouw presentaties in het conceptuele tijdperk
Bron: {{< lib "A whole new Mind" >}} van Daniel Pink. <br/><br/>
Zowel met L- als R geheugen leren werken in de nieuwe wereld, en de volgende "high touch" talenten spelen hierbij van groot belang:
##### 1. Ontwerp
1. Nooit bewust door de kijker laten opmerken
2. Handig gebruik maken van bijvoorbeeld de 1/3de regel in de fotografiewereld om iets in beeld te brengen
3. Hou rekening met contrast
4. Denk aan eenvoud: 1 of 2 plaatjes is voldoende, met maximum enkele woorden tekst.
##### 2. Verhaal
Feiten zijn in overvloed beschikbaar in deze informatieve wereld, een verhaal hierrond brengen wordt nauwelijks gedaan.
Studenten:
> *De effectiefste docenten zijn echter degenen die ware verhalen vertellen. Niet simpelweg de stof behandelen, maar er persoonlijkheid, karakter en ervarnig doorweven! *
##### 3. Symfonie
*"Het vermogen om schijnbaar niet-verwante stukjes te gebruiken om het totaalbeeld te vormen en te uiten"*
De beste presentatoren kunnen verbanden leggen die we misschien nog niet eerder legden. <br/><br/>
Zodra iemand op iets gewezen wordt, begrijpt hij ook effectief de stof (once you see it...)
1. Symfonie behelst dat we beslissen wat van belang is en de rest loslaten!
2. Betrekking op het gebruik van de héle geest (logica, analyse, synthese en intuïtie) om ons onderwerp zin te geven
##### 4. Empathie
1. U inleven in de kijkers om uw boodschap duidelijker en eenvoudiger naar voren te brengen
2. Nonverbale aanwijzingen van anderen leren begrijpen
##### 5. Spel
Bij veel praatjes kunnen speelsheid en humor er aanzienlijk toe bijdrage om een presentatie beter verteerbaar te maken. <br/><br/>
Dus niet presentaties lelijk, ingewikkeld en zo gedetailleerd mogelijk maken maar aantrekkelijk, eenvoudig en duidelijk!
##### 6. Betekenis
1. Iets nieuws onderwijzen dat zín heeft
2. Een "bijdrage" maken aan uw eigen wereld of alles rondom u. Mensen die naar uw presentatie luisterden die het zinloos vonden worden vaak gefrustreerd.
### Creativiteit en werken met Beperkingen
##### Begin met de kijk van een beginner
Quote van Zen meesters' "blik van een kind": fris, enthousiast, eindeloze mogelijkheden van ideeën en oplossingen<br/><br/>
Shunryu Suzuki:
> In de ogen van een beginner zijn er talloze mogelijkheden, in de ogen van een deskundige slechts een paar
##### U bent creatief
U bent altijd **creatief**!<br/><br/>
Ontdek dit in uzelf met {{< lib "If you want to Write" >}} van Brenda Ueland. Het boek had net zo goed "als u creatief wilt zijn" kunnen heten en is voor alle professionals die iemand iets willen bijleren essentiële leerstof.
Sir Ken Robinson (TED 2006):
> Als u niet bereid bent om fouten te maken, zult u nooit iets origineels bedenken.
##### De kunst om met beperkingen te werken
Met restricties werken wil niet zeggen dat het onmogelijk is om op een geweldig idee te komen!
T.S. Eliot:
> Binnen een strikt kader gedwonen wordt de verbeelding het zwaarst op de proef gesteld en zal hij haar rijkste ideeën produceren. Bij totale vrijheid gaat het werk algauw alle kanten op.
1. *Beperkingen zijn een krachtige bondgenoot in plaats van een vijand*!
2. Het is vaak van groot belang om uzelf beperkingen op te leggen om goed en creatief te kunnen werken.
Bijvoorbeeld: **[Pecha-kucha](http://www.pecha-kucha.org)** presentaties: 20 slides, 20 seconden elk = 6min40
### Analoog plannen
Benadrukken van het belang om weg van de computer te plannen. <br/><br/>
Als je ideeën hebt, kun je zonder machinerie veel doen. Zodra je die ideeën eenmaal hebt, begint de machinerie voor je te werken... Bij de meeste ideeën heb je niet meer nodig dan een stok in het zand.
:exclamation: Merk hier ook weer de agile software engineering/Getting Things done gelijkenissen op:
1. Noteer direct alles wat in je op komt (dus niet "who's got a good idea", zie GTD)
2. Braindump, mindmapping, ...
3. Werk met post-its op een bord om makkelijker te kunnen organiseren
4. Vaart minderen om het geheel te overzien: zie project planning bij GTD en de verschillende niveau's
##### De behoefte aan eenzaamheid
Dr. Ester Bucholz:
> Anderen inspireren ons, informatie voedt ons en oefneing doet ons beter presteren. Maar daarnaast hebben we rust nodig om dingen uit te zoeken, neiuwe ontdekkingen aan te dragen en originele antwoorden te bedenken.
Perioden van eenzaamheid zijn belangrijk om ons creatieve vermogen an te boren!
##### De juiste en verkeerde vragen stellen
Niet focussen op inhoud of te ver voorlopen op de feiten, gas terugnemen en eerst de volgende vragen beantwoorden:
* Hoeveel tijd heb ik?
* Hoe ziet de zaal er uit?
* Op welk tijdstip van de dag vindt mijn presentatie plaats?
* Wie zijn de toeschouwers, wat is hun achtergrond?
* Wat verwachten ze van de presentatie?
* Wat wil ik dat ze doen?
* Waarom hebben ze me gevraagd om te spreken?
* Wat is hét doel van mijn praatje? Welk verhaal hoort hierbij?
* **Wat is mijn absoluut centrale stelling**?
Komt eropneer: 1) wat wil ik zeggen 2) waarom is dat belangrijk.<br/><br/>
Twee dingen kunnen u daarbij helpen:
1. "Dakari Nani" (wat dan nog?) - constant uzelf vragen "wat wil je daarmee zeggen" tijdens voorbereiding
2. De lifttest: Tussen naar lift gaan en naar garage gaan voor auto moet je je doel verkocht krijgen aan een persoon.
##### Hand-outs kunnen u de handen vrij geven
Deel nooit kopieën uit van uw dia's, die kunnen nooit **op zichzelf staan**! Dias versterken uw verhaal, handouts bevatten uw verhaal en meer details.<br/><br/>
Het is dus belangrijk om beide zaken op te splitsen! Vermijd te mixen!
### Het verhaal smeden
##### Wat zorgt ervoor dat een boodschap blijft hangen?
* Eenvoud: Als alles belangrijk is, is niets belangrijk!
* Onverwacht: Verrassing zal aandacht trekken
* Concreet: gebruik spreektaal en geef echte voorbeelden
* Geloofwaardig: statistische gegevens hebben geen enkel nut, hun context waarin dit van belang is wel!
* Emotie: Laat mensen iets *voelen*, speel hierop in.
* Verhaal: mensen communiceren al eeuwen lang door middel van verhalen.
##### Het proces
1. Brainstorming
2. Groeperen en de kern bepalen, één thema centraal laten staan
3. Werk met een storyboard zonder PC en verwerk de gegevens van stap 2 op notes
4. Werk met een storyboard op PC: in de diasorteerweergave/tabelweergave van PowerPoint.
##### Bewerkingen en beperkingen
Knip onnodige zaken van uw verhaal om het zo effectief mogelijk te maken! Hou mensen niet langer dan nodig bezig met uw presentatie. <br/><br/>
Laat bij twijfel direct iets weg. Editeer alles vastbesloten als de eerste draft af is.
### Waarom eenvoud zo belangrijk is
Samen met andere grondregels zoals beperking en natuurlijkheid is eenvoudig in Zen en de Zen-kunsten een sleutelbegrip. Toepassingen zoals theeceremonies((Sado staat voor de Japanse theeceremonie)), haiku, ikebana en sumi-e. enkele begrippen hieruit zijn:
##### Kanso (eenvoud)
Schoonheid en visuele elegantie worden teweeggebracht door alle overbodigheid weg te laten.
##### Shizen (natuurlijkheid)
Verhindert het gebruik van uitgebreide ontwerpen en oververfijning. (beperking dus weer)
##### Shibumi (elegantie)
Elegante eenvoud en helder uitgedrukte bondigheid - ingehouden elegantie. <br/><br/>
Voor meer opvattingen over schoonheid, zie **Wabi-Sabi**: armoede (afwezigheid van materiële rijkdom) en eenzaamheid.
Scott McCloud:
> Door een afbeelding tot zijn essentiële betekenis terug te brengen kan een ontwerper die betekenis versterken.
Hoofdboodschap: *Versterk door te vereenvoudigen*! <br/><br/>
Leer bijvoorbeeld van de kunst van het striptekenen: {{< lib "Understanding comics: the invisible art" >}} (Scott McCloud).
Pas op: eenvoud is niet gemakkelijk en kost meestal méér tijd in plaats van het meestal gedachte minder ("rap iets weglaten, kkdone")
### Presentaties ontwerpen
Algemene ontwerpprincipes, ook zonder designer achtergrond, kan je terugvinden in {{< lib "The non-designer's design book" >}} (Robin Williams)
##### Signal-noise ratio
De vereenvoudiging tussen relevante en irrelevante informatie op een slide. Vaak te drukke slides, te veel contrast zodat het belangrijkste element niet goed in beeld komt, ... Het probleem schuilt meestal in een heel klein hoekje: maak alle visuele aanpassingen zo subtiel mogelijk. Zie {{< lib "Visual Expectations: images and quantities" >}} (Edward Tufte)
Vermijd ook "fancy 3D effectjes" toe te passen, grafieken zijn in hun 2D-vorm duidelijker en makkelijker te interpreteren.
:exclamation: Geen logo's op elke dia! Eerste & laatste dia met bedrijfslogo. De rest vormt ruis!
##### Het beeldsuperioriteitseffect
Vul uitgesproken worden beter aan met foto's, beelden, metaforen, ... <br/><br/>
{{< lib "Going visual: Using images to enhance productivity, decision-making and profits" >}}: gebruik visuele beelden om uw verhaal te vertellen!<br/><br/>
Gebruik het hele scherm voor uw afbeelding, zonder mensen af te leiden met default achtergrond van dia's.
Werken met citaten die in de context van uw verhaal van toepassing zijn werken ook effectief.
##### Lege ruimte
Daisetz Suzuki:
> Leegheid die abusievelijk als louter niets doen kan worden begrepen, is in feite het reservoir van oneindige mogelijkheden.
Lege ruimten impliceren elegantie en klaarheid. Dat geldt zowel voor grafische ontwerpen als voor interieur design.<br/><br/>
Herinner uzelf eraan dat het niet nodig is om alle woorden die je uitspreekt ook op een dia te plakken!
Denk hier aan het evenwicht tussen lege ruimtes, woorden en afbeeldingen.
##### Rasters en de 1/3de regel
Bekijk de "compositie" van uw dia op dezelfde manieren als fotografen hun onderwerp willen vastleggen. <br/><br/>
Hiermee schept u samenhang en estethische kwaliteit.
##### De grote 4
* Contrast: sterke dynamische verschillen vastleggen die onderdelen afscheiden
* Herhaling: bevordert de eenheid en oderlijkheid van uw dia's
* Uitlijning: visueel koppelen via onzichtbare lijnen
* Nabijheid: bij elkaar horende onderdelen groeperen.
### De kunst om volledig aanwezig te zijn
David Bader:
> Wees nu hier aanwezig. Wees later ergens anders. Is dat zo moeilijk?
Focus leggen en concentratie daar laten liggen tijdens het geven van de presentatie is belangrijk!<br/><br/>
Het publiek merkt op als je "opgaat" in je eigen presentatie, of niet weet over wat het gaat. Daarom: **Blijf met uw gedachten bij uw onderwerp**!
Zen principe: *mindfulness*, een verhoogde mate van aandacht. (Referentie GTD e.a.: "flow state of mind")
##### De geest die geen geest is
"Mushin no Shin", een zwaardvechter die volledig in het moment aanwezig is met een *lege geest*. Hij denkt niet na over hoe hij moet zwaardvechten. Op die manier verandert zowel het zwaard als de zwaardvechter in een instrument in de handen van het onbewuste (intuïtie, Dreyfus level5). Zie {{< lib "Zen and Japanese Culture" >}} door Daisetz Suzuki. Het is **het onbewuste dat wonderen van creativiteit verricht**.
Daisetz Suzuki:
> De wateren zijn voortdurend in beweging, maar de maan behoudt zijn sereniteit. De geest beweegt als reactie op tienduizend situaties, maar blijft altijd hetzelfde.
Referentie GTD "mind clear as water"!
##### Leren van Judo
1. Observeer uzelf en uw situatie zorgvuldig, observeer anderen en uw omgeving zorgvuldig
2. Neem het initiatief bij wat u onderneemt
3. Weeg ten volle af en handel besluitvaardig.
4. Weet wanneer u moet stoppen.
5. Blijf in het midden.
Dit zijn 5 judoprincipes besproken in {{< lib "Budo Secrets" >}} (John Stevens), makkelijk overal toepasbaar.
##### Hara Hachi Bu
"Eet tot je 80% vol bent", een Japans principe.<br/><br/>
Ook toepasbaar op presenteren: hou het kort, laat mensen ietwat hongerig achter, verlangend naar meer. Zorg zo dat ze bijvoorbeeld:
* Effectief je hand-out ook lezen
* Eventueel meer opzoekingswerk doen over het onderwerp en bijgevolg
* **Geïnspireerd raken**!
##### Laat de lichten aan
Het publiek moet u altijd kunnen zien. Sta centraal, en niet achter een bureau te klikken/prullen met de presentatie laptop!
### Hoe u zich kunt verbeteren
Dingen om te doen om een betere presentator (of algemener) te worden:
##### Lees en bestudeer
Lees boeken, bekijk documentatie, zoek relevante onderwerpen, ...
http://www.presentationzen.com bevat 75+ referentieboeken.
##### Doe het
Zelfstudie alleen is meestal niet genoeg. Het effectief ook doen helpt enorm!
##### Oefen uw "rechter"-hersenhelft
Verwaarloos uw passies en talenten niet door uw werk op voortouw te nemen. Ga uw gevoel achterna.
##### Ga erop uit
Er zullen nooit fantastische dingen gebeuren als u in uw luie stoel blijft zitten. Leg contacten, trek erop uit, daag uzelf uit en ontwikkel uweigen creativiteit.

View File

@ -1,121 +0,0 @@
+++
title = "productive_programmer"
draft = false
tags = [
"books",
"productive_programmer"
]
date = "2013-03-12"
+++
# The Productive Programmer
Author: Neal Ford<br/><br/>
{{< lib "Productive programmer|Librarything Link" >}}
Dit is een samenvatting van alle **notes** in essentie, opgedeeld per hoofdstuk.
## Part 1: Mechanics
### Acceleration
* Concentrate on essence, not ceremony.
* The usefulness of an application list is inversely proportional to its length.
* Eye candy looks goot but isn't nutritious.
* Typing is faster than navigation.
* Prefer typing over mousing.
* The address bar is the most efficient Windows interface.
* Take the time to learn all the hidden keyboard shortcuts of your universe.
* Context switching eats time.
* Clipboarding to batches is faster than clipboarding serially.
* Those who remember their history aren't doomed to type it again.
* Embedded command prompts give you access to the best of both worlds.
* Embed the command prompt to make it easier to switch contexts.
* When coding, always prefer the keyboard to the mouse.
* Learn the IDE keyboard shortcuts in context, not by reading long lists.
* When you type a complicated construct for the second time, templatize it.
* For any symmetric operation on multiple lines of text, find a pattern and record a macro.
* The more times you perform a particular operation on a chunck of text, the greater the likehood you'll do it again.
* Don't type the same command over and over again.
* Spend a little time each day to make every day more productive.
<img style='float: left; width: nolink&|px;' src='/img//books/angry_monkeys.png'>
### Focus
* The higher the level of concentration, the denser the ideas.
* THe bigger the haystack, the harder it is to find the needle.
* Replace file hierarchies with search.
* Try simpler searching before resorting to "hard target" searching.
* Take advantage of built-in focus facilities like colors.
* Use links to create virtual project management folders.
* Virtual desktops unclutter your stacks of windows.
### Automation
* Use tools out of their original context when appropriate.
* Don't spend time doing by hand what you can automate.
* Performing simple, repetitive tasks squanders your concentration.
* Finding innovatige solutions to problems makes it easier to solve similar problems in the future.
* Timebox speculative development.
### Canonicality
* Keep a single copy of everything you don't build in version control.
* Use indirection to create friendlier workspaces.
* Use indirection to keep your life in sync (symlinks).
* No matter what you are copying and pasting, reuse by copy and paste is evil.
* Use virtualization to canonicalize dependencies for your projects.
* Don't let object-relational mapping tools violate canonicality.
* Add behavior to generated code via extention, open classes or partial classes.
* Always keep code and schemas in sync.
* Use migrations to create repeatable snapshots of schema changes.
* Out-of-date documentation is worse than none because it is actively misleading.
* For managers, documentation is about risk mitigation.
* Always keep "living" documents.
* Anything that takes real effort to create makes its creator irrationally attached to it.
* Whiteboard + digital camera > CASE tools.
* Generate all the technical documents you can.
* Never keep two copies of the same thing.
* Repetition is the single most diminishing force in software development.
## Part 2: Practice
### Statistic analysis
* Statistic analysis tools represent cheap verification.
### Good citizenship
* Don't create global variables, even the object kind.
### YAGNI
* Don't pay complexity tax unless you absolutely must.
* Software development is first and foremost a communication game.
### Ancient philosophers
* Maximize work on essential complexity; kill accidental complexity.
* Even general-purpose programming languages suffer from the "80-10-10" rule.
* Pay attention to the lore of "ancient" technologies. (Smalltalk lol)
### Meta-programming
* Meta-programming changes your syntactic vocabulary, giving you more ways to express yourself.
### Composed method and SLAP
* Refactoring to composed method reveals hidden reusable code.
* TDD predisposes composed method.
* Encapuslate all implementation details away from public methods.
### Find the perfect Tools
* Find your perfect editor and learn it inside and out.
* Record macros for all symmetrical text manipulations.
* Good knowledge of regexp can save orders of magnitude of effort.
* Don't make round trips when you can batch.
* Use a "real" scripting language for automation chores.
* Keep behavior in (testable) code.
* Pay attention to the evolution of your tools.
* Pay as little complexitax as you can.

View File

@ -1,24 +0,0 @@
+++
title = "purplecow"
draft = false
tags = [
"books",
"purplecow"
]
date = "2013-03-12"
+++
# Purple Cow: Transform Your Business by Being Remarkable
### Crossing the Chasm
{{< wp "Crossing the Chasm" >}}
<img style='float: left; width: direct&800 |px;' src='/img//books/crossing-the-chasm.png'>
Focus op **Early Adopters** in plaats van "majority"! Waarom?
1. Die mensen geven vroeg feedback
2. Zijn de "niezers" die andere mensen besmetten via mond-op-mond reclame "kijk wat voor iets nieuws ik heb en hoe goed het werkt". Binnen de majority groep is zo niets dat zijn allemaal slechts volgers, en tegen dan is het product "uitgebold".
3. Op dat moment heeft het product nog de meeste waarde.
*Late majority* = Gebaseerd op ervaring van anderen.

View File

@ -1,48 +0,0 @@
+++
title = "quiet"
draft = false
tags = [
"books",
"quiet"
]
date = "2013-09-17"
+++
# Quiet
> It's not that I am more intelligent, it's that I stay with problems Longer. (A. Einstein)
## Persoonlijkheden in de wereld
### Introverten
1. Energie halen uit alleen zijn, boek lezen, wandelen in bergen, ...
2. Introvert <> niet sociaal, ze zoeken even veel toenadering als anderen, maar dan minder frequent of in (zeer) kleine groepen.
3. Heeft het moeilijk om zijn mening te uiten in grotere groepen, wordt snel overweldigd
4. Hebben veel meer natuurlijke volhouding (zeer fel focussen en toeleggen op 1 probleem)
5. Man of contemplation
6. stress van bvb tornooien bij wedstrijden, tov "anoniem" presteren, gaat beter
### Extraverten
1. Superjoviaal
2. Houdt van netwerken, feestjes, ...
3. Neemt natuurlijkerwijs het voortouw, ongeduldig t.o.v. mening van introverten
4. Man of action
5. Energie halen uit mensen rond hem
6. Haalt juist energie uit het feit dat hij "bekeken" wordt bij wedstrijden (sommige atleten hebben dit net nodig)
### Ambiverten
1. Kunnen beide vormen aan
2. Opgelet met verschil tussen introvert die zich gedraagt als extravert (bvb op werk), haalt energie naar beneden
Ben je een ambivert? Doe de test: http://www.danpink.com/assessment/
> There is no such thing as a pure introvert or extrovert. Such a person would be in the lunatic asylum. ~ Carl G Jung
Denk je dat je een ambivert bent? Beantwoord deze vraag eens:
> “would you prefer to go to a party or read a book?” My first thought was “Depends on the party or book and also how tired I am from the previous night.” But that contextual option wasnt available. Now I realize what a gift it is to be sensible, reasonable and well balanced enough to have the freedom of choice.
Als jij altijd, 100% voor het boek zou gaan ben je een introvert die zich als extravert gedraagd op gelegenheden.
Zie ook http://lonerwolf.com/ambivert/

View File

@ -1,273 +0,0 @@
+++
title = "rework"
draft = false
tags = [
"books",
"rework"
]
date = "2013-03-12"
+++
# Rework
Author: Jason Fried & David Heinemeier Hansson<br/><br/>
Context: Pragmatic project/company management
{{< lib "Rework|Librarything Link" >}}
## Takedowns
1. Ignore the real world
* Hoofd niet laten hangen als iedereen beweert dat het onmogelijk is, niet geloven!
* Allemaal excuses om het niet te proberen, heeft niets met u te maken.
1. Learning from mistakes is overrated
* Het is bewezen dat mensen die succes hebben een grotere kans op succes hebben in de toekomst
* "Learn by mistake" is dus niet altijd 100% correct
1. Planning is guessing
* Het heeft geen nut om lange termijn plannen op te stellen
* Plan wat uitmaakt op korte termijn, vandaag! Hou op met gokken
* Promoot adaptability/agility, pas u aan op het moment zelf
1. Why grow?
* Groter worden als bedrijf brengt enorm veel nadelen met zich mee
* *Small is not just a stepping stone. Small is a great destination itself.*
1. Workaholism
* Overwerken heeft geen nut, lack of focus, lack of concentration
* Mensen voelen zich verplicht om te blijven en boeken 0 vooruitgang.
1. Enough with "enterpreneurs"
## GO
<img style='float: left; width: nolink&|px;' src='/img//books/rework_enthousiasm.png'>
1. Make a dent in the universe
* Zorg voor een gevoel van verschil
* Aim voor *"This makes my life better"* van de klant uit
* Voor het idee uit, "heb" het niet alleen.
1. Scratch your own itch
* Als er nood is aan een tool intern, maak die dan voor uzelf en verkoop ze daarna!
* Vergroot de band met wat je zelf maakt, is nuttig en vereist minder werk.
1. Start making something
* *Until you start actually making something, an idea is just an idea. And everyone's got one of those*
* Stop met zagen, start met werken!
1. No time is no excuse
* Start met kleine beetjes tijd hier en daar vrij te maken, en aan het idee te werken
* Het perfecte moment zal er nooit zijn!
1. Draw a line in the sand
* Heb een sterke meningsuiting, een sterke visie, en ga nooit over die streep!
* Bvb. nee zeggen tegen de klant als uw bedrijf staat voor eenvoud in gebruik
1. Mission statement impossible
* *Standing for something isn't just about writing it down. It's about believing it and living it.*
1. Outside money is plan Z
* Gefinancierd worden is een enorm slecht idee en heeft veel nadelen en constraints! Gebruik enkel als laatste optie!
1. You need less than you think
* Tegenwoordig is alles dat vereist is een laptop en een plaats om te werken.
* Laat u niet tegenhouden door zogezegde énorme (hardwarematige) requirements. Allemaal voor niets nodig.
1. Start a business, not a startup
2. Building to flip is building to flop
* *You need a commitment strategy, not an exit strategy!*
* Denk nog niet na over hoe quitten zonder verlies of in beslagname van x of y.
1. Less mass
* Enorm veel dingen weerhouden u van actueel werk:
* Lange termijn contracten
* Te veel werknemers
* Meetings
* Politiek
* Lange termijn plannen
* ...
## Progress
1. Embrace constraints
* Minder resources zetten u aan om met beperkte middelen toch iets te realiseren!
* Bart meldde dit voor hij het boek zelf las! Ook overal anders op toepasbaar. => Wekt creativiteit op (hacken iemand anders zijn code)
* Legt weer nadruk op less mass.
1. Build half a product, not a half-assed product (zie onder)
2. Start at the epicenter
* Neem houvast aan het *core concept*, en breid vanaf daar uit
* Alles in scope pakken is onmogelijk! Release early promoot de houvast aan uw core domein.
1. Ignore the details early on (zie boven)
2. Make the call is making progress
* Beslissingen uitstellen heeft geen zin, ze worden dan snel en zonder nadenken afgehandeld.((Komt ook weer terug bij Power Thinking))
* Swap *Let's think about it* voor *Let's decide about it*!
1. Be a curator
2. Throw less at the problem
* *When things aren't working, cut back*. Gooi niet meer geld en resources tegen een probleem aan, maar juist minder.
* Zo werkt in principe XP ook: wanneer er meer werk is, werk dan minder lang, ipv overuren te maken (zie eerder ook weer)!
1. Focus on what won't change
* Probeer minder rekening te houden met fancy dingen die *hot & new* zijn. Focus op substance ipv fasion.
* Focus op permanente features ipv dingen die na verloop van tijd hun stijl verliezen.
1. Tone is in your fingers
* Het maakt niet uit welke tools gebruikt worden, hoe high-end ze ook zijn! Met kladblok bereik je evenveel!
1. Sell your by-products
* Het is onmogelijk om juist 1 ding te maken. Verkoop ook bijproducten die een gevolg zijn van het maken van 1 ding.
1. Launch now
* Release early ((Agile referentie #4556)).
* Focus on core (zie vroeger), fancy effecten is bijzaak. Gebruik de deadline, verschuif het niet!
## Productivity
1. Illusions of agreement
* *The business is littered with dead documents that waste people's time* ((XP referentie #4557))
* Stop met abstractions zoals rapportjes en documentjes maken voor niks.
1. Reasons to quit
* Vraag u op tijd af of het de moeite is om te doen wat er gedaan wordt:
* Is het wel handig?
* Voegt het een waarde toe?
* Verandert dit het gebruik?
* Is het makkelijker op te lossen?
* Wat zou je in de plaats beter kunnen doen?
* Is het echt de moeite?
1. Interruption is the enemy of productivity
* No-brainer. Gebruik bvb een SPOC ((Single point of Contact)) voor interruptions af te leiden. Introduceer no-talk day, ...
1. Meetings are toxic
* Bijna alle meetings verknoeien kostbare tijd die je beter aan iets ander spendeert.
* Indien toch nodig:
* Nodig zo weinig mogelijk mensen uit
* Zet een timer EN GEBRUIK DIE!
* Duidelijke agenda punten.
* Begin met specifieke problemen en eindig met duidelijke doelstellingen ((Zoals een Retrospective dus))
1. Good enough is fine
* *The easiest thing that could possibly work*
1. Quick wins
* Concreet: release in kleine stukken, en enorm vaak in plaats van een lang plan te hebben en nooit iets te geven aan klanten
1. Don't be a hero
* Stop op tijd met iets dat te veel tijd in beslag neemt in plaats van "door te bijten" dat niet de moeite is.
1. Go to sleep (zie eerder)
2. Your estimations suck
* nog maar eens: deel op in kleine stukken en schat die individueel, dan is er een veel kleinere afwijking dan grote dingen inschatten.
1. Long lists don't get done
* Door bvb. backlog beperkingen uit te voeren. Focus op core, ...
1. Make tiny decisions (zie eerder)
## Competitors
1. Don't copy
* Kopiëren is een formule om te **falen**! Iets overnemen zonder te begrijpen wat er staat is compleet nutteloos.
* Zorg voor inzicht en neem dan over, maar nooit letterlijk. Laat u beïnvloeden, maar steel niet.
1. Decommoditize your product (*Pour yourself into your product*)
2. Pick a fight
3. Underdo your competition
* *Cold War mentality is a dead end*
* Productne die hopelos iets anders proberen na te bootsen zijn al op voorhand gedoemd om te falen (zie eerder)
1. Who cares what they are doing?
* Focus u niet op anderen maar op uzelf!
## Evolution
1. Say no by default
* Leer om nee te zeggen tegen klanten. Mensen zeggen standaard ja omdat ze schrik hebben om confrontaties aan te gaan.
* Op die manier merk je sneller wat klanten écht wensen.
1. Let your customers outgrow you
* Customize nooit één product volledig gericht op één klant. Graaf zo niet uw eigen graf!
1. Don't confuse enthousiasm with priority
* Een fijntje speciaal voor mij. Een idee kweekt enorm **(te) veel enthousiasme** en de neiging om alles te laten vallen en dat te implementeren is groot.
* Focus op prioriteiten en de core in plaats van nice to haves!
1. Be at-home good
* Probeer iets te maken wat klanten imponeert, ook als ze thuis zijn in plaats van in de winkel (door te focussen op wawzomg toeters en bellen)
1. Don't write it down
* Request trackers zijn niet nodig, vergeet af en toe wat de klant wilt.
* Wanneer het echt belangrijk is komt het terug en kan het niet meer vergeten worden. Zo filter je het belangrijkste van de nice-to-have zaken beter.
## Promotion
1. Welcome obscurity
* Niet bekend zijn als bedrijf geeft u de kans om nieuwe dingen te proberen - als dit mislukt maak het toch niet uit. Blijf tweaken en inventen!
* Als 1 miljoen mensen uw product gebruiken spreken we over iets totaal anders.
1. Build an audience
* Doe geen beroep op advertenties om klanten te lokken. Doe beroep op een publiek dat naar u komt in plaats van andersom.
* Concreet bvb een blog bijhouden en discussies over design starten, zodat mensen terug komen om te zien wat jij als bedrijf te vertellen hebt.
1. Out-teach your competition
* Outselling the competition gaat nooit lukken, zeker niet als klein bedrijf. En daar win je geen vertrouwen mee.
* Door op te leiden leert men zelf ook veel ((pragmatic thinking & learning referenties zijn er ook ja))
1. Emulate chefs
* chefs delen hun beste recepten met anderen. Als bedrijf moet knowledge ook geshared worden! ((Wikis met kennis?))
* Bedrijven doen meestal paranoïde en geheim, dat is bullshit. Een recept is kopiëerbaar, een bedrijf niet.
* Heb een persoonlijk "kookboek" als bedrijf dat uw visie en geheimen deelt!
1. Go behind the scenes
* Laat mensen zien hoe jij als bedrijf werkt, toon dat in het juiste licht en maak het interessant.
1. Nobody likes plastic flowers
* *Leave the poetry in what you make. When something becomes too polished, it loses its soul. It seems robotic*
* Toon uw tekortkomingen als bedrijf. Niemand houdt van "suits" die elke dag er hetzelfde uitzien met hun kravat.
1. Press releases are spam
* Coverage door middel van pers is vervelend, subjectief en kost geld. Probeer mensen persoonlijker te bereiken.
* *Be remarkable. Stand out.*
1. Forget about the Wall Street journal
2. Drug dealers get it right
* Maak het product zo goed dat mensen altijd terug komen. Geef een vinger en ze willen een hele arm. Ga daarvoor.
1. Marketing is not a department
* Iedereen doet aan marketing door te communiceren! Gebruik al die kleine momenten in plaats van een aparte "afdeling".
1. The myth of the overnight sensation (slow measured growth > overnight success)
## Hiring
1. Do it yourself first
* Huur nooit iemand in voor iets dat ge zelf nooit gedaan hebt. Zo kunt ge beter dat werk inschatten en afstemmen.
* Probeer eerst te leren!
1. Hire when it hurts
* Meestal kan aanwerving uitgesteld worden, probeer zo lang mogelijk zonder vol te houden.
1. Pass on great people
* Ook al is iemand zijn CV wowdemax, neem niemand aan als er geen extra werk is en er geen volk nodig is!
* Werfreserves = zever.
1. Strangers at a coctail party
* Huur aan een trage rate aan, zodat mensen elkaar heel goed kennen en ge weet hoe ver ge met werknemers kunt gaan.
* Een sfeer die je niet wil op het bedrijf: smalltalk (at a coctail party), maar voor de rest niet durven communiceren.
1. Resumés are ridiculous
* Huur afhankelijk van brieven in plaats van CVs!
1. Years of irrelevance
* Het verschil tussen iemand met 6 maand en 6 jaar ervaring is meestal kleiner dan verwacht.
* Het echte verschil ligt hem in de individuele dedicatie en intelligentie.
1. Forget about formal education (zever, gezever)
2. Everybody works
* Mensen die werk delegeren zijn nutteloos
1. Hire managers of one
2. Hire great writers
* Onafhankelijk van het type van job, indien een keuze is, huur de beste schrijver.
1. The best are everywhere (geo-onafhankelijk)
2. Test-drive employees
* Probeer iemand in te huren voor een klein project, bvb iets van 24h, en evalueer het resultaat.
## Damage control
1. Own your bad news
* Het slechte nieuws brengen doe je nog altijd het beste zelf!
* Wees eerlijk en persoonlijk
1. Speed changes everything
* Callcenters + holdtime = lol - geef klanten zo snel mogelijk feedback! Ook bij negatieve zaken.
* Dit verandert de perceptie van de klant zelf
1. How to say you're sorry
* Niet "wij excuseren ons voor het ongemak dat dit kan gekost hebben" maar "het spijt MIJ want [eerlijke en geldige reden]"
* Personaliseer excuses!
1. Put everyone on the front lines
* Hoe meer stappen tussen klanten contact en developers, hoe groter de kans dat iets verloren gaat! ((Wink naar proxies))
* Probeer zo veel mogelijk mensen in contact met de klanten te zetten
1. Take a deep breath
## Culture
1. You don't create a culture
2. Decisions are temporary
* Maak geen problemen die er nog niet zijn in realiteit. Beslissingen die vandaag worden genomen hoeven niet voor altijd te gelden!
* *The ability to change course is one of the big advantages of being small.*
1. Skip the rock stars
2. They're not thirteen
* Behandel werknemers met gespect en geef ze vrijheid. Veel regels opleggen = werkresultaten van iemand van 13 terugkrijgen.
1. Send people home at 5 (zie vroeger)
2. Don't scar on the first cut
* Leg niet direct policies vast als één werknemer iets heeft foutgedaan. Dit brengt de rest ook in een negatief daglicht.
1. Sound like you
* Bedrijfspropaganda en emails moeten niet in 3de persoon geschreven worden, in ingewikkelde academische taaltjes.
* Communiceer zoals je tegen je vrienden praat!
1. Four-letter words
* Vermijd:
* Need - weinig dingen moeten gedaan worden
* Can't - alles kan!
* Easy - *easy is a word to describe other people's jobs*
* Fast - Alles moet snel gebeuren...
* *"We need to add this feature now. We can't launch without, everyone wants it. It's only a little thing so It'll be easy and done fast"* -> full of fail
1. ASAP is poison (zie vermijd snel)
## Conclusion
1. Inspiration is perishable
* Iedereen heeft ideeën, maar inspiratie komt met vlagen. Pak het met beide handen vast en gebruik het op dat moment!
* Inspiratie vervliegt. Op het juiste moment aan het idee werken verzet meer werk dan een week in een dag.

View File

@ -1,86 +0,0 @@
+++
title = "where_good_ideas_come_from"
draft = false
tags = [
"books",
"where_good_ideas_come_from"
]
date = "2013-03-12"
+++
# Where good ideas come from
{{< lib "Where Good Ideas come From" >}} van Steven Johnson
Zie p75C en p78B en p79C
### 1. The Adjacent Possible
Concept: *Ideeën en uitvindingen die uitgebracht worden, openen de deur voor andere ideeën en uitvindingen*. Kopiëren van anderen (het idee, niet de uitwerking) is niet slecht maar goed, en maakt het mogelijk om bijvoorbeeld verder te breiden op het vorige idee. Een primitieve computer werd reeds volledig mechanisch ontwikkeld (met ballen die tandwielen doen roteren, zie {{< wp "Charles Babbage" >}}'s analytical engine, reeds in **1834** aan begonnen!), voordat elektriciteit uitgevonden werd. Zo'n uitvinding is *zijn tijd voor* - dat wil zeggen, de uitwerking van het idee wordt over het algemeen niet aanvaard of heel moeilijk tot onmogelijk gemaakt op dat bepaald tijdstip.
> All of us live inside our own private versions of the adjacent possible. In our work lives, in our creative pursuits, in the organizations that employ us, in the communities that we inhabit - in all these different environments, we are surrounded by potential new configurations, new ways of breaking out of standard routines.
### 2. Liquid Networks
<img style='float: left; width: |px;' src='/img//books/where-do-good-ideas-come-from.jpg'>
Concept: het overdragen van ideeën van persoon of community A naar B en zo verschillende ideeën combineren om tot iets nieuws te komen (en dan misschien weer een deur naar de volgende mogelijkheid openen, zie punt 1). Een "netwerk" kan zich in verschillende staten bevinden:
* **Air**: bvb. Gas - té aggressief, het vervliegt direct en er zijn er te veel. Vergelijk gas met ideeën die constant veranderen en vervliegen.
* **Liquid**: bvb Water - houdt zuurstof redelijk goed vast en trekt via cohesie andere vloeistoffen aan: een idee dat ronddrijft op het water en mogelijk tegen anderen botst om zich te vergroten.
* **Solid**: bvb Beton - geen enkele staat van verandering mogelijk, "vastgegroeid" in een oud systeem waar niets innoverent kan en zal werken.
Streef zo veel mogelijk naar "liquid networks". Dat wil zeggen: op uw werk, in uw privé leven, ... Zorg dat je jezelf omringt met andere genieën die goede ideeën verspreiden via het liquid network, met innovaties waar je naar op kijkt. Om zelf liquid networks te creëren moet je je omgeving ook zo aanpassen!
Grotere steden waar meer *innovators* wonen, groeien bijgevolg nog sneller door de ideeën die van persoon tot persoon overgedragen worden en zo nog meer nieuwigheden creëren. Al die dingen zijn enkel in het juiste netwerk mogelijk.
> The quickest way to innovate is to make novel connections
Voorbeeld: een wiki bijhouden digitaal kan te *solid* zijn vanwege de geforceerde manier van structureren. Een boek en random dingen op random plaatsen opschrijven is "losser" maar heeft dan weer kans om ideeën te laten "vervliegen" als je het boek niet regelmatig naleest.
### 3. The Slow Hunch
Concept: het "billion dollar idee" ineens krijgen bestaat niet - zulke dingen hebben meestal járen gerijpt in iemands brein. Om zo'n idee te laten ontstaan zijn ook botstingen met anderen nodig (zie punt 2)
> Reading is an unsurpassed vericle for the transmission of interesting new ideas
Tips om tot invallen te komen en de "slow hunch" levende te houden:
1. Noteer alles en herlees regelmatig notities
2. Omgeef uzelf door mensen waar je naar opkijkt of die iets te maken hebben met het idee waar aan je wilt werken
3. Zorg ervoor dat alles in een liquid network zit zodat het *superliniair scalet* in plaats van een *failed spark* wordt
4. Vertrouw op snap judgementes en schrijf ze ook op!
### 4. Serendipity
Concept: **per ongeluk** ergens op stoten door bijvoorbeeld een boekenwinkel te browsen en random titels af te gaan en u te laten leiden door uw gevoel. Of alle gedachten en notities in één plaats bewaren (digitaal, bijvoorbeeld in [DEVONthink](http:*www.devon-technologies.com/products/devonthink/)) en hierdoor zoeken - zo kom je andere ideeën terug tegen (Google's *did you mean ... ?//) en maak je op die manier nieuwe links. Wikipedia's "see also" links die alles met elkaar verbinden.
> {{< wp "Serendipity" >}} is when someone finds something that they weren't expecting to find.
Tegenwoordig onderschatten we te veel de kracht van op iets struikelen (*to stumble upon ideas*) - we zoeken op Google heel gericht naar onderwerp X, of in winkels kopen we Y en negeren we de rest. Kijk rond u, interesseer u ook in andere zaken en domeinen en draag een deel van die kennis over naar uw domein waar je aan dat slow hunch aan het werken bent.
### 5. Error
> The errors of the great mind exceed in number those of the less vigorous one ({{< wp "William Stanley Jevons" >}})
Concept: fouten maken is een essentiëel proces dat incrementeel voor verbeteringen zorgt. Men leert uit fouten en men krijgt andere ideeën uit fouten. Door constant fouten te maken ga je paden verkennen die je nooit eeder verkende - bijvoorbeeld door fout te denken dat een stelling juist is ga je je experiment daarrond richten maar blijkt dat je per ongeluk iets heel anders ondekt. *Transforming error into insight is one of the key functions of the lab conference*.
> Perhaps the history of the errors of mankind, all things considered, is more valuable and interesting than that of their discoveries. Truth is uniform and narrow, it constantly exists, and does not seem to require so much an active energy, as a passive aptitude of soul in order to encounter it. But error is endlessly diversified. ({{< wp "Benjamin Franklin" >}})
### 6. Exaptation
Concept: *aanpasbaarheid aan de omgeving.* Wanneer iets faalt of iets anders gaat dan je verwacht, gooi niet meteen alle ideeën weg. Pas het simpelweg aan, om in de nieuwe omgeving even goed of zelfs beter te kunnen functioneren. Kijk naar moeder natuur: organismen passen zich al miljoenen jaren aan aan hun omgeving.
De {{< wp "water flea" >}} bijvoorbeeld, kloont zichtzelf wanneer alles "goed" gaat. Wanneer alles goed gaat -> more of the same natuurlijk! Echter, wanneer het barre leefomstandigheden zijn, reproduceert deze luis zich via seks. Hierdoor kruisen cellen zich, zodat Nieuwe en andere cellen ontstaan die zich aanpassen aan de omgeving. Klonen brengt meer van hetzelfde, kruisen niet.
> In challenging times, an organism needs new ideas to meet them.
Brein stamcellen kunnen in twee modi werken:
1. Chaos mode
2. Phase locking mode
In mode 2 vuren alle neuronen synchroon af. In mode 1 niet, daardoor is er veel meer kans dat ideeën ontstaan in het brein doordat neuronen "vrij" met elkaar kunnen verbinden of tegen elkaar botsen. Hoe meer in chaos mode, hoe hoger het IQ van de mens ook ligt.
### 7. Platforms
Concept: Door te bouwen op ideeën en rond liquid networks ons gamma aan innovaties uit te breiden, bouwen we platformen waarop we verder kunnen werken. Concreet als voorbeeld: het GPS satelliet systeem, het World Wide Web, ... - deze zaken waren ooit uitvindingen die voor iets heel anders dienden maar groeiden uit tot een immens platform waarop andere mensen ideeën op uitwerkten, en zo voorts. Dit zijn hele communities geworden die vanuit het niets ontstaan zijn.

View File

@ -1,110 +0,0 @@
+++
title = "woordenlijst"
draft = false
tags = [
"books",
"woordenlijst"
]
date = "2013-03-12"
+++
# Woordenlijst
## Engelse woorden
^ Engels ^ Synoniem ^ Nederlandse vertaling ^
| Maldaptive | Marked by faulty or inadequate adaptation | Slechte aanpassing |
| colloquially | informal / using conversation | informeel |
| florid | gaudy, flamboyant | "bloemrijk" / overdreven sierlijk |
| probing | to search into or examine thoroughly - investigating | onderzoekend |
| myriad | countless | een enorm groot bedrag |
| valence (electrons) | the relative combining capacity of an atom | ... |
| primordial | constituting a beginning - first formed | "oer-" |
| surge | a strong forward moment, swelling of something | een golf |
| dispersed | to drive or send off | verspreid |
| nascent | beginning to exist or develop | in wording |
| erudite | educated | enorm veel kennis hebbend |
| dissertations | a written essay | thesis |
| calcifying | to become bony (hardened by calcium) | calcificerend? |
| inordinate | not within reasonable limits - extreme, unreasonable | buitensporig |
| of that ilk | of the same class or kind | ? |
| intrinsic | native, innate | intrinsiek |
| perpetrations | to commit | plegen |
| prescient | foresight | voorkennis |
| contemplating | to view with continuous attention - gaze at, behold | overwegend |
| elicited | to draw or bring out - to evoke | oproepen |
| disseminate | to scatter or spread widely - to disperse | verspreiden |
| sprig | a shoot, twig | een takje |
| concocted | to diverse, to make up | verzonnen |
| convey | to carry or bring | overbrengen |
| a finch | a similar bird (songbird) | ... |
| tantalizing | having something that provokes interest or desire | prikkelend |
| murkiness | dark, gloomy, cheerless | donker |
| frontispiece | the front of a building - an illustration facing the cover of a book | "titelplaat" ? |
| accretion | the addition | "aanwas" ? |
| pedigree | ancestral - distinguished | stamboom |
| contemporaries | existing at the same time | tijdgenoten |
| lingua franca | any language that is widely used as a means of communication among speakers of other languages. | ... |
| inebriated | to make drunk, toxiate | "bezatten" |
| proliferating | to increase in number/speed rapidly | profilerend |
| pileated | in the form of a skullcap (see [woodpecker](http://www.alphadictionary.com/goodword/word/pileated)) | ... |
| diminutive | small, little | klein |
| aragonite | {{< wp "aragonite" >}} | mineraal |
| unvarnished | plain, clear - straightforward | onverbloemd |
| meticulous | taking or showing extreme care to details | nauwgezet |
| idiosyncrasies | a characteristic, habit | een eigenaardigheid aan een persoon |
| impunity | immunity to damaging effects as of an action | straffeloosheid |
| incursion | a running in | inval |
| tenured | of holding/having | in aanstelling |
| scarcity | insufficiency | schaarsheid |
| oscillation | the act of swinging and moving from/to - fluctuating | ... |
| inexorable | unalterable | onverbiddelijk |
| rendition | an interpretation | weergave |
| mesmerizing | to compel by fascination | betoverend |
| introspection | mental process observing | introspectie |
| to churn | to produce mechanically in a hurry (like a container or machine to make butter) | ... |
| precipitated | to cast/send violently | neergeslagen |
| to atrophy | to undergo degeneration | ... |
| cubism | a style of painting & sculpture | ... |
| percussive | having an impact/blow | ... |
| to lodge in the head | to household - to store thoughts ? | ?? |
| reverberating | to rebound/recoil | weerkaatsend |
| dilettante | a lover of fine art and science - an amatuer at | ... |
| scorned | an object of contempt (disgrace) | geminacht |
| fastidious | critically or demanding | kieskeurig |
| allegory | fable | allegorie |
| latent | present but not visible, existing as potential | ... |
| barnacle | a person or thing that keeps firm hold of | ... |
| incessantly | continuing without interruption - unceasing | constant |
| contrivance | something obviously planned or forced | vernuft |
| latticce | a window or gate-like object | traliewerk |
| exhiliration | stimulating | ontdrukkend |
| mammalian | belonging to the class of mammalia | zoogdier- |
| untethered | to release from a chain/rope | ongebonden |
| vetted | to check for accuracy | doorlichten |
| fringe | a decorative border (from a raveled edge) | franje |
| parlance | in a manner of speaking | bij wijze van |
| sequestered | to remove/separate | teruggetrokken |
| cloistering | a covered walk/courtyard | opsluiting |
| anomalous | inconsistent | abnormaal |
| acumen | keen insight | scherpzinnigheid |
| cohort | a group or company | een groep |
| dwindling | to fall away/become smaller and smaller | afnemend |
| prodigious | wonderful - marvel | wonderbaarlijk |
| fortnight | 2 weeks | over twee weken |
| excreted | separated from an organic body | uitgescheiden |
| atoll | a ring-shaped coral reef | ... |
| designate | to denote, indicate, name | aanwijzen |
| desolate | laid waste | verlaten |
| emanating | to send forth or to emit | voortbrengend |
| coalesced | grown together into one body | samenvloeiend |
| quibbling | small objections | spitsvondigheden |
| litigiousness | pertaining to lawsuit | betwistbaarheid |
| glutton | a person who eats and drinks excessively | veelvraat |
| winnowing | to drive or blow away by fanning | ... |
| conflagration | a destructive fire | brand |
| anguish | suffering - pain | angst |
| ingrate | ungrateful | ondankbaar |
| scrupulously | precise or exact | nauwgezet |
| disdained | to despise | verachtten |
| slovenly | untidy in appearance or habits | slordig |
| to contort | twist or bend out of shape | verdraaien |

View File

@ -1,22 +0,0 @@
+++
title = "code"
draft = false
tags = [
"code"
]
date = "2013-03-12"
+++
# Code
[<img style='' src='/img//code.jpg|'>]({{< relref "code.md" >}})
## Inhoudsopgave
<img style='' src='/img/indexmenu>code|js navbar nocookie'>
## Links
#### Bijleren: algemeen
* http:*codingkata.org/ - kleine oefeningen afhankelijk van uw skill level in *éénder welke taal//
* http:*www.codeschool.com/ - Learn by Doing - screencasts, tutorials, heel uitgebreid - bvb [Rails for Zombies](http:*railsforzombies.org/)

View File

@ -1,18 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"build",
"home"
]
date = "2013-03-12"
+++
# Building & Compiling
<img style='' src='/img/indexmenu>.|js navbar nocookie'>
## Log management
1. http://www.splunk.com/ om zaken visueel samen te vatten, zelfde exceptions uit logs te halen, statistiekjes te trekken, ...
2. [unix/cmd]({{< relref "wiki/unix/cmd.md" >}}) tools zoals grep en sed gebruiken om de rest manueel te doen!

View File

@ -1,42 +0,0 @@
+++
title = "ant"
draft = false
tags = [
"code",
"build",
"ant"
]
date = "2013-03-12"
+++
# Ant scripts etc
### JSP files precompilen met tomcat lib
```xml
<project name######"vac Precompilatie" default"precompile-all" basedir=".">
<taskdef classname######"org.apache.jasper.JspC" name"jasper">
<!-- -Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true -->
<classpath id="jasperpath">
```et
<include name="*.jar"/>
</fileset>
```et
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<target name="precompile-all">
<mkdir dir="target/jsp" />
<jasper
validatexml="false"
uriroot="target/vac"
outputdir="target/jsp" />
</target>
</project>
```
Als ge dit bovenstaande gebruikt, jasper als dep. toevoegen (`org.apache.tomcat jasper 6.0.3x`)

View File

@ -1,13 +0,0 @@
+++
title = "grunt"
draft = false
tags = [
"code",
"build",
"grunt"
]
date = "2013-03-12"
+++
# Grunt
:exclamation: Zie [code/javascript/frameworks/yeoman]({{< relref "wiki/code/javascript/frameworks/yeoman.md" >}})

View File

@ -1,116 +0,0 @@
+++
title = "jsunit"
draft = false
tags = [
"code",
"build",
"jsunit"
]
date = "2013-05-17"
+++
# JsUnit Testen
## Integratie met een Ant build
Zie http://www.jsunit.net/
Hoofd JUnit klasse die gestart moet worden als junit tag vanuit ant: **`net.jsunit.StandaloneTest`**<br/><br/>
Voor uitleg over de parameters, zie jsunit website.
:exclamation: Belangrijk: JsUnit draait binnen een aparte context op een embedded Jetty server. Dit wil zeggen dat javascript test suites (html pagina's) die javascript files includen wel binnen de context staan, maar javascript files in een web project binnen eclipse bijvoorbeeld niet. Oplossing: kopiëer alle JS files voordat de test gedraaid wordt binnen de context.
Voor JS files te testen binnen een jar moeten die ook unjarred worden.
### Ant build snippet
```xml
<!-- JsUnit properties -->
<property name######"jsunit.lib.dir" value"${basedir}/../buildscripts/${lib.dir}/jsunit" />
<property name######"jsunit.browserFileNames" value"c:<br/><br/>program files<br/><br/>internet explorer<br/><br/>iexplore.exe,c:<br/><br/>program files<br/><br/>Mozilla Firefox<br/><br/>firefox.exe" />
<property name######"jsunit.port" value"9001" />
<property name######"jsunit.suite" value"suite.html" />
<property name######"jsunit.url" value"http:*localhost:9001/jsunit/testRunner.html?testPage######http:*localhost:9001/jsunit/tests/${jsunit.suite}&amp;autoRuntrue" />
<property name######"jsunit.common.jar" value"${web.lib.dir}/commonResources.jar" />
<property name######"jsunit.src.js" value"${web.dir}/resources/scripts" />
<property name######"jsunit.src.tests" value"test/jsunit" />
<property name######"jsunit.target" value"${target.dir}/jsunit" />
<property name######"jsunit.target.js" value"${jsunit.target}/tests/js" />
<property name######"jsunit.target.tests" value"${jsunit.target}/tests" />
<path id="jsunit.classpath">
```et
</path>
<target name######"jsunit-tests" depends"-clean-reports, -compile-test, -jsunit, -junit-report"/>
<target name######"-jsunit" if"jsunit.tests.present">
<junit failureproperty######"junit.failed" errorproperty"junit.error">
<formatter type######"plain" usefile"false"/>
<classpath refid="jsunit.classpath"/>
<sysproperty key######"java.util.logging.config.file" value"${jsunit.target.tests}/logging.properties"/>
<sysproperty key######"browserFileNames" value"${jsunit.browserFileNames}"/>
<sysproperty key######"description" value"JsUnit server"/>
<sysproperty key######"logsDirectory" value"${report.dir}"/>
<sysproperty key######"port" value"${jsunit.port}"/>
<sysproperty key######"resourceBase" value"${jsunit.target}"/>
<sysproperty key######"url" value"${jsunit.url}"/>
<test name="net.jsunit.StandaloneTest"/>
</junit>
</target>
<target name######"-compile-jsunit" depends"-jsunit-check" if="jsunit.tests.present">
<antcall target="-jsunit-copy-lib" />
<antcall target="-jsunit-copy-common-js" />
<antcall target="-jsunit-copy-tests" />
<antcall target="-jsunit-copy-js" />
<antcall target="-jsunit-build-suite" />
</target>
<target name="-jsunit-check">
<available file######"${jsunit.src.tests}" property"jsunit.tests.present"/>
</target>
<target name="-jsunit-copy-lib">
<copy todir="${jsunit.target}">
```et
</copy>
</target>
<target name="-jsunit-copy-common-js">
<unjar src######"${jsunit.common.jar}" dest"${jsunit.target.js}/common">
<patternset>
<include name="**/*.js" />
<exclude name="**/resourcesmini/**"/>
</patternset>
<mapper type="flatten"/>
</unjar>
</target>
<target name="-jsunit-copy-tests">
<copy todir="${jsunit.target.tests}">
```et
</copy>
</target>
<target name="-jsunit-copy-js">
<copy todir="${jsunit.target.js}">
```et
</copy>
</target>
<target name="-jsunit-build-suite">
<taskdef name######"jsUnitSuiteBuilder" classname"be.cegeka.ant.JsUnitSuiteBuilder" classpath="${jsunit.lib.dir}/java/ant/cegekant.jar" />
<jsUnitSuiteBuilder testdir######"${jsunit.target.tests}" testsuitefilename"${jsunit.target.tests}/${jsunit.suite}"
suitetemplatefilename="${jsunit.target.tests}/suite_template.html"/>
</target>
```
### Suite.html automatisch genereren
`testRunner.html` draait standaard een html pagina als test suite waar alle anderen geïnclude in worden. Een JS test methode moet beginnen met `test`X(). Standaard assertions kunnen gebruikt worden die deel van JsUnit zelf zijn, zie die documentatie.
Om niet altijd de hoofd suite aan te moeten passen, kan een ant plugin gemaakt worden die een bepaald pad scant op html files en deze recursief toevoegt aan de suite zelf. Die wordt bij elke build dus in principe overschreven.
Hiervoor is een plugin geschreven op: http://code.google.com/p/cegekant/<br/><br/>
[Volledige source suite builder](http://code.google.com/p/cegekant/source/browse/trunk/src/be/cegeka/ant/JsUnitSuiteBuilder.java)

View File

@ -1,610 +0,0 @@
+++
title = "maven"
draft = false
tags = [
"code",
"build",
"maven"
]
date = "2013-06-05"
+++
# Maven2 Build stuff
:exclamation: **properties** guide: http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide
## javascript files automatisch minify-en
```xml
<profiles>
<profile>
<id>minify</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<warSourceExcludes>**/js/**</warSourceExcludes>
</configuration>
</plugin>
<plugin>
<groupId>net.tqh.plugins</groupId>
<artifactId>uglifyjs-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<sourceDirectory>src/main/webapp/js</sourceDirectory>
<outputDirectory>target/${project.name}-${version}/js</outputDirectory>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>uglify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
```
Bron: https:*github.com/mishoo/UglifyJS - maven plugin gebruikt `Rhino` om dit uit te voeren. Kan ook met `node` uitgevoerd worden - gebruik bij voorkeur `r.js` (zie http:*requirejs.org/docs/optimization.html)
## Argumenten als system property meegeven aan testen
Maven forkt by default dus `-Dbla=blie` gaat niet werken, dit is een property voor het maven java commando, maar niet voor de test zelf.
Oplossing: ` mvn test -DargLine######"-Dsystem.test.propertytest"`
**argLine** gebruiken. Zie:
1. http://www.cowtowncoder.com/blog/archives/2010/04/entry_385.html
2. [maven properties guide](http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide)
## Een single-deps jar mekan met maven assembly
```xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
```
En dan met `mvn assembly:single` uitvoeren. Dit maakt in uw target dir een file genaamd `bla-1.0-SNAPSHOT-jar-with-dependencies.jar`. `java -jar [jar]` werkt dan.
## Een test jar maken met maven assembly
Met `maven assembly` kan je files packagen na het compileren van tests maar voor het runnen. Op die manier kunnen we dus bvb class files in een jar packagen (of resources in een zip). Daarna manueel installeren in de repository ofzoiets.
Plugin:
```xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
<executions>
<execution>
<id>create-test-dependency</id>
<phase>process-test-classes</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>gatecontrol</finalName>
<attach>false</attach>
<descriptors>
<descriptor>test-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
```
De externe assembly file:
```xml
<assembly>
<id>testjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
```ets
```et
<directory>target/test-classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**</include>
</includes>
</fileSet>
</fileSets>
</assembly>
```
:exclamation: test jars zijn precies niet **transitief** qua dependencies? <br/><br/>
Als je een test-jar (die dus op `scope test` staat) wil includen in je eigen `assembly:single` jar, kan je `classifier tests` gebruiken:
```xml
<dependency>
<groupId>be.bla</groupId>
<artifactId>bla-blie</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
```
Dan wordt die test jar mee gepackaged, maar zijn dependencies blijbkaar niet?
## Profiles en properties
#### activeByDefault
Zie http://java.dzone.com/articles/maven-profile-best-practices - **nooit** gebruiken! Waarom?
> This flag activates the profile if no other profile is activated. Consequently, it will fail to activate the profile if any other profile is activated. This seems like a simple rule which would be hard to misunderstand, but in fact it's surprisingly easy to be fooled by its behaviour. When you run a multimodule build, the activeByDefault flag will fail to operate when any profile is activated, even if the profile is not defined in the module where the activeByDefault flag occurs.
In plaats daar van:
```xml
<profile id="nofoobar">
<activation>
<property>
<name>!foo.bar</name>
</property>
</activation>
</profile>
```
## JAXB generatie
#### Genereer endpoints vanaf WSDL
```xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>${org.codehaus.mojo.jaxws.maven.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/resources/wsdl</wsdlDirectory>
<packageName>com.x.interfaces.ws</packageName>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws</sourceDestDir>
</configuration>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>${com.sun.xml.ws.jaxws.version}</version>
</dependency>
</dependencies>
</plugin>
```
Zie http://rphgoossens.wordpress.com/2011/02/20/developing-a-contract-first-jax-ws-webservice/
Genereer de code met `mvn jaxws:wsimport` goal.
#### Genereer JAXB Java objecten vanaf XSD
Zelfde pincipe, andere `goal`:
```xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${org.jvnet.jaxb2.maven2.maven.jaxb2.plugin.version}</version>
<executions>
<execution>
<id>crm_generation</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/schema</schemaDirectory>
<schemaIncludes>
<include>y.wsdl</include>
</schemaIncludes>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.x.interfaces</generatePackage>
</configuration>
</execution>
</executions>
</plugin>
```
## Integratie met Ant
Maven kan ook ant tasks uitvoeren. Dit door ant code te embedden in de pom.xml op de volgende manier:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<property name######"target.war" value"bla.war" />
<property name######"zip.name" value"bla.zip" />
<ant antfile######"build.xml" inheritRefs"true" inheritAll="true">
<target name="buildZip" />
</ant>
</tasks>
</configuration>
<goals>
<goal>install</goal>
</goals>
</plugin>
```
Binnen de configuration tag zit ant code, met de ant tag roep ik een externe build xml aan. Op die manier kan je dus een ant buildfile volledig naast een pom.xml maven2 file plaatsen, en properties doorgeven! Die ant task wordt uitgevoerd met het commando `mvn antrun:run` of bij bepaalde geconfigureerde goals.
Voorbeeld: http://maven.apache.org/plugins/maven-antrun-plugin/
#### Aan bepaalde phase hangen
Zie http://www.avajava.com/tutorials/lessons/what-are-the-phases-of-the-maven-default-lifecycle.html
Om nog rap een property file te kopiëren, best aan `prapare-package` phase hangen (maven 2.1+):
```xml
<profiles>
<profile>
<id>env</id>
<activation>
<property>
<name>env</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="Env property detected, copying ${env} to output directory..." />
<copy file######"src/main/resources/template/env.${env}.properties" tofile"${project.build.outputDirectory}/env.properties"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
```
## Javadoc genereren
Deze plugin nodig:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<reportOutputDirectory>release/doc</reportOutputDirectory>
<destDir>javadoc</destDir>
<doctitle>API for ${project.name} ${project.version}</doctitle>
<windowtitle>API for ${project.name} ${project.version}</windowtitle>
</configuration>
</plugin>
```
:exclamation: output dir = `${reportOutputDirectory}/${destDir}`<br/><br/>
Voorbeeld: http://maven.apache.org/plugins/maven-javadoc-plugin/examples/output-configuration.html
## Deployen met maven
### Jetty integratie en auto-deploy
#### jetty run
Integratie met jetty en maven2: gebruik `mvn jetty:run` om automatisch de jetty server op te starten.<br/><br/>
Het is ook mogelijk om die te laten scannen voor resource changes met `scanIntervalSeconds` - server start automatisch (normaal gezien...)
```xml
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<stopPort>9966</stopPort>
<stopKey>comeet</stopKey>
<scanIntervalSeconds>5</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8089</port>
</connector>
</connectors>
</configuration>
</plugin>
```
:exclamation: Vanaf Jetty plugin 7 zijn packages hernoemd en zo, zie http://wiki.eclipse.org/Jetty en de migratie van 6->7->...9
##### Debug poort instellingen
Gebruikt `MAVEN_OPTS` JVM parameters (omdat het proces niet geforked wordt?): http://docs.codehaus.org/display/JETTY/Debugging+with+the+Maven+Jetty+Plugin+inside+Eclipse
```
-Xdebug -Xnoagent -Djava.compiler######NONE -Xrunjdwp:transportdt_socket,address######4000,servery,suspend=y
```
##### JNDI Datasources definiëren
Kan in webapp/WEB-INF/jetty-env.xml:
```xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-*Mort Bay Consulting*DTD Configure*EN" "http:*jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id######"partnerwerkingDataSource" class"org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/partnerwerkingDataSource</Arg>
<Arg>
<New class="oracle.jdbc.pool.OracleDataSource">
<Set name="URL">${database.url}</Set>
<Set name="user">${database.user}</Set>
<Set name="password">${database.password}</Set>
</New>
</Arg>
</New>
</Configure>
```
wordt dan automatisch door `jetty:run` opgepikt.
#### auto-start bij integratie testen (failsafe plugin)
Als we aan bovenstaande plugin ook nog `executions` opgeven, start jetty automatisch bij `pre-integration-test` en stopt hij automatisch bij `-post-integration-test`:
```xml
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
```
`daemon` moet op **true** staan omdat de bovenstaande plugin (jetty6) geen fork doet en dan natuurlijk geen testen gedraaid worden...
### Tomcat deploy
Op verschillende omgevingen deployen kan door verschillende profielen aan te maken in de pom.xml file, en dan als env. parameter `-Denv=[gewenste env value]` de te deployen mee te geven:
```xml
<profiles>
<profile>
<activation>
<property>
<name>env</name>
<value>test</value>
</property>
</activation>
<properties>
<server.url>http://blatomcat:8888/manager</server.url>
<server.username>user</server.username>
<server.password>pass</server.password>
</properties>
</profile>
</profiles>
```
Die properties die hierboven staan worden dan in deze plugin ingevuld:
```xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<url>${server.url}</url>
<username>${server.username}</username>
<password>${server.password}</password>
</configuration>
</plugin>
```
Uitvoeren met `mvn tomcat:deploy [-Denv=x]`<br/><br/>
Voorbeelden en meer uitleg: http://mojo.codehaus.org/tomcat-maven-plugin/
## War name veranderen
Staat default op `${project.build.finalName}` wat neerkomt op artifactId-version.war.
Te veranderen door `<warName>blar</warName>` in `<configuration/>` te plaatsen in de `maven-war-plugin`.<br/><br/>
**Zonder** .war ext. dus.
Zie http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#warName
## Jar source code downloaden
```
mvn dependency:sources
```
Ook mogelijk in de pom door per dependency `downloadSources` op `true` te zetten, of via de `eclipse:eclipse` goal plugin:
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
... other stuff ...
</configuration>
</plugin>
</plgins>
</build>
```
Vergeet niet dan als property `-DdownloadSources=true` mee te geven.
#### eclipse:eclipse genereert ook de .project file
Library dependencies worden daar automatisch aan toegevoegd, maar alles staat onder **M2_REPO**/org/.../bla.jar en Eclipse moet weten waar lokaal de repository staat. Zie ook http://maven.apache.org/guides/mini/guide-ide-eclipse.html - Dit commando uitvoeren & eclipse herstarten:
`mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo`
#### Automatisch source files encoden
Je kan met die plugin ook extra configuratie meegeven die de `.java` files qua encoding goed zet:
```xml
<additionalConfig>
```
<name>.settings/org.eclipse.core.resources.prefs</name>
<content>
<![CDATA[eclipse.preferences.version######1${line.separator}encoding/<project>${project.build.sourceEncoding}${line.separator}]]>
</content>
```
</additionalConfig>
```
## Dependency tree tonen
```
mvn dependency:tree > deptree.out
```
Produceert rommel in het volgend formaat:
```
[INFO] [dependency:tree {execution: default-cli}]
[INFO] be.--api:jar:2.21-SNAPSHOT
[INFO] +- be.-support:jar:7.21-SNAPSHOT:compile
[INFO] | +- org.easytesting:fest-assert:jar:1.2:test (scope managed from compile)
[INFO] | | <br/>- org.easytesting:fest-util:jar:1.1:test
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] | | <br/>- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] | +- org.objenesis:objenesis:jar:1.2:compile
[INFO] | +- net.sf.ehcache:ehcache:jar:1.6.0:compile
[INFO] | +- log4j:log4j:jar:1.2.15:compile
[INFO] | | <br/>- javax.mail:mail:jar:1.4:compile
[INFO] | +- commons-codec:commons-codec:jar:1.3:compile
[INFO] | +- jmimemagic:jmimemagic:jar:0.1.2:compile
[INFO] | | +- oro:oro:jar:2.0.8:compile
[INFO] | | <br/>- commons-logging:commons-logging:jar:1.1.1:compile (version managed from 1.0.4)
[INFO] | +- commons-io:commons-io:jar:1.4:compile
[INFO] | +- org.htmlcleaner:htmlcleaner:jar:2.1:compile
..
```
## Een bepaalde test draaien via Maven
```
mvn test -Dtest=[testClass] -P [profile]
```
Waarbij `profile` het profiel is die de surefire plugin heeft - bijvoorbeeld:
```xml
<profile>
<id>endtoend</id>
<activation>
<property>
<name>endtoend</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skip>false</skip>
<argLine>-Xms128M -Xmx512M -XX:MaxPermSize=512M</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
```
:exclamation: Als een bepaalde jar nog deployed moet worden (naar Jetty bvb) voor het runnen van de test (scenario testen zoals selenium en webdriver), moet de `install` in plaats van `test` goal uitgevoerd worden. <br/><br/>
Het kan *ook* zijn dat nog zaken geïnstalleerd moeten worden in de lokale Maven repository (het root project) -> eerst `mvn clean install` op het root project doen (voor *vac* is dit zo). Dit is omdat het endtoend project daarop afhangt, en de compile dan faalt.
## Een jar manueel in de repository installeren
Gebruik het volgende commando:
> `mvn install:install-file -Dfile######x.jar -DgroupIdcom.group -DartifactId######jarName -Dversion1.0.0 -Dpackaging=jar`
Wens je dit in de **remote repository** te installeren, gebruik dan `mvn deploy:deploy-file` met als extra parameter de url van de repository via de `-Durl=repoUrl` optie.
## De maven java compiler versie goed zetten
Gebeurt in een plugin in de `build` fase:
```xml
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
```

View File

@ -1,409 +0,0 @@
+++
title = "appengine"
draft = false
tags = [
"code",
"build",
"maven",
"appengine"
]
date = "2013-03-12"
+++
# Maven Google Appengine
#### maven-cli-plugin gebruiken als semi-hot-deployer
Zie [Mavenizing my project](http://blog.cloudme.org/2010/04/mavenizing-my-project/)
In plaats van betalende JRebel kan je bvb. voor GAE de jetty server op zetten met `gae:run`, maar alles in webapp ziet hij niet als een change.
* In Tab1: `mvn gae:run`.
* In Tab2: `mvn cli:execute` en dan commando's `compile war` in aparte tab die de eerste tab (nog actieve maven) oppikt dan.
Andere mogelijkheid is natuurlijk voor niet-GAE dingen, `jetty:run` gebruiken (zie [code/build/maven]({{< relref "wiki/code/build/maven.md" >}})).
:exclamation: de plugin is **niet werkend met maven 3**, zie https://github.com/mrdon/maven-cli-plugin/wiki/Maven-3.0-Support -
```
INFO]
[INFO] --- maven-cli-plugin:1.0.6:execute (default-cli) @ gatecontrolweb ---
[INFO] Waiting for commands...
maven2> clean
[INFO] Executing: org.apache.maven.plugins:maven-clean-plugin [clean]
[ERROR] Unable to complete running command: clean
java.lang.RuntimeException: org.apache.maven.plugin.MojoExecutionException: Unable to execute mojo
at org.twdata.maven.cli.commands.ExecuteGoalCommand.run(ExecuteGoalCommand.java:111)
at org.twdata.maven.cli.CliShell.interpretCommand(CliShell.java:48)
at org.twdata.maven.cli.CliShell.run(CliShell.java:29)
at org.twdata.maven.cli.AbstractCliMojo.displayShell(AbstractCliMojo.java:144)
at org.twdata.maven.cli.AbstractCliMojo.access$000(AbstractCliMojo.java:22)
at org.twdata.maven.cli.AbstractCliMojo$1.run(AbstractCliMojo.java:116)
Caused by: org.apache.maven.plugin.MojoExecutionException: Unable to execute mojo
at org.shaded.mojoexecutor.MojoExecutor.executeMojo(MojoExecutor.java:106)
at org.twdata.maven.cli.MojoCall.run(MojoCall.java:31)
at org.twdata.maven.cli.commands.ExecuteGoalCommand.runMojo(ExecuteGoalCommand.java:125)
at org.twdata.maven.cli.commands.ExecuteGoalCommand.run(ExecuteGoalCommand.java:104)
... 5 more
Caused by: java.lang.UnsupportedOperationException
at org.apache.maven.plugin.internal.DefaultPluginManager.executeMojo(DefaultPluginManager.java:90)
at org.shaded.mojoexecutor.MojoExecutor.executeMojo(MojoExecutor.java:104)
... 8 more
```
Tof...
#### maven-endpoint-plugin
:exclamation: Google App Engine **endpoint metadata** genereren via maven kan ook en is een totaal andere plugin: http://code.google.com/p/maven-endpoint-plugin/
Hiervoor moet je de volgende repository gebruiken (zit niet in de central repo):
```xml
<repositories>
<repository>
<id>cbreleases</id>
<url>https://repository-michael.forge.cloudbees.com/release</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>cbreleases</id>
<url>https://repository-michael.forge.cloudbees.com/release</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
```
#### maven-gae-plugin
Laatste versie van de "officiele" plugin op https://github.com/maven-gae-plugin/maven-gae-plugin
Een compleet voorbeeld gebaseerd op de jsp archetype:
```xml
<?xml version######"1.0" encoding"UTF-8"?>
<project xmlns######"http:*maven.apache.org/POM/4.0.0" xmlns:xsi"http:*www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:*maven.apache.org/POM/4.0.0 http:*maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- The Basics -->
<groupId>com.myapp.test</groupId>
<artifactId>testapp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>lkjm</name>
<dependencies>
<!-- Google App Engine meta-package -->
<dependency>
<groupId>net.kindleit</groupId>
<artifactId>gae-runtime</artifactId>
<version>${gae.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!--
J2EE Servlet API. We need it to compile IndexServlet class. You can
probably remove it, if you don't explicitly use Servlets
-->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.5_spec</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<!--
Make use of JSP tags. Remove, if you don't use JSPs
-->
<dependency>
<artifactId>standard</artifactId>
<groupId>taglibs</groupId>
<version>1.1.2</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<!-- These dependencies are here just for enabling logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.24</version>
</dependency>
<!-- Test scope -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<!--
GAE libraries for local testing as described here:
http://code.google.com/appengine/docs/java/howto/unittesting.html
-->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo2-api</artifactId>
<version>2.3-eb</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>transaction-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<!--
This plug-in "enhances" your domain model objects (i.e. makes them
persistent for datanucleus)
-->
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>1.1.4</version>
<configuration>
<!--
Make sure this path contains your persistent classes!
-->
<mappingIncludes>**/model/*.class</mappingIncludes>
<verbose>true</verbose>
<enhancerName>ASM</enhancerName>
<api>JDO</api>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus.version}</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>transaction-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>${datanucleus.version}</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-enhancer</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo2-api</artifactId>
<version>2.3-ec</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/appengine-web.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<!--
The actual maven-gae-plugin. Type "mvn gae:run" to run project, "mvn
gae:deploy" to upload to GAE.
-->
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<version>0.9.5</version>
</plugin>
<!--
Upload application to the appspot automatically, during
release:perform
-->
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<goals>gae:deploy</goals>
</configuration>
</plugin>
<!-- Java compiler version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- Specify hard-coded project properties here -->
<properties>
<!-- Sets the project's default encoding.
http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--
This is just for "eclipse:eclipse" goal to always attempt downloading
sources
-->
<downloadSources>true</downloadSources>
<!--
Specify AppEngine version for your project. It should match SDK
version pointed to by ${gae.home} property (Typically, one used by
your Eclipse plug-in)
-->
<gae.version>1.6.5</gae.version>
<!--
Upload to http://test.latest.<applicationName>.appspot.com by default
-->
<gae.application.version>test</gae.application.version>
<datanucleus.version>1.1.5</datanucleus.version>
</properties>
<profiles>
<!--
We can configure our integration server to activate this profile and
perform gae:deploy, thus uploading latest snapshot to the
http://1.latest.<applicationName>.appspot.com automatically
-->
<profile>
<id>integration-build</id>
<properties>
<gae.application.version>stage</gae.application.version>
</properties>
</profile>
<!--
This profile will activate automatically during release and upload
application to the http://2.latest.<applicationName>.appspot.com (We
might want to set the 2nd version as our applications Default version
to be accessible at http://<applicationName>.appspot.com)
-->
<profile>
<id>release-build</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<properties>
<!--
During release, set application version in appengine-web.xml to 2
-->
<gae.application.version>release</gae.application.version>
</properties>
</profile>
</profiles>
</project>
```
Hiermee kan je:
1. `mvn gae:unpack` uitvoeren om de GAE SDK in uw maven repo te unpacken zodat `${gae.home}` niet nodig is in de pom (vanaf 0.9.5)
1. `mvn gae:run` uitvoeren om een devserver te starten
##### Andere versie
Een oudere versie (??) is deze:
```xml
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
```
Hiermee kan je:
1. `mvn appengine:devserver` gebruiken om lokaal een jetty op te starten, en
1. `mvn appengine:update` om te deployen via de commandline.

View File

@ -1,36 +0,0 @@
+++
title = "releasing"
draft = false
tags = [
"code",
"build",
"maven",
"releasing"
]
date = "2013-03-28"
+++
# Maven Releasing
Opmerking: de te releasen code zetten onder een folder C:/xxx en niet te diep nesten (CVS kan te lange folder structuur niet uitchecken)
#### Hoe een maven release uitvoeren ?
1. (**eenmalig uit te voeren** :exclamation:) voor elke nieuwe release maken we op een gepast moment een CVS 'maintenance release branch' waarop we de laatste bugfixen uitvoeren :
1. deze zal steeds de vorm 'versiez_y_x' hebben waarbij we z_y vervangen door een TOP release nummer b.v. 'versie2_7_x'
2. deze branch wordt later ook gebruikt om maintenance releases op uit te voeren (emergency / extra TOP's om bugfixes door te voeren)
3. gebruik volgend maven commando om de branch aan te maken (gebruik wel de juiste branchname en username/password voor cvs !) :
1. CVS --> mvn release:branch -DupdateBranchVersions######true -DupdateWorkingCopyVersionstrue -DbranchName######versiez_y_x -DautoVersionSubmodulestrue -Dusername######xxxx -Dpasswordyyyyy
2. SVN --> zelfde als CVS, maar zonder username en password
4. bij het uitvoeren van het commando komt maven vragen achter het versienummer in de branch en de nieuwe versie in de hoofdbranch.
5. De branch versie nummer zal 'z.y.0-SNAPSHOT' zijn (in dit voorbeeld '2.7.0-SNAPSHOT')
6. De hoofdbranch versie zal 'z.y+1-SNAPSHOT' zijn (in dit voorbeeld '2.8-SNAPSHOT'
2. update het project via wincvs naar de correcte branch 'versiez_y_x' (in het voorbeeld versie2_7_x).
3. bereidt de nieuwe release voor door het commando mvn release:prepare -Dresume######false -DpreparationGoals"clean install" -DautoVersionSubmodules=true -Dusername######xxxx -Dpasswordyyyyy uit te voeren.
4. Als dit niet lukt met de fout 'address in use', dan moet je de maven opts aanpassen (remote debugging weghalen). Maven zal je vragen achter de release versie nummer (in het voorbeeld wordt dit 2.7.0) en achter de volgende development versie (in het voorbeeld 2.7.1-SNAPSHOT).
5. finaliseer de release via het commando mvn release:perform -Dusername######xxxx -Dpasswordyyyyy
6. pas de pom.xml van relevant projecten aan
7. pas eventueel de prj/pom.xml & vdabbuild.xml aan om je EAR / WAR automatisch in de deployment TAR te stoppen.
#### Hoe skip ik mijn testen bij een release?
`-Darguments="-DskipTests"` meegeven

View File

@ -1,37 +0,0 @@
+++
title = "msbuild"
draft = false
tags = [
"code",
"build",
"msbuild"
]
date = "2014-01-31"
+++
# MSBuild
## Adding/Modifying build steps
##### Q: Hoe kan ik iets aan de build toevoegen zonder de XAML template te wijzigen?
A: Maak een nieuw **dummy solution** met één project, waar in de `csproj` file het volgende bijgevoegd is:
```xml
<Target Name="AfterBuild">
<Exec Condition######" '$(Configuration)|$(Platform)' 'Release|x86' " Command="attrib -r ../../AUP/C-eHealthPortal.aup" />
<BuildUpdate Condition######" '$(Configuration)|$(Platform)' 'Release|x86' " ProjectFile######"../../AUP/C-eHealthPortal.aup" PublishLocations"LOCAL" />
<Exec Condition######" '$(Configuration)|$(Platform)' 'Release|x86' " Command="attrib +r ../../AUP/C-eHealthPortal.aup" />
</Target>
```
(Ter info, `BuildUpdate` is een tag die met een using included werd: `<UsingTask AssemblyFile######"../../AUP/Kjs.AppLife.Update.BuildUpdateTask.dll" TaskName"Kjs.AppLife.Update.MSBuild.BuildUpdate" />`)
:exclamation: Indien volgorde belangrijk is, aan MSBuild als parameter deze solution als laatste builden, zodat de output/bin folder al de juiste gegevens bevat.
## WebServers drop folder
##### Q: Ik wil geen _publishedWebsite.zip waar heel diep PackageTmp in zit maar de exploded dir!
A: Append in `MSBuild` arguments `;DeployOnBuild=true` - zie [MSDN DeployOnBuild property](http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.workflow.activities.msbuild.deployonbuild.aspx)
Er is blijkbaar ook een `CreatePackageOnPublish` property (?)

View File

@ -1,138 +0,0 @@
+++
title = "scons"
draft = false
tags = [
"code",
"build",
"scons"
]
date = "2014-03-24"
+++
# SCons
1. [SCons Wiki Frontpage](http://www.scons.org/wiki/FrontPage)
2. [Single HTML Manpage](http://www.scons.org/doc/HTML/scons-man.html#lbAF)
3. [SCons Construction Variables](http://www.scons.org/doc/0.96.90/HTML/scons-user/a3061.html) om bvb de compiler te specifiëren.
### Opsplitsen SConstruct en SConscript
Waarom? http://www.scons.org/doc/2.1.0/HTML/scons-user/c3356.html
Build output definiëren, duplicate source files, etc. Voorbeeld `SConstruct` file:
```python
SConscript('SConscript', variant_dir######'build', duplicate0)
```
Voorbeeld file om Google Test mee te (proberen) builden `SConscript`:
```python
def Glob( pattern ###### '*.*', dir '.' ):
import os, fnmatch
files = []
for file in os.listdir( Dir(dir).srcnode().abspath ):
if fnmatch.fnmatch(file, pattern) :
files.append( os.path.join( dir, file ) )
return files
# construction variables: http://www.scons.org/doc/0.96.90/HTML/scons-user/a3061.html
env ###### Environment(CXX 'g++',
CPPPATH = '../:./include')
# add to library search path env.Append(LIBPATH = ['/usr/local/lib/'])
# add to libraries link path env.Append(LIBS = ['SDL_image','GL'])
env.Append(CPPFLAGS = ['-isystem ./include'])
env.Append(CXXFLAGS = ['-g', '-Wall', '-Wextra', '-pthread'])
env.SharedLibrary(target ###### 'gtest_main.dll', source ['../src/gtest-all.cc'])
# after that, we should link with gtest_main
```
Poging tot converteren van deze voorbeeld `Makefile` - supplied bij de gtest sources:
```
# A sample Makefile for building Google Test and using it in user
# tests. Please tweak it to suit your environment and project. You
# may want to move it to your project's root directory.
#
# SYNOPSIS:
#
# make [all] - makes everything.
# make TARGET - makes the given target.
# make clean - removes all files generated by make.
# Please tweak the following variable definitions as needed by your
# project, except GTEST_HEADERS, which you can use in your own targets
# but shouldn't modify.
# Points to the root of Google Test, relative to where this file is.
# Remember to tweak this if you move this file.
GTEST_DIR = ..
# Where to find user code.
USER_DIR = ../samples
# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem $(GTEST_DIR)/include
# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread
# All tests produced by this Makefile. Remember to add new tests you
# created to the list.
TESTS = sample1_unittest
# All Google Test headers. Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h <br/>
$(GTEST_DIR)/include/gtest/internal/*.h
# House-keeping build targets.
all : $(TESTS)
clean :
rm -f $(TESTS) gtest.a gtest_main.a *.o
# Builds gtest.a and gtest_main.a.
# Usually you shouldn't tweak such internal variables, indicated by a
# trailing _.
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized. This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
gtest-all.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c <br/>
$(GTEST_DIR)/src/gtest-all.cc
gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c <br/>
$(GTEST_DIR)/src/gtest_main.cc
gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^
gtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $@ $^
# Builds a sample test. A test should link with either gtest.a or
# gtest_main.a, depending on whether it defines its own main()
# function.
sample1.o : $(USER_DIR)/sample1.cc $(USER_DIR)/sample1.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1.cc
sample1_unittest.o : $(USER_DIR)/sample1_unittest.cc <br/>
$(USER_DIR)/sample1.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/sample1_unittest.cc
sample1_unittest : sample1.o sample1_unittest.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
```

View File

@ -1,44 +0,0 @@
+++
title = "teamcity"
draft = false
tags = [
"code",
"build",
"teamcity"
]
date = "2015-07-13"
+++
# Teamcity
**Build pipeline** voor continuous deployment: zie [http:*robdmoore.id.au/blog/2012/09/01/maintainable-teamcity-continuous-deployment-pipeline-configuration/](http:*robdmoore.id.au/blog/2012/09/01/maintainable-teamcity-continuous-deployment-pipeline-configuration/)
### Parameters: comboboxen/checkboxen
<img style='' src='/img//code/build/tc_deploy_params.png|'>
**Demo omgeving**
Dit ingeven in "spec":
```
select display######'prompt' label'Demo omgeving' data_11######'FixDemo' data_10'FixDev' data_02######'TestDemo1' data_01'Package' data_04######'TestDemo3' data_03'TestDemo2' data_06######'TestDemo5' data_05'TestDemo4' data_08######'TestDemo7' data_07'TestDemo6' data_09='SERVERNAME'
```
**Modules**
Dit ingeven in "spec":
```
select data_7######'Modx' data_5'Mody.DAL' data_6######'Modz' ... multiple'true'
```
Wordt dan comma-separated doorgegeven via `%Modules%` parameter dat je kan gebruiken in build configuration.
### Artifacts bijhouden
Edit build settings > Artifact paths > `**/packaged.zip` om alle files die zo heten als artifact te bewaren. <br/><br/>
Probleem met HDD space kan opgelost worden met [http:*confluence.jetbrains.com/display/TCD8/Clean-Up](http:*confluence.jetbrains.com/display/TCD8/Clean-Up): Clean-up settings are configured under Administration | Project-related Settings | Build History Clean-up.
Gevolg is dat gebuilde zipfiles gedownload kunnen worden op deze manier:
<img style='float: left; width: nolink |px;' src='/img//code/build/builddeploy.png'>

View File

@ -1,20 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"c",
"home"
]
date = "2013-08-05"
+++
# C/C++ >> Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>
#### Nuttige links
* [The 5 minute guide to C Pointers](http://denniskubes.com/2012/08/16/the-5-minute-guide-to-c-pointers/)
* [A tutorial on Pointers and Arrays in C](http://pw1.netcom.com/~tjensen/ptr/pointers.htm)

View File

@ -1,184 +0,0 @@
+++
title = "basics"
draft = false
tags = [
"code",
"c",
"basics"
]
date = "2013-12-02"
+++
# C(++) Basics
## Scope
C++ heeft block level scope, net als Java, alleen is het mogelijk om een variabele binnen een for loop dezelfde naam te geven als een die buiten die block gedefiniëerd is, terwijl dat in Java niet gaat:
```c
int j;
for(int i = 0; i < 10; i++) {
int j = i + 1; // compile fout in java
}
```
### Pointer scope
[auto_ptr](https://en.wikipedia.org/wiki/Auto_ptr) kan gebruikt worden om een pointer automatisch te verwijderen met `delete` wanneer deze scope verliest - alle andere zaken moet je zelf opkuisen.
:exclamation: Dit is deprecated in C++ 11, gebruik [unique_ptr](https://en.wikipedia.org/wiki/Smart_pointer#unique_ptr)
Voorbeeld van wikipedia:
```c
#include <iostream>
#include <memory>
using namespace std;
int main(int argc, char **argv)
{
int *i = new int;
auto_ptr<int> x(i);
auto_ptr<int> y;
y = x;
cout << x.get() << endl; // Print NULL
cout << y.get() << endl; // Print non-NULL address i
return 0;
}
```
## overloading: 'virtual'
In java wordt by default het diepste gedefiniëerde element opgeroepen, in C++ ben je verplicht `virtual` te gebruiken als "optimalisatie" wordt dit standaard niet gedaan... Voorbeeld:
```c
class Simple
{
public:
Simple() : someMember(3) {}
virtual int guessNumber();
int someMember;
};
```
```c
#include "simplecpp.h"
int Simple::guessNumber()
{
return 5;
}
```
Als je nu `guessNumber()` wil overschrijven in een subklasse kan dit:
```c
#include "simplecpp.h"
class Complexer : public Simple
{
public:
Complexer() {}
int guessNumber();
};
```
Merk op, te overschrijven method heropsommen in header file... (??) - hier hoeft geen `virtual` meer bij dan.
```c
#include "complexer.h"
int Complexer::guessNumber()
{
return 10;
}
```
Wat is hier de uitkomst van:
```c
#include "complexer.h"
#include <iostream>
int main()
{
Simple* simple = new Complexer();
std::cout << simple->guessNumber();
delete simple;
}
```
10. Haal `virtual` weg. 5. <br/><br/>
Definiëer `Complexer` zo:
```c
Complexer* complexer = new Complexer();
```
En het is altijd 10.
## Initialisatie
(Voorbeelden van bovenstaande)
```c
#include "complexer.h"
#include <iostream>
int main()
{
Simple simpleInitialized; // oops, I created something?
// Simple simpleInitialized = NULL; cannot convert from 'int' to 'Simple' (#define NULL 0)
Simple* simplePtr;
std::cout << "<br/>n initialiezd: " << simplePtr->someMember;
// Run-Time Check Failure #3 - The variable 'simplePtr' is being used without being initialized
delete simplePtr;
}
```
Wat is hier speciaal aan?
1. In C++ wordt altijd een object aangemaakt als je ze declareert. In Java niet!
2. In C++ is `NULL` gedefiniëerd als `#define NULL 0` - je kan dus niet zomaar iets toekennen hieraan. In C++ 11 heb je `nullptr`
3. Je kan wel een pointer declareren zonder een waarde toe te kennen, en dit geeft dan een run-time fout (zou bvb een `NullPointerException` gooien in java)
## Typecasting
Uitgebreide uitleg: zie http://www.cplusplus.com/doc/tutorial/typecasting/
In C++ is één impliciete conversie mogelijk door middel van de constructor, bijvoorbeeld:
```c
class Something
{
public:
Something(int i) : myVar(i) {}
private:
int myVar;
}
int getal = 10;
Something something = getal; // use constructor
```
Om dit tegen te gaan kan je altijd het `explicit` keyword gebruiken, zodat je dit moet doen:
```c
Something something = Something(getal); // expliciet oproepen constructor
```
Je kan `staic_cast<Type>(var)` gebruiken om explicit constructors aan te roepen, zo kunnen ze dan toch nog gecast worden.
## C++ 11 goodies
Algemeen: [How C++ 11 helps boost your productivity](http://www.informit.com/articles/article.aspx?p=1910142)
1. [Lambdas](http://www.codeproject.com/Articles/277612/Using-lambdas-Cplusplus-vs-Csharp-vs-Cplusplus-CX) zijn mogelijk
2. `nullptr`
3. `auto` keyword, zoals `var` in C# - dit is typesafe en door de compiler zelf bepaald.
4. 100% multithreading support, zie [code/c/threading]({{< relref "wiki/code/c/threading.md" >}})

View File

@ -1,84 +0,0 @@
+++
title = "linking"
draft = false
tags = [
"code",
"c",
"linking"
]
date = "2014-03-26"
+++
# Linking obj/dlls
Probleemstelling: verschillende **solutions**, code over solutions heen willen gebruiken.
Dit compileert by default altijd, maar tijdens het linken van de gecompileerde files loopt het mis. Waarom? Omdat er geen `dllexport` voorzien is.
<br/><br/> Op te lossen:
```c
#ifndef RESOURCE_UTILS_H
#define RESOURCE_UTILS_H
#include "Utility.h"
#ifdef _DLL
#define DllExImport __declspec(dllexport)
#else
#define DllExImport __declspec(dllimport)
#endif
class DllExImport ResourceUtils
{
public:
static RAIIObject<HICON> getIcon(int resourceId);
static RAIIObject<HICON> getIcon(HINSTANCE resourceHandleInstance, int resourceId);
private:
ResourceUtils() {}
};
#endif
```
in de cpp file hoeft niets speciaal meer te staan.
#### Functies exposen voor native calls
Zelfde principe om klassen te exposen met `_ _declspec(dllexport)`. Gebruik eventueel std calls (C# heeft dit nodig): `DllExImport MyStruct* _ _stdcall GetSignals();`.
#### Properties van solutions
##### Die de te exporteren code bevat
1. Configuration type: Dynamic Libraray (DLL)
2. Incremental linking: Yes (/INCREMENTAL)
3. Link Linkage Deps: Yes
4. Output file: *.dll
##### Die de code bevat die gebruik maakt van de dll
1. Linker; Input: Additional dependencies ../OtherSolution.lib
### Shared libraries linken in Unix
`declspec` is Win32 specifiek. Lees alles over GCC Visibility in [GNU GCC Wiki on Visibility](http://gcc.gnu.org/wiki/Visibility). Komt op dit neer:
```c
#if defined(_MSC_VER)
// Microsoft
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
#elif defined(_GCC)
// GCC
#define EXPORT __attribute__((visibility("default")))
#define IMPORT
#else
// do nothing and hope for the best?
#define EXPORT
#define IMPORT
#pragma warning Unknown dynamic link import/export semantics.
#endif
```
Zie ook [How to write shared Libraries](http://www.akkadia.org/drepper/dsohowto.pdf) by Ulrich Drepper.

View File

@ -1,98 +0,0 @@
+++
title = "mfc"
draft = false
tags = [
"code",
"c",
"mfc"
]
date = "2013-12-12"
+++
# MFC
:exclamation: MFC en AFX [is hetzelfde](http://en.wikipedia.org/wiki/Microsoft_Foundation_Class_Library):
> One interesting quirk of MFC is the use of "Afx" as the prefix for many functions, macros and the standard precompiled header name "stdafx.h". During early development what became MFC was called "Application Framework Extensions" and abbreviated "Afx". The name Microsoft Foundation Classes (MFC) was adopted too late in the release cycle to change these references
### Strings in MFC
Gebruik `CString` - werkt niet op non-win32 omgevingen.
##### Formatting
Formatten kan bijvoorbeeld met `string.Format(_T("%s in %d"), otherString, otherDecimal);`
:exclamation: Om een string te intialiseren en toe te kennen moet je wel de `_T` macro gebruiken
##### Substringen
`Find` is hetzelfde als `indexOf` in andere talen.
```c++
CString HostServiceProxy::GetCouponFromResponseString(CString response)
{
CString couponKey ###### _T("Coupon");
CString couponPart = response.Mid(response.Find(couponKey) + couponKey.GetLength());
return couponPart.Left(couponPart.Find(_T(";")));
}
```
### Resource handling
Icons en images worden opgeslagen in .rc files die als resources in de code gekoppeld kunnen worden aan bijvoorbeeld een `CButton`. Hoe?
```c
HANDLE hImage = ::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(resourceId), IMAGE_ICON, 16, 15, LR_DEFAULTCOLOR);
if(hImage ###### NULL)
ASSERT(FALSE);
HICON image = static_cast<HICON>(hImage);
```
`HICON` is van `WinDef.h` en `::LoadImage` zit op `WinUser.h`. Zie [MSDN doc](http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx) voor LoadImage.
######= De juiste resource handle vastkrijgen ######=
Als je een MFC DLL maakt, gaat `AfxGetResourceHandle()` verwijzen naar de resource handle van uw DLL zelf. Als je dus resources wil vastpakken van een andere DLL heb je pech. Als je geen MFC DLL maakt kan je dit aanpassen met ` AFX_MANAGE_STATE(AfxGetStaticModuleState( ))`. **Dit gooit echter linking errors** ( error LNK2005: _DllMain@12 already defined) indien je dit vanuit een MFC DLL aanroept - dan is dit niet nodig.
Meer uitleg hierover: zie http://support.microsoft.com/kb/161589
:exclamation: de Afx resource handle kan **altijd** gewijzigd worden door leuke dingen te doen als:
```c
HINSTANCE old = AfxGetResourceHandle();
AfxSetResourceHandle(GetModuleHandle("andereModule"));
```
Gebruik daarom best `::GetModuleHandle(char*)` bij `::LoadImage`.
######= Resources op het juiste moment terug vrijgeven ######=
Resources worden meestal gewrapped in kleine objectjes die bij de constructor de resource alloceren en bij de destructor deze terug vrijgeven in plaats van in `try { ... }` zoiets te moeten doen in Java. Dit pattern is [RAII](http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization) of "Resource Acquisition Is Initialization". Voorbeeld:
```c
template<class TObject>
class RAIIObject
{
public:
explicit RAIIObject(const TObject& obj) : m_Object(obj) {}
RAIIObject() {}
~RAIIObject() {ReleaseObject();}
RAIIObject<TObject>& operator######(const TObject& obj) {if(&obj ! &m_Object) {ReleaseObject(); m_Object = obj;} return *this;}
RAIIObject<TObject>& operator######(const RAIIObject<TObject>& obj) {if(&obj ! this) {ReleaseObject(); m_Object = obj;} return *this;}
TObject& GetObject() {return m_Object;}
const TObject& GetObject() const {return m_Object;}
operator TObject&() {return m_Object;}
operator const TObject&() const {return m_Object;}
private:
void ReleaseObject();
TObject m_Object;
};
template<> inline void RAIIObject<HICON>::ReleaseObject() {::DestroyIcon(m_Object); m_Object = NULL;}
template<> inline void RAIIObject<CBrush>::ReleaseObject() {m_Object.DeleteObject();}
template<> inline void RAIIObject<CBitmap>::ReleaseObject() {m_Object.DeleteObject();}
template<> inline void RAIIObject<CFont>::ReleaseObject() {m_Object.DeleteObject();}
template<> inline void RAIIObject<CMenu>::ReleaseObject() {m_Object.DestroyMenu();}
```

View File

@ -1,27 +0,0 @@
+++
title = "preprocessing"
draft = false
tags = [
"code",
"c",
"preprocessing"
]
date = "2013-12-02"
+++
# Preprocessing
## Handige macro's
##### Exception/Debug informatie expanden
```c++
#define _ERROR_STR2(a) #a
#define _ERROR_STR(a) _ERROR_STR2(a)
#define ERROR_INFO(fn) _T(_ERROR_STR(__FILE__" line: "__LINE__" function: "fn))
```
Te gebruiken als `someFn(ERROR_INFO("bla"))`. Merk op dat `__FUNCTION__` of `__FUNC__` ook gebruikt kan worden, afhankelijk van de C++ compiler, maar dit is geen deel van de standaard (vanaf C++ v11).
De `#a` notatie wordt gebruikt om iets te [stringifyen](http://gcc.gnu.org/onlinedocs/cpp/Stringification.html) in de preprocessor, vandaar de delegate:
> Sometimes you may want to convert a macro argument into a string constant. Parameters are not replaced inside string constants, but you can use the # preprocessing operator instead. When a macro parameter is used with a leading #, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is not macro-expanded first. This is called stringification.

View File

@ -1,16 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"c",
"testing",
"home"
]
date = "2013-07-17"
+++
# code:c:testing >> Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>

View File

@ -1,103 +0,0 @@
+++
title = "gtest"
draft = false
tags = [
"code",
"c",
"testing",
"gtest"
]
date = "2014-03-26"
+++
# Google Test
Downloaden op https://code.google.com/p/googletest/downloads/list
**Waarom**?
1. Platform onafhankelijk
2. Snelheid
3. Geen gezeik met Managed C++, compatibel met "eender wat" (enige vereiste: `cc` compiler variant)
4. Wordt veel gebruikt (Chromium, Stack overflow)
**Waarom niet**?
1. slechte of geen integratie met VStudio (zie onder)
2. wéér een andere syntax dan MS .NET testen
3. beetje awkward assertions
#### Assertions schrijven
```c
#include "../BaseCode/BaseCode.h"
#include "gtest/gtest.h"
TEST(MyTestCase, MyTest_Success)
{
EXPECT_EQ(2, MySum(1, 1));
}
TEST(MyTestCase, MyTest_Failure)
{
EXPECT_EQ(3, MySum(1, 2));
}
```
Waarbij dan `BaseCode` uw system under test zaken bevat (waar `MySum` defined is)
#### Builden met scons en g++
Tested in Cygwin Win7 & OSX 10.9
```python
Import('env')
env ###### env.Clone(CPPPATH './:./include')
env.Append(CXXFLAGS = ['-g', '-Wall', '-Wextra', '-pthread'])
gtest ###### env.Library(target 'gtest', source = ['src/gtest-all.cc', 'src/gtest_main.cc'])
Return('gtest')
```
Zie [code/build/scons]({{< relref "wiki/code/build/scons.md" >}})
#### Builden met Visual Studio
<img style='float: left;' src='/img//code/c/testing/screenshot.png|'>
Zie http://leefrancis.org/2010/11/17/google-test-gtest-setup-with-microsoft-visual-studio-2008-c/
Er zijn 2 `.sln` files voorzien in de msvc subdir bij de zipfile, één voor statische links en één voor dynamische. Afhankelijk van uw project (.DLL of .LIB gegenereerde uitkomst), ga je één van beiden moeten compileren. Als je van plan bent om `/MDd` te gebruiken (dll + debugging), gebruik dan `gtest-md.sln`.
Daarna kan je een nieuwe solution maken, package naar executable om de test zelf te runnen (om gtest testen te draaien). Verander deze dingen in het project:
1. General > Configuration type = Application (.EXE)
2. C/C++ > General > Additional Include dirs naar gtest/include verwijzen
3. C/C++ > Preprocessor > definitions toevoegen `_VARIADIC_MAX=10`
4. Code generation > Runtime library op `/MDd` of `/MTd` juist zetten (zie boven)
5. Linker > Additional Library directories > gtest/Debug (staan reeds binaries indien compiled)
6. Linker > Input > Additional dependencies = gtestd.lib;gtest_maind.lib;(rest)
7. Linker > System > SubSystem Console `/SYBSYSTEM:CONSOLE`
8. Linker > Input > Module Definition file leeg (indien van DLL naar EXE veranderd kan hier wat brol in zitten)
#### Visual Studio 2012 en STD problemen
Fouten als
```
1>a:<br/>gtest<br/>include<br/>gtest<br/>gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments
1> b:<br/>program files (x86)<br/>microsoft visual studio 2012<br/>vc<br/>include<br/>utility(73) : see declaration of 'std::tuple'
```
Op te lossen met een preprocessor macro _VARIADIC_MAX=10, zie http://stackoverflow.com/questions/12558327/google-test-in-visual-studio-2012
##### Integratie met Visual Studio 2008/2010
[GoogleTestAddin](http://googletestaddin.codeplex.com/documentation) (kopieer 2 files naar C:<br/>Users<br/>bkwog<br/>Documents<br/>Visual Studio 2008<br/>Addins, map misschien nog aanmaken)
Niet super nuttig, een knopje om testen snel te herdraaien (of één die geselecteerd is), beter dan post-build actie zie boven...
#### Integratie met Visual Studio 2012
[Google Test Adapter](http://visualstudiogallery.msdn.microsoft.com/f00c0f72-ac71-4c80-bf8b-6fe381548031) plugin (1.1 - geen actieve development?)

View File

@ -1,135 +0,0 @@
+++
title = "teamtest"
draft = false
tags = [
"code",
"c",
"testing",
"teamtest"
]
date = "2013-07-17"
+++
# Visual Studio 2005 TeamTest Framework
Hoofdartikel (2005, C# voorbeelden): http://msdn.microsoft.com/en-us/library/ms379625(v=vs.80).aspx
**Waarom**?
1. Zelfde syntax als built-in C# unit tests voor Visual Studio
2. Makkelijker te lezen dan bvb [code/c/testing/gtest]({{< relref "wiki/code/c/testing/gtest.md" >}})
3. Garbage collector van Managed C++, joepie (?)
4. Toch mogelijk om unmanaged native C++ te testen (zie onder), integratie VStudio.
**Waarom niet**?
1. Dropped support voor VS2012? zie [code/c/testing/testexplorer]({{< relref "wiki/code/c/testing/testexplorer.md" >}}) in de plaats (native C++)
2. `/cli` flag miserie (zie onder)
3. Onduidelijke syntax voor hardcore C++ users die niet aan C# gewend zijn
## Visual Studio 2008
Hiervoor moeten we een apart test project aanmaken dat met **/CLR** flag compileert om de .NET test suites te gebruiken (`using namespace Microsoft::VisualStudio::TestTools::UnitTesting;`):
Project > configuration properties > General > Common Language Runtime support
<img style='float: left;' src='/img//code/c/testing/clr_unittests.png |'>
Dit staat op `/clr:safe` indien je met VStudio 2008 een nieuwe test aan maakt via menu Test > New Test > Unit Test
Een voorbeeld header file om te testen:
```c
class MyClass {
public:
MyClass() {};
int addUp(int one, int two);
};
```
```c
#include "myclass.h"
#include <iostream>
using namespace std;
int MyClass::addUp(int one, int two)
{
return one + two;
}
```
#### Managed test code schrijven
Gebruik dezelfde manier als .NET Unit Testing framework met attributes - dit vereist dus de CLR flag. Voorbeeld:
```c
#include "stdafx.h"
#include "../libtest/myclass.h"
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace unittests
{
[TestClass]
public ref class MyClassTest
{
public:
[TestMethod]
void AddOne()
{
Assert::AreEqual(3, MyClass().addUp(1, 2));
};
};
}
```
**Assert** heeft een hoop static methods
#### een externe klasse testen die van een lib komt
Als je vanuit je test project wil refereren naar productie code/projecten, kan dit een probleem zijn:
```
MyClassTest.obj : error LNK2028: unresolved token (0A00000A) "public: __thiscall MyClass::MyClass(void)" (??0MyClass@@$$FQAE@XZ) referenced in function "public: void __clrcall unittests::MyClassTest::AddOne(void)" (?AddOne@MyClassTest@unittests@@$$FQ$AAMXXZ)
MyClassTest.obj : error LNK2028: unresolved token (0A00000B) "public: int __thiscall MyClass::addUp(int,int)" (?addUp@MyClass@@$$FQAEHHH@Z) referenced in function "public: void __clrcall unittests::MyClassTest::AddOne(void)" (?AddOne@MyClassTest@unittests@@$$FQ$AAMXXZ)
MyClassTest.obj : error LNK2019: unresolved external symbol "public: int __thiscall MyClass::addUp(int,int)" (?addUp@MyClass@@$$FQAEHHH@Z) referenced in function "public: void __clrcall unittests::MyClassTest::AddOne(void)" (?AddOne@MyClassTest@unittests@@$$FQ$AAMXXZ)
```
Dat wil zeggen, het compileert, maat het linkt niet. Oplossing: Voeg dit toe aan uw `stdafx.cpp`:
```c
#pragma comment(lib, "../Debug/libtest.lib")
```
gegeven dat "libtest" uw project under test is. Vanaf dan kan je normaal header files includen in uw test cpp file, zie boven.
#### een externe klasse testen die van een DLL komt
Er wordt pas een `.lib` file gegenereerd wanneer je `declspec(dllexport)` definiëert - wanneer niets exported is, kan er ook niets imported worden... Dus `myClass` aanpassen:
```c
#ifdef FRIENDCLASS_EXPORT
#define FRIENDCLASS __declspec(dllexport)
#else
#define FRIENDCLASS __declspec(dllimport)
#endif
class FRIENDCLASS MyClass {
public:
MyClass();
int addUp(int one, int two);
};
```
En dan het libtest project compileren met de extra preprocessor definitie `FRIENDCLASS_EXPORT` zodat in commandline `/D "FRIENDCLASS_EXPORT"` erbij komt. Zie ook [MSDN Preprocessor definitions](http://msdn.microsoft.com/en-us/library/hhzbb5c8(v=vs.80).aspx), nu kunnen we hierop checken in de code met `#ifdef`. Bovenstaande code doet een export wanneer gedefiniëerd, en een import anders - dit gebeurt wanneer we de header file includen vanuit onze test cpp file.
#### Debugging
:exclamation: [Debug information format flags](http://msdn.microsoft.com/en-us/library/958x11bc(v=vs.80).aspx): `/ZI` ("Edit and Continue feature", retry drukken bij assertion failure) is **niet** ondersteund in combinatie met `/cli`. Debuggen gaat wel op `/Zi` niveau.

View File

@ -1,107 +0,0 @@
+++
title = "testexplorer"
draft = false
tags = [
"code",
"c",
"testing",
"testexplorer"
]
date = "2013-09-05"
+++
# Visual Studio 2012 Test Explorer framework
**Waarom**?
1. Integratie VStudio, zelfde manier om te "runnen" als C# testen
2. __unmanaged__ (native) C++ code testen zonder vettige `/cli` mode die nodig is.
3. Voor mixed team C#/C++ misschien beter/makkelijker?
**Waarom niet**?
1. Weeral iets anders, Team Test buiten? Wat gaat het zijn voor VS3013?
2. Niet 100% dezelfde syntax als C# (toch al closer, maar bvb geen attributes etc)
3. VS2012 only momentel, dus 2008 = kinkloppen
Voorbeeld project in VS2012: <img style='' src='/img//code/c/testing/math_testexplorer_vs2012.zip|'>
#### Assertions schrijven
Gebruik namespace `CppUnitTestFramework` - voorbeeld:
```c
#pragma once
#include "stdafx.h"
#include "CppUnitTest.h"
#include "PlusStub.cpp"
#include "../Math/Plus.h"
#include "../Math/Calculator.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace calc
{
TEST_CLASS(CalculatorTest)
{
private:
int nStartValue;
Calculator* calc;
void CreateCalcSUT()
{
calc = new Calculator(nStartValue);
}
public:
/*testcase template:
TEST_METHOD(Classname_Functionname_SpecialParams_ExpectedResult)
{
param specialParam = specialvalue;
...
param expectation = whatYouExpect;
...
(SUT creation)
(call methods)
...
assert(s)
}*/
TEST_METHOD_INITIALIZE(InitialiseDefaults)
{
calc = NULL;
nStartValue = 5;
}
TEST_METHOD_CLEANUP(CleanupObjects)
{
delete calc;
}
TEST_METHOD(Calculator_Constructor_NoArgument_GetValueZero)
{
int nExpectedValue = 0;
calc = new Calculator();
Assert::AreEqual(nExpectedValue, calc->GetValue());
}
TEST_METHOD(Calculator_Constructor_Five_GetValueFive)
{
nStartValue = 5;
int nExpectedValue = 5;
CreateCalcSUT();
Assert::AreEqual(nExpectedValue, calc->GetValue());
}
};
}
```
<img style='' src='/img//code/c/testing/cppunittesting.png|'>
Zelfde manier om assertions te schrijven.
:exclamation: dit test project heeft GEEN `/clr` flag, dus is ook __unmanaged__, dat is het voordeel.
Zoals gezien op screencap is dit volledig geïntegreerd met VStudio 2012.
[Meer informatie over het nieuwe cpp testing framework 'Test Explorer'](http://msdn.microsoft.com/en-us/library/hh270864.aspx)

View File

@ -1,121 +0,0 @@
+++
title = "threading"
draft = false
tags = [
"code",
"c",
"threading"
]
date = "2013-12-02"
+++
# Threading
Handige links:
1. [Thread synchronization for beginners](http://www.codeproject.com/Articles/7953/Thread-Synchronization-for-Beginners)
## Thread-safe Singleton pattern
Bijna onmogelijk in C++ < v11 blijkbaar?
Onderstaand voorbeeld gebruikt Win32 code (`WaitForSingleObject`) en een mutex om te wachten:
```c++
#pragma once
#include <WinBase.h>
class AddinProcessService
{
static AddinProcessService *singletonInstance;
AddinProcessService() : m_coupon(_T("")), m_hostServiceAddress(_T("")) {}
public:
inline const CString& GetHostServiceAddress() const
{
return m_hostServiceAddress;
}
inline const CString& GetCoupon() const
{
return m_coupon;
}
inline void SetCoupon(CString coupon)
{
m_coupon = coupon;
}
inline void SetHostServiceAddress(CString address)
{
m_hostServiceAddress = address;
}
static AddinProcessService* getSingletonInstance()
{
static volatile int initialized = 0;
static HANDLE mtx;
if (!initialized)
{
if (!mtx)
{
HANDLE mymtx;
mymtx = CreateMutex(NULL, 0, NULL);
if (InterlockedCompareExchangePointer(&mtx, mymtx, NULL) != NULL)
CloseHandle(mymtx);
}
WaitForSingleObject(mtx, 0);
if (!initialized)
{
libInitInternal();
initialized = 1;
}
ReleaseMutex(mtx);
}
return singletonInstance;
};
private:
CString m_hostServiceAddress;
CString m_coupon;
static void libInitInternal()
{
singletonInstance = new AddinProcessService();
}
};
```
:exclamation: Vergeet niet in de cpp file uw singletonInstance pointer te declareren, anders krijg je linker errors: `AddinProcessService* AddinProcessService::singletonInstance;`
In UNIX kan men [pthreads](https://computing.llnl.gov/tutorials/pthreads/) gebruiken, ongeveer op deze manier:
```c++
static Foo &getInst()
{
static Foo *inst = NULL;
if(inst ###### NULL)
{
pthread_mutex_lock(&mutex);
if(inst ###### NULL)
inst = new Foo(...);
pthread_mutex_unlock(&mutex);
}
return *inst;
}
```
Dan kan je `#ifdef WIN32` gebruiken om te switchen tussen beide implementaties.
############ C++ 11 multithreading ############
Vanaf C++ 11 zijn multithreads 100% native supported, dit wil zeggen dat manueel locken met een `mutex` overbodig wordt. Bovenstaande singleton kan gereduceerd worden tot (merk het **static** keyword op, dat is het belangrijkste voor de autolock):
```c++
static Singleton& get(){
static Singleton instance;
return instance;
}
```
Voor meer info, zie http://stackoverflow.com/questions/11711920/how-to-implement-multithread-safe-singleton-in-c11-without-using-mutex

View File

@ -1,50 +0,0 @@
+++
title = "win32specifics"
draft = false
tags = [
"code",
"c",
"win32specifics"
]
date = "2013-12-12"
+++
# code:c >> Win32 API specifics
#### Get Loaded DLL info from given process
huidig proces: `GetCurrentProcessId()` - dit is een `HANDLE`.
```c++
CString ExceptionHandler::GetLoadedDllInfo() const
{
CString dlls = _T("");
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId());
if(process ###### NULL)
{
return dlls;
}
HMODULE hMods[1024];
DWORD cbNeeded;
BOOL modules = EnumProcessModules(process, hMods, sizeof(hMods), &cbNeeded);
if(!modules)
{
return dlls;
}
for (int i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
{
TCHAR szModName[MAX_PATH];
if (GetModuleFileNameEx(process, hMods[i], szModName, sizeof(szModName) / sizeof(TCHAR)))
{
dlls.Format(_T("%s, %s"), dlls, szModName);
}
}
CloseHandle(process);
return dlls;
}
```
Hiervoor moet je `#include <psapi.h>` includen én de psapi.lib file mee linken! Zie [EnumProcessModules MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682631(v=vs.85).aspx).

View File

@ -1,15 +0,0 @@
+++
title = "ceylon"
draft = false
tags = [
"code",
"ceylon"
]
date = "2013-11-13"
+++
# Ceylon
#### Interessant leesmateriaal
1. [Why is there no protected visibility modifier in Ceylon?](http://ceylon-lang.org/documentation/1.0/faq/language-design/#no_protected_modifier)
2. [Ceylon 1.0 Tour](http://ceylon-lang.org/documentation/1.0/tour/) die vergelijkingen met Java en C# legt op gebied van functies, variabelen, klassen, lambda's, ...

View File

@ -1,14 +0,0 @@
+++
title = "csharp"
draft = false
tags = [
"code",
"csharp"
]
date = "2013-12-03"
+++
# code >> Csharp
## Inhoudsopgave
<img style='' src='/img/indexmenu>code/csharp|js navbar nocookie'>

View File

@ -1,15 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"csharp",
"home"
]
date = "2013-07-19"
+++
# C# Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>

View File

@ -1,80 +0,0 @@
+++
title = "aspdotnet"
draft = false
tags = [
"code",
"csharp",
"aspdotnet"
]
date = "2014-06-30"
+++
# ASP.NET
### Troubleshooting
#### 'WebForm_DoPostBackWithOptions' is undefined in IE1
Probleem: [How to get your ASP.NET application working in IE11](http://blogs.telerik.com/aspnet-ajax/posts/13-12-19/how-to-get-your-asp.net-application-working-in-ie11)
Fix: [App_Browsers](http://www.shubho.net/2011/01/what-is-appbrowsers-folder-in-aspnet.html) folder aanmaken in uw webapp en een `.browser` file toevoegen:
```xml
<browsers>
<browser id######"IE11" parentID"Mozilla">
<identification>
<userAgent match="Trident/(?'layoutVersion'[7-9]|0*[1-9]<br/>d+)(<br/>.<br/>d+)?;(.*;)?<br/>s*rv:(?'version'(?'major'<br/>d+)(<br/>.(?'minor'<br/>d+)))" />
<userAgent nonMatch="IEMobile" />
</identification>
<capture>
<userAgent match="Trident/(?'layoutVersion'<br/>d+)" />
</capture>
<capabilities>
<capability name######"browser" value"IE" />
<capability name######"layoutEngine" value"Trident" />
<capability name######"layoutEngineVersion" value"${layoutVersion}" />
<capability name######"extra" value"${extra}" />
<capability name######"isColor" value"true" />
<capability name######"letters" value"${letters}" />
<capability name######"majorversion" value"${major}" />
<capability name######"minorversion" value"${minor}" />
<capability name######"screenBitDepth" value"8" />
<capability name######"type" value"IE${major}" />
<capability name######"version" value"${version}" />
</capabilities>
</browser>
<!-- Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11,0) like Gecko -->
<browser id######"IE110" parentID"IE11">
<identification>
<capability name######"majorversion" match"11" />
</identification>
<capabilities>
<capability name######"ecmascriptversion" value"3.0" />
<capability name######"jscriptversion" value"5.6" />
<capability name######"javascript" value"true" />
<capability name######"javascriptversion" value"1.5" />
<capability name######"msdomversion" value"${majorversion}.${minorversion}" />
<capability name######"w3cdomversion" value"1.0" />
<capability name######"ExchangeOmaSupported" value"true" />
<capability name######"activexcontrols" value"true" />
<capability name######"backgroundsounds" value"true" />
<capability name######"cookies" value"true" />
<capability name######"frames" value"true" />
<capability name######"javaapplets" value"true" />
<capability name######"supportsCallback" value"true" />
<capability name######"supportsFileUpload" value"true" />
<capability name######"supportsMultilineTextBoxDisplay" value"true" />
<capability name######"supportsMaintainScrollPositionOnPostback" value"true" />
<capability name######"supportsVCard" value"true" />
<capability name######"supportsXmlHttp" value"true" />
<capability name######"tables" value"true" />
<capability name######"supportsAccessKeyAttribute" value"true" />
<capability name######"tagwriter" value"System.Web.UI.HtmlTextWriter" />
<capability name######"vbscript" value"true" />
</capabilities>
</browser>
</browsers>
```
**ofwel** .NET 4.5 op server installeren (ook al gebruik je 4.0!)

View File

@ -1,235 +0,0 @@
+++
title = "classes"
draft = false
tags = [
"code",
"csharp",
"classes"
]
date = "2014-01-29"
+++
# Classes
## Dynamically creating instances
Gebruik `Activator`:
```csharp
Activator.CreateInstance(type) as MyType
```
## Overrides en shadowing: 'new' en 'virtual'
Zie onder andere:
1. http://stackoverflow.com/questions/1014295/new-keyword-in-method-signature
2. http://stackoverflow.com/questions/9892468/java-is-there-java-equivalent-for-c-sharp-new-keyword-in-method-signature-how
In java zijn alle methods `virtual`, dat wil zeggen dat ze overschrijfbaar zijn (`@Override`) zodat de method in de diepst geneste polymorfe structuur gebruikt wordt. In C# is daarvoor het keyword `virtual` nodig:
```csharp
public class A
{
public virtual void One();
public void Two();
}
public class B : A
{
public override void One();
public new void Two();
}
B b = new B();
A a = b as A;
a.One(); // Calls implementation in B
a.Two(); // Calls implementation in A
b.One(); // Calls implementation in B
b.Two(); // Calls implementation in B
```
De concretere klasse moet dan overriden met `override` dat niet gaat als het niet `virtual` is (je kan ook niet overerven waarbij een klasse `sealed` is, zoals `final` in java). Wat hier wel opmerkelijk is, is het gebruik van het keyword `new` in de tweede method "Two". Hierbij kan je de eerste implementatie toch nog hiden, maar je moet wel upcasten! Misschien is dit nog handig bij het schrijven van legacy testen?
Het is in java niet mogelijk om een `final` method te overriden. (Private telt natuurlijk niet mee...) In C# is het [wel mogelijk om halverwege de chain te sealen](http://msdn.microsoft.com/en-us/library/aa645769(v=vs.71).aspx)!
## Closures en Lambda's
Interessante links:
1. [Lambda expressions MSDN C# programming guide](http://msdn.microsoft.com/en-us/library/bb397687.aspx)
2. [Expression Trees MSDN](http://msdn.microsoft.com/en-us/library/bb397951.aspx) hier worden lambda's gebruikt voor LINQ
### Passing on 'work' to a method, to execute the lambda
In Java:
```java
public interface Workable<T> {
public T work();
}
public class MyWork extends Workable<MyObj> {
public MyObj work() {
// do stuff here
}
}
public class Executer {
public <T> T doStuff(Workable<T> w) {
prepare();
T result = w.work();
cleanup();
}
public MyObj createMyObj() {
return doStuff(new MyWork());
}
}
```
Basically, gebruik interfaces. Pijnlijk en verbose. In C# kan je `() =>` gebruiken om een anonieme method aan te maken, en `Func<>` als type gebruiken. <br/><br/>
Concreet voorbeeld:
```csharp
internal virtual T Execute<T>(Func<T> work)
{
Connection.Open();
var transaction = Connection.BeginTransaction();
try
{
var retVal = work.Invoke();
transaction.Commit();
return retVal;
}
catch (Exception)
{
transaction.Rollback();
throw;
}
finally
{
Connection.Close();
}
}
public bool BlaBla()
{
return Execute(() =>
{
// do query stuff in here.
return true;
});
}
```
##### Q: Wat is het verschil tussen een Lambda (>()) en een delegate? ######
A: niets; zie voorbeeld:
```csharp
Func<string, int> giveLength = delegate(string text) { return text.Length; };
Func<string, int> giveLength ###### (text > text.length);
```
de `=>` notatie is nieuwer.
###### Q: Wat is het verschil tussen een expression type en een anonymous type? ######
http://stackoverflow.com/questions/299703/delegate-keyword-vs-lambda-notation
> If you assign the lambda to a delegate type (such as Func or Action) you'll get an anonymous delegate.
If you assign the lambda to an Expression type, you'll get an expression tree instead of a anonymous delegate. The expression tree can then be compiled to an anonymous delegate.
Edit: Here's some links for Expressions.
Zeer interessant artikel: http://weblogs.asp.net/scottgu/archive/2007/04/08/new-orcas-language-feature-lambda-expressions.aspx
############ Nested (inner) classes in C# ############
http://blogs.msdn.com/b/oldnewthing/archive/2006/08/01/685248.aspx - C# heeft geen referentie naar de outer class (`$0` die in Java er impliciet is), bijgevolg moet je dit zelf bijhouden.
Zie ook http://stackoverflow.com/questions/4770180/anonymous-inner-classes-in-c-sharp
############ Modules as anonymous inner classes, JavaScript pattern ############
```javascript
var Mod = (function(consoleDep) {
function yo() {
consoleDep.log("yo");
}
return {
hi: yo
};
})(console);
Mod.hi();
```
equals
```csharp
private interface ILoggable
{
void Log(string msg);
}
private class Console : ILoggable
{
public void Log(string msg)
{
Debug.WriteLine(msg);
}
}
[TestMethod]
public void TestMe()
{
var Mod ###### new Func<ILoggable, Dictionary<string, Action>>((consoleDep) >
{
Action yo ###### () > consoleDep.Log("yo");
return new Dictionary<string, Action>
{
{ "hi", yo }
};
})(new Console());
Mod["hi"]();
}
```
Problemen
* cannot assign lambda expression to an implicitly-typed local variable (`var` bij de yo ipv `Action`)
* duck typing for module dependencies??
############= Enums in C# ############=
Zie ook http://stackoverflow.com/questions/469287/c-sharp-vs-java-enum-for-those-new-to-c
> Enumerations in the CLR are simply named constants. The underlying type must be integral. In Java an enumeration is more like a named instance of a type. That type can be quite complex and - as your example shows - contain multiple fields of various types.
Optie 1: gebruik **extensions** (nog altijd een switch nodig omdat het type in algemene vorm binnen komt)
Optie 2: maak uw eigen enum klasse door immutable readonly classes te maken:
```c#
class Planet
{
public static readonly Planet EARTH = new Planet("earth");
private string name;
private Planet(string name)
{
this.name = name;
}
public static IEnumerable<Planet> Values
{
// return set of planets
}
}
```

View File

@ -1,142 +0,0 @@
+++
title = "dynamica"
draft = false
tags = [
"code",
"csharp",
"dynamica"
]
date = "2014-11-05"
+++
# Dynamica
Zie ook [code/csharp/reflectie]({{< relref "wiki/code/csharp/reflectie.md" >}})
### Expression trees opbouwen
##### Van een MethodInfo instantie naar een Func<>
```csharp
var instanceToMemoize = Activator.CreateInstance<TClassToMemoize>();
foreach (var method in instanceToMemoize.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
{
var parameters ###### method.GetParameters().Select(p > Expression.Constant("test"));
var expr = Expression.Lambda(Expression.Call(Expression.Constant(instanceToMemoize), method, parameters)).Compile();
_Delegates.Add(method.ToString(), expr);
}
```
Argumenten stuk klopt nog niet. Refs:
1. http://stackoverflow.com/questions/2933221/can-you-get-a-funct-or-similar-from-a-methodinfo-object
2. http://stackoverflow.com/questions/11367830/how-to-find-full-name-of-calling-method-c-sharp
##### Memoization
Ook mogelijk via `Func<>` wrappers; zie
1. http://www.jaylee.org/post/2013/04/18/Memoization-and-Immutable-data-in-CSharp-Part-1.aspx
2. http://www.jaylee.org/post/2013/04/22/Immutable-Data-and-Memoization-in-CSharp-Part-2.aspx
Dit is een extension die 2 type arguments aanvaard:
```csharp
public static Func<TArg1, TArg2, TResult> AsMemoized<TArg1, TArg2, TResult>(this Func<TArg1, TArg2, TResult> func)
{
var values = new Dictionary<MemoizedKey<TArg1, TArg2>, TResult>();
return (arg1, arg2) => MemoizedValue(func, arg1, arg2, values);
}
public static Func<TArg, TResult> AsMemoized<TArg, TResult>(this Func<TArg, TResult> funcArg)
{
Func<TArg, object, TResult> func ###### (arg1, arg2) > funcArg(arg1);
var values = new Dictionary<MemoizedKey<TArg, object>, TResult>();
return (arg) => MemoizedValue(func, arg, null, values);
}
private static TResult MemoizedValue<TArg1, TArg2, TResult>(Func<TArg1, TArg2, TResult> func, TArg1 arg1, TArg2 arg2, Dictionary<MemoizedKey<TArg1, TArg2>, TResult> values)
{
TResult value;
var memoizedKey = new MemoizedKey<TArg1, TArg2>(arg1, arg2);
if (!values.TryGetValue(memoizedKey, out value))
{
value ###### values[memoizedKey] func(memoizedKey.Arg1, memoizedKey.Arg2);
}
return value;
}
private class MemoizedKey<TArg1, TArg2>
{
public MemoizedKey(TArg1 arg1, TArg2 arg2)
{
Arg1 = arg1;
Arg2 = arg2;
}
public TArg1 Arg1 { get; private set; }
public TArg2 Arg2 { get; private set; }
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((MemoizedKey<TArg1, TArg2>)obj);
}
public override int GetHashCode()
{
unchecked
{
return (EqualityComparer<TArg1>.Default.GetHashCode(Arg1) * 397) ^ EqualityComparer<TArg2>.Default.GetHashCode(Arg2);
}
}
private bool Equals(MemoizedKey<TArg1, TArg2> other)
{
return EqualityComparer<TArg1>.Default.Equals(Arg1, other.Arg1) && EqualityComparer<TArg2>.Default.Equals(Arg2, other.Arg2);
}
}
```
Equals is nodig voor de `Dictionary` (generated).
### Aspect Oriented Programming
**PostSharp**: [http:*www.postsharp.net](http:*www.postsharp.net)
#### Transacties wiren
Zie [code/csharp/persistence]({{< relref "wiki/code/csharp/persistence.md" >}})
#### Aspects applyen op assembly level
Q: Ik wil AOP toepassen voor alle klassen (& [publieke] methods) in een bepaald project (DLL)<br/><br/>
A: Gebruik [Multicasting aspects](http://www.postsharp.net/aspects/multicasting).
Bijvoorbeeld, om exceptions overal op te vangen, en dan door te delegeren, evt screenshot van de app te nemen:
```csharp
[assembly: ScenarioTests.ScenarioExceptionHandler]
namespace ScenarioTests
{
[Serializable]
[ScenarioExceptionHandler(AttributeExclude = true)]
public class ScenarioExceptionHandler : OnMethodBoundaryAspect
{
public override void OnException(MethodExecutionArgs args)
{
WebDriverExceptionHandler.Handle(args.Exception);
base.OnException(args);
}
}
}
```
De eerste regel, `[assembly:]` is van belang, zie documentatie. Je kan ook verder filteren by visibility etc, zoals in [Spring AOP/AspectJ]({{< relref "wiki/code/java/dynamica/aspectj.md" >}}) de strings in XML gedfiniëerd zijn.

View File

@ -1,77 +0,0 @@
+++
title = "linq"
draft = false
tags = [
"code",
"csharp",
"linq"
]
date = "2014-01-29"
+++
# Collections, Iterating, ???, Linq (profit)
## yield hocus pocus
Zie [The implementation of iterators in C#](http://blogs.msdn.com/b/oldnewthing/archive/2008/08/12/8849519.aspx) - wordt uitgelegd hoe `yield` door de compiler geïnterpreteerd wordt.
Hiermee is het mogelijk om heel snel uw eigen `IEnumerable` te maken.
> “yield”, [...] which allows you to quickly write iterators without worrying about preserving state.
## Folding, selecting, etc
### Closing over the loop variable
Main article: http://blogs.msdn.com/b/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx
Opgelet met `foreach` en de manier waarop die geïmplementeerd is (onder C# 5):
```csharp
{
IEnumerator<int> e = ((IEnumerable<int>)values).GetEnumerator();
try
{
int m; // OUTSIDE THE ACTUAL LOOP
while(e.MoveNext())
{
m = (int)(int)e.Current;
funcs.Add(()=>m);
}
}
finally
{
if (e != null) ((IDisposable)e).Dispose();
}
}
```
de variabele `m` verandert constant. Wanneer we in een loop dan een `delegate` gebruiken die de variabele uitleest, krijgen we op moment van executie slechts de laatste waarde!
```csharp
var values = new List<int>() { 100, 110, 120 };
var funcs = new List<Func<int>>();
foreach(var v in values)
funcs.Add( ()=>v );
foreach(var f in funcs)
Console.WriteLine(f()); // print 120, 120, 120, whoops??
```
### side-effects
Zie ook [foreach vs ForEach](http://blogs.msdn.com/b/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx): `LINQ` is ontwikkeld om side-effect free te werken, dit wil zeggen dat er altijd een nieuwe collectie aangemaakt wordt. De volgende code is niet voldoende om in een method een lijst te sorteren:
```csharp
private void sortMe(IEnumerable<string> toSort) {
toSort.ToList().Sort(); // ToList() returns a new list! as it should be
}
```
### naming
1. Gebruik `Select()` in plaats van de JS `transform()`.
2. `Aggregate` is een native `foldLeft` - gebruik `Reverse` om van achter naar voor te beginnen.
3. `All` retrourneert een boolean en is om te controleren of er elementen in een collectie zitten, niet om te transformen of te loopen!
### Achterliggende implementatiedetails
http://community.bartdesmet.net/blogs/bart/archive/2008/08/17/folding-left-right-and-the-linq-aggregation-operator.aspx

View File

@ -1,301 +0,0 @@
+++
title = "linqtosql"
draft = false
tags = [
"code",
"csharp",
"linqtosql"
]
date = "2015-07-14"
+++
# code:csharp >> Linqtosql
Zie ook [MSDN LinqToSql pagina](https://msdn.microsoft.com/en-us/library/bb425822.aspx)
## Basic
Principe is een **DataContext** object aanmaken waar je je connectionstring aan meegeeft (`Log` kan naar `Console.Out` ofzo). Vanaf dan via het context object werken:
* `context.GetTable<T>().Where(t ######> t.Property x).ToList()` om te queryen
* bij deleten of wijzigen: `.Attach(entity)` en `.DeleteOnSubmit(entity)`
* ...
Modellen: annoteren met `[Table(Name######"tabelnaam")]`, kolommen met `[Column(Name"kolomnaam", IsPrimaryKey ###### true, IsDbGenerated true)]`
Wijzigingen doorvoeren met `SubmitChanges()` door simpelweg properties van modellen te wijzigen, zoals een "echte" ER tool.
## Advanced
#### ManyToOne relaties en domain driven design
In het model: `[Association(ThisKey ###### "ReferenceId", IsForeignKey true)]` attribuut toevoegen.
Als je een Fetch wil doen en associaties ook wenst op te halen moet je dit **altijd meegeven**: `new DataLoadOptions().LoadWith<T>(t => t.AssociationProperty)`. Ook deze loadoptions meegeven aan de context.
Indien dit overgeslagen wordt, zal bij een ToList in LINQ die property niet opgehaald worden. Dit is vervelend om elke keer mee te geven - kan ook generiek, bijvoorbeeld zo:
```csharp
private static void AddLoadOptions<T>(DataContext context) where T : class, new()
{
if (IsAssociation<T>())
{
var loadOps = new DataLoadOptions();
((IAssociationModel)new T()).AssociationsToLoad(loadOps);
context.LoadOptions = loadOps;
}
}
private static bool IsAssociation<T>() where T : class, new()
{
return typeof(IAssociationModel).IsAssignableFrom(typeof(T));
}
```
`AddLoadOptions` altijd aanroepen wanneer een fetch in een repository zou gebeuren. Dit zit er op de interface:
```csharp
public interface IAssociationModel
{
IList<object> AssocationsToAttach();
void AssociationsToLoad(DataLoadOptions loadOps);
}
```
Zo kan iedere entiteit zijn eigen `LoadWith` oproepen.
#### Transacties
Gebruik `TransactionScope` object, aanmaken voor je iets doet en `.Complete()` of `.Dispose()` oproepen. <br/><br/>
Om dit niet de helel tidj zelf te moeten beheren, complexiteit opbergen in een basis Repository klasse, zoiets:
```csharp
using (var repo = Repository.Instance.Transactional())
{
Fetch(); // ...
Delete();
// ...
}
```
om dan in de `Dispose()` de transactie te completen. De transactionele method maakt een scope aan.
## Compleet voorbeeld repository
```chsarp
public class Repository : IRepository
{
private readonly string _ConnectionString;
private DataContext _CurrentContext;
private TransactionScope _TransactionScope;
public Repository(string connectionString)
{
_ConnectionString = connectionString;
}
private Repository(Repository baseRepo)
: this(baseRepo._ConnectionString)
{
_CurrentContext = CreateContext();
_TransactionScope = new TransactionScope();
}
public static IRepository Instance { get; set; }
private bool InTransaction
{
get { return _TransactionScope != null; }
}
public void Add<T>(T entity) where T : class, new()
{
InContext(context =>
{
var table = context.GetTable<T>();
if (IsAssociation<T>())
{
foreach (var toAttach in ((IAssociationModel)entity).AssocationsToAttach())
{
context.GetTable(toAttach.GetType()).Attach(toAttach);
}
}
table.InsertOnSubmit(entity);
});
}
public void Add<T>(IEnumerable<T> entities) where T : class
{
InContext(context => context.GetTable<T>().InsertAllOnSubmit(entities));
}
public void CommitChanges<T>(T entity) where T : class
{
InContext(context =>
{
var entityTable = context.GetTable<T>();
if (!InTransaction)
{
entityTable.Attach(entity);
}
context.Refresh(RefreshMode.KeepCurrentValues, entity);
});
}
public int Count<T>(ICanModifyIQueryable<T> queryModifier) where T : class, new()
{
return InContext(context =>
{
AddLoadOptions<T>(context);
IQueryable<T> list = context.GetTable<T>();
list = queryModifier.ModifyForCount(list);
return list.Count();
});
}
public void Delete<T>(T entity) where T : class
{
InContext(context =>
{
var entityTable = context.GetTable<T>();
if (!InTransaction)
{
entityTable.Attach(entity);
}
entityTable.DeleteOnSubmit(entity);
});
}
public void Dispose()
{
CompleteTransaction();
}
public List<T> Fetch<T>() where T : class, new()
{
return InContext(context =>
{
AddLoadOptions<T>(context);
return context.GetTable<T>().ToList();
});
}
public List<T> FetchBy<T>(Expression<Func<T, bool>> whereClause) where T : class, new()
{
return InContext(context =>
{
AddLoadOptions<T>(context);
return context.GetTable<T>()
.Where(whereClause)
.ToList();
});
}
public List<T> FetchBy<T>(ICanModifyIQueryable<T> queryModifier) where T : class, new()
{
return InContext(context =>
{
AddLoadOptions<T>(context);
IQueryable<T> list = context.GetTable<T>();
list = queryModifier.Modify(list);
return list.ToList();
});
}
public IRepository Transactional()
{
return new Repository(this);
}
private static void AddLoadOptions<T>(DataContext context) where T : class, new()
{
if (IsAssociation<T>())
{
var loadOps = new DataLoadOptions();
((IAssociationModel)new T()).AssociationsToLoad(loadOps);
context.LoadOptions = loadOps;
}
}
private static bool IsAssociation<T>() where T : class, new()
{
return typeof(IAssociationModel).IsAssignableFrom(typeof(T));
}
private void CompleteTransaction()
{
if (_CurrentContext ###### null || !InTransaction)
{
return;
}
try
{
_CurrentContext.SubmitChanges();
_TransactionScope.Complete();
}
finally
{
_TransactionScope.Dispose();
_CurrentContext.Dispose();
_TransactionScope = null;
_CurrentContext = null;
}
}
private DataContext CreateContext()
{
return new DataContext(_ConnectionString) { Log = Console.Out };
}
private void InContext(Action<DataContext> action)
{
InContext(context =>
{
action(context);
return true;
});
}
private T InContext<T>(Func<DataContext, T> action)
{
var context = _CurrentContext;
var newContext = false;
if (context ###### null)
{
context = CreateContext();
newContext = true;
}
try
{
// context.Log = Console.Out;
var value = action(context);
if (newContext)
{
context.SubmitChanges();
}
return value;
}
finally
{
if (newContext)
{
context.Dispose();
}
}
}
}
```

View File

@ -1,60 +0,0 @@
+++
title = "meta"
draft = false
tags = [
"code",
"csharp",
"meta"
]
date = "2014-02-13"
+++
# Metaprogramming
### Tests on source code contents
Wat is de bedoeling? Lees alle source files in en check of er iets in voorkomt (in onderstaand geval `Bla.Instance`)
De `GoUpThreeDirs` is omdat bij unit testen draaien dit in rootDir/unitTestProject/Bin/Debug uitgevoerd wordt, dat is de huidige dir. wij hebben nodig: rootDir/sourceCodeProject.
```csharp
[TestMethod]
public void StaticInstanceShouldNeverBeUsedExceptInAllowedCases()
{
foreach (var file in Directory.GetFiles(GetSourcePath(), "*.cs", SearchOption.AllDirectories))
{
var source = File.ReadAllText(file);
if (source.Contains(typeof(Bla).Name + ".Instance") && NoStaticRefAllowedInThatFile(file))
{
Assert.Fail("file " + file + " contains a static reference to Bla which is not allowed!" +
"Please use Dependency Injection instead, take a look at the existing repositories as an example.");
}
}
}
private bool NoStaticRefAllowedInThatFile(string file)
{
List<Type> allowedTypesWithInstanceRef = new List<Type>()
{
typeof(Bla),
typeof(Blie)
};
return allowedTypesWithInstanceRef.All(x => !file.Contains(x.Name));
}
private static string GetSourcePath()
{
return GoUpThreeDirectories(Environment.CurrentDirectory) + "<br/><br/>ProjectNameOfSourceCode";
}
private static string GoUpThreeDirectories(string dir)
{
string rootDir = dir;
for (var i ###### 1; i < 3; i++)
{
rootDir = rootDir.Substring(0, rootDir.LastIndexOf("<br/><br/>", StringComparison.Ordinal));
}
return rootDir;
}
}
```

View File

@ -1,173 +0,0 @@
+++
title = "nativecalls"
draft = false
tags = [
"code",
"csharp",
"nativecalls"
]
date = "2013-12-13"
+++
# C++ Native calls uitvoeren
#### Voorbeeld project
Wat is het probleem:
1. Ik wil Native C++ methods kunnen aanroepen vanuit C#. Dit kan met de `DllImport` attribute.
2. Ik wil structs kunnen remarshallen die uit de native code komen. Dit kan met `StructLayout` en `PtrToStructrue`.
3. Ik wil een char* mappen op een C# string: gebruik `[MarshalAsAttribute(UnmanagedType.LPStr)]` in uw C# struct.
4. Ik wil parameters mee kunnen geven: gebruik de juiste calling method (STD of DECL) instelling, zie `CallingConvention` op `UnmanagedFunctionPointer`.
```c++
#pragma once
#ifdef _DLL
#define DllExImport __declspec(dllexport)
#else
#define DllExImport __declspec(dllimport)
#endif
struct MyStruct
{
char* id;
char* description;
};
DllExImport MyStruct* __stdcall GetSignals();
```
```c++
#include "stdafx.h"
#include "TestClass.h"
DllExImport MyStruct* __stdcall GetSignals()
{
static MyStruct a[] =
{
{ "id1", "desc1" },
{ "id2", "desc2" },
{ "id3", "desc3" }
};
return a;
}
```
```csharp
namespace structArrayImportTest
{
#region
using System;
using System.Runtime.InteropServices;
#endregion
internal class StructImporter
{
// Charset.Ansi is not needed it seems
[DllImport("kernel32.dll", EntryPoint = "LoadLibrary")]
private static extern IntPtr LoadLibrary(
[MarshalAs(UnmanagedType.LPStr)] string lpLibFileName);
[DllImport("kernel32.dll", EntryPoint = "GetProcAddress")]
private static extern IntPtr GetProcAddress(IntPtr hModule,
[MarshalAs(UnmanagedType.LPStr)] string lpProcName);
[DllImport("kernel32", SetLastError ###### true, EntryPoint "GetProcAddress")]
private static extern IntPtr GetProcAddressOrdinal(IntPtr hModule, IntPtr procName);
[DllImport("kernel32.dll", EntryPoint = "FreeLibrary")]
private static extern bool FreeLibrary(int hModule);
[StructLayout(LayoutKind.Sequential)]
public class MyStruct
{
[MarshalAsAttribute(UnmanagedType.LPStr)]
public string _id;
[MarshalAsAttribute(UnmanagedType.LPStr)]
public string _description;
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate IntPtr fGetSignals();
public fGetSignals GetSignals;
public void Import()
{
IntPtr lib = LoadLibrary(@"C:<br/>Users<br/>bkwog<br/>Documents<br/>Visual Studio 2012<br/>Projects<br/>structArrayExportTest<br/>Debug<br/>structArrayExportTest.dll");
// gebruik dumpbin /exports [bla.dll] om ordinal & name van exported functions te bepalen.
IntPtr signalsHandle = GetProcAddressOrdinal(lib, new IntPtr(1));
GetSignals = (fGetSignals) Marshal.GetDelegateForFunctionPointer(signalsHandle, typeof (fGetSignals));
IntPtr myStructs = GetSignals();
int structSize = Marshal.SizeOf(typeof(MyStruct));
Console.WriteLine(structSize);
for (int i = 0; i < 3; ++i)
{
// What's the difference between toInt32 & 64 here? Both work...
IntPtr data = new IntPtr(myStructs.ToInt64() + structSize * i);
MyStruct ms = (MyStruct)Marshal.PtrToStructure(data, typeof(MyStruct));
Console.WriteLine("id: " + ms._id + " - descr: " + ms._description );
}
}
}
}
```
#### Calling convention
In te stellen via C++ project settings -> advanced -> calling convention, voor alles, of per functie met `__stdcall`. C# werkt hiet default mee. Aanpasbaar in het attribute, zie boven.
Als de calling convention niet overeen zou komen, krijg je bij het uitvoeren in de C# code de volgende fout:
> call to PInvoke function 'structArrayImportTest!structArrayImportTest.StructImporter+fGetSignals::Invoke' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
#### dumpbin
Als je niet met ordinals wenst te werken maar de volledige naam van de functie kan jet met `dumpbin.exe` dit achterhalen:
```
C:<br/>Program Files (x86)<br/>Microsoft Visual Studio 10.0<br/>Common7<br/>IDE>dumpbin /exports TfsAdmin.exe structArrayExportTest.dll
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file TfsAdmin.exe
File Type: EXECUTABLE IMAGE
Dump of file structArrayExportTest.dll
File Type: DLL
Section contains the following exports for structArrayExportTest.dll
00000000 characteristics
52A888CA time date stamp Wed Dec 11 16:46:18 2013
0.00 version
1 ordinal base
2 number of functions
2 number of names
ordinal hint RVA name
1 0 00011113 ?GetSignals@@YAPAUTestStruct@@XZ
2 1 000110E6 ?GetSize@@YAPAHXZ
Summary
1000 .data
1000 .idata
3000 .rdata
3000 .reloc
11000 .rsrc
8000 .text
10000 .textbss
```
Merk op dat de functie `GetSignals` hier niet die naam heeft, maar `?GetSignals@@YAPAUTestStruct@@XZ`!

View File

@ -1,560 +0,0 @@
+++
title = "persistence"
draft = false
tags = [
"code",
"csharp",
"persistence"
]
date = "2015-07-13"
+++
# Persistence
## NHibernate
### Second level caching
Gebruik [SysCache2](http://www.codeproject.com/Articles/529016/NHibernate-Second-Level-Caching-Implementation) voor Web projecten. Hoe enablen? DLL ref + in config:
```csharp
Configuration.SessionFactory().Caching.Through<SysCacheProvider>().WithDefaultExpiration(60);
Configuration.SetProperty(Environment.UseSecondLevelCache, "true");
Configuration.SetProperty(Environment.UseQueryCache, "true");
```
In hbm mappings moet je entiteiten cache-baar markeren (read-only, read-write, ... zie docs) met `<cache usage="read-write" />`. Vanaf dan kan je aan Criteria of LINQ queries dingen doen als:
1. `Session.Query<Obj>().Cachable().List()` of
2. `Session.CreateCriteria<Obj>().SetCachable(true)`
Groeperen in "regions" is ook mogelijk, mee te geven met criteria.
#### Clearing everything
```csharp
SessionFactory.EvictQueries();
foreach (var collectionMetadata in SessionFactory.GetAllCollectionMetadata())
SessionFactory.EvictCollection(collectionMetadata.Key);
foreach (var classMetadata in SessionFactory.GetAllClassMetadata())
SessionFactory.EvictEntity(classMetadata.Key);
```
#### Using regions
Sectie toevoegen in `configSections`:
```
<section name######"syscache2" type"NHibernate.Caches.SysCache2.SysCacheSection, NHibernate.Caches.SysCache2"/>
```
En dan dit stuk bijvoorbeeld om syscache2 te configureren:
```
<syscache2>
<cacheRegion name######"RegionName" priority"High">
<dependencies>
<commands>
<add name="test"
command="Select col from dbo.[Table]"
connectionName="default"
connectionStringProviderType="Utilities.Connection.SysCache2ConnectionStringProvider, PFW.Utilities"/>
</commands>
</dependencies>
</cacheRegion>
</syscache2>
```
Queries en entiteiten laten cachen via die naam.
Er is een standaard connectionStringProvider die uit het `connectionStrings` stuk uit de web/app.config uw string uitleest geïmplementeerd: `ConfigConnectionStringProvider`. Indien iets custom nodig zoals in bovenstaand voorbeeld, afleiden van `IConnectionStringProvider` en zelf de connectionstring voorzien (connectionName wordt als parameter meegegeven maar is in dit geval nutteloos).
Op database niveau moet je ook nog een aantal dingen nagaan:
1. Is de dbo user eigenaar van de database voor het region command uit te voeren? (`use [DbName] EXEC sp_changedbowner 'sa`')
2. Is de broker service actief? Indien neen zet aan, zie [code/db/mssql]({{< relref "wiki/code/db/mssql.md" >}})
### LINQ OR queries schrijven
AND queries zijn makkelijk te schrijven met `.Where()` chaining in LINQ. Hoe doe je dit met SQL ORs? Met de PredicateBuilder:
```csharp
/// <summary>
*/ http:*www.albahari.com/nutshell/predicatebuilder.aspx
/// </summary>
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters);
return Expression.Lambda<Func<T, bool>>
(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression<Func<T, bool>> False<T>()
{
return f => false;
}
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters);
return Expression.Lambda<Func<T, bool>>
(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression<Func<T, bool>> True<T>()
{
return f => true;
}
}
```
Voorbeeld:
```csharp
var pred = PredicateBuilder.False<IOccupation>();
pred ###### pred.Or(occ > new List<decimal>() {1, 2}.Contains(occ.Id));
pred ###### pred.Or(occ > new List<decimal>() {1, 2}.Contains(occ.Id));
Session.Query<IOccupation>()
.Where(pred)
.ToList();
```
### Sessie contexten
* [Current session architecture](http://www.nhforge.org/doc/nh/en/index.html#architecture-current-session)
Te mappen in xml:
```xml
<property name="current_session_context_class">thread_static</property>
```
Zelf te (un-)binden via:
```csharp
var session = sessionFactory.OpenSession();
if (!CurrentSessionContext.HasBind(sessionFactory))
{
CurrentSessionContext.Bind(session);
}
```
Dan kan je `SessionFactory.GetCurrentSession()` gebruiken.
Een typische manier van werken is session-per-request, in begin van request een sessie openen & binden, en op het einde sluiten. Dit zorgt voor problemen bij asynchrone calls omdat de sessie gebind wordt op `HttpContext` die dan uiteraard verdwenen is. Een tussenoplossing is werken met een hybride sessie context: gebruik de HTTP context indien mogelijk, werk anders met een `ThreadStatic` variabele. Bijvoorbeeld:
```csharp
public class HybridWebSessionContext : WebSessionContext
{
private const string _SessionFactoryMapKey = "NHibernate.Context.WebSessionContext.SessionFactoryMapKey";
[ThreadStatic]
private static IDictionary _ThreadSessionMap;
private ISession ThreadSession
{
set
{
if (_ThreadSessionMap ###### null)
{
_ThreadSessionMap = new Dictionary<ISessionFactoryImplementor, ISession>();
}
if (value ###### null)
{
_ThreadSessionMap.Remove(_Factory);
}
else
{
_ThreadSessionMap[_Factory] = value;
}
}
}
private readonly ISessionFactoryImplementor _Factory;
// This constructor should be kept, otherwise NHibernate will fail to create an instance of this class.
public HybridWebSessionContext(ISessionFactoryImplementor factory) : base(factory)
{
_Factory = factory;
}
protected override IDictionary GetMap()
{
var currentContext = ReflectiveHttpContext.HttpContextCurrentGetter();
if (currentContext != null)
{
return ReflectiveHttpContext.HttpContextCurrentItems[_SessionFactoryMapKey] as IDictionary;
}
return _ThreadSessionMap;
}
protected override ISession Session
{
set
{
base.Session = value;
ThreadSession = value;
}
}
protected override void SetMap(IDictionary value)
{
var currentContext = ReflectiveHttpContext.HttpContextCurrentGetter();
if (currentContext != null)
{
ReflectiveHttpContext.HttpContextCurrentItems[_SessionFactoryMapKey] = value;
return;
}
_ThreadSessionMap = value;
}
}
```
Die dan in de hibernate config injecteren:
```csharp
configuration.SetProperty(NHibernate.Cfg.Environment.CurrentSessionContextClass, typeof(HybridWebSessionContext).AssemblyQualifiedName);
```
Op die manier werkt `Bind()` altijd.
:exclamation: Geen sessie factory sluiten op het einde van de request maar enkel de `ISession` - uw pooling zit in de factory!
############ Transacties ############
* [Getting TransactionScope to play nice with NHibernate](http://www.mattwrock.com/post/2010/12/26/Getting-TransactionScope-to-play-nice-with-NHibernate.aspx)
* [Batching NHibernate's DML Statements](http://thatextramile.be/blog/2008/10/batching-nhibernates-dm-statements/)
* [NHibernate IPreUpdateEventListener & IPreInsertEventListener](http://ayende.com/blog/3987/nhibernate-ipreupdateeventlistener-ipreinserteventlistener)
######= Multiple nested transactions ######=
is **niet** mogelijk in NHibernate! Hier kan je rond werken door een dummy te retourneren (wel `ISession.BeginTransaction()` decoreren op de onderstaande manier)
```csharp
public ITransaction BeginTransaction()
{
if (_Session.Transaction.IsActive)
{
// bad programmer's code, nice going. nested transactions are not supported in NHibernate!
* see http:*rajputyh.blogspot.be/2011/02/nested-transaction-handling-with.html and http://stackoverflow.com/questions/1192111/how-do-i-do-nested-transactions-in-nhibernate
return new HibernateTransactionDummy();
}
var newTransaction = _Session.BeginTransaction();
return newTransaction;
}
```
######= Locking ######=
[NHibernate mapping & concurrency](http://ayende.com/blog/3946/nhibernate-mapping-concurrency) - pessimistic locking kan gedaan worden door in een query de `LockMode` mee te geven:
```csharp
var person = session.Get<Person>(1,LockMode.Upgrade);
```
Binnen een transactie uiteraard. Dit genereert `with(updlock, rowlock)` in de `SELECT` statements. De lock wordt gereleased wanneer de transactie gecommit wordt. Dit is [blijkbaar geen table lock](http://stackoverflow.com/questions/19873880/understanding-effects-of-with-updlock-rowlock-on-a-query-in-sql-server):
> The `updlock` will place update locks on every row being touched (selected) - so this means until the end of the transaction (explicit or implicit), the row(s) touched by the SELECT will have an update lock on them which allows for other transactions to read, but not update or delete the row. The `rowlock` just indicates that you want row-level locks instead of page or table locks. That lock makes sense if you need to select first, then update a row within the same explicit transaction.
It doesn't make it run any faster, and can cause other transactions to be blocked
############ Event listeners ############
:exclamation: in events als `IPreInsertEventListener` moet je zowel het object (via `@Event.Entity`) als de state (via `@Event.State`) wijzigen. Hoe werkt dit met `IPersistEventListener`?
Custom event listener die de Java annotaties zoals `@PrePersist` ea mogelijk maakt in C# met attributes:
```csharp
public class HibernateAttributeEventListener : IPreUpdateEventListener, IPreInsertEventListener, IPersistEventListener, IFlushEntityEventListener
{
public bool OnPreUpdate(PreUpdateEvent @event)
{
InvokeMethodsWithAttribute(@event.Entity, @event.Session, typeof(PreUpdate));
return false;
}
public bool OnPreInsert(PreInsertEvent @event)
{
InvokeMethodsWithAttribute(@event.Entity, @event.Session, typeof(PreInsert));
return false;
}
public void OnPersist(PersistEvent @event)
{
InvokeMethodsWithAttribute(@event.Entity, @event.Session, typeof(PrePersist));
}
public void OnPersist(PersistEvent @event, IDictionary createdAlready)
{
}
public void OnFlushEntity(FlushEntityEvent @event)
{
}
private static void InvokeMethodsWithAttribute(object entity, ISession session, Type attributeType)
{
entity.GetType()
.GetMethods()
.Where(method => method.GetCustomAttributes(attributeType, false).Length > 0)
.ForEach(method => Invoke(entity, session, method));
}
private static void Invoke(object entity, ISession session, MethodInfo method)
{
var parameters = method.GetParameters();
if (parameters.Length ###### 0)
{
method.Invoke(entity, new object[] {});
} else if (parameters.Length ###### 1 && parameters[0].ParameterType ###### typeof (ISession))
{
method.Invoke(entity, new object[] {session});
}
else
{
throw new ArgumentException("Error while invoking attribute event method, only 0 or 1 params (ISession) is supported!");
}
}
```
Dit kan je dan aan de config hangen met `_Configuration.EventListeners.PreInsertEventListeners = new IPreInsertEventListener[] {new HibernateAttributeEventListener()};` - moet per type listener dat je wenst te gebruiken. De attributes zijn zo gedefiniëerd (enkel op method):
```csharp
[AttributeUsage(AttributeTargets.Method)]
public class PrePersist : Attribute
{
}
```
:exclamation: Indien state wijzigt in `PrePersist` of `PreUpdate` moet je ook de @event.State wijzigen, naast de state van het object zelf.
Voor details zie [http:*ayende.com/blog/3987/nhibernate-ipreupdateeventlistener-ipreinserteventlistener](http:*ayende.com/blog/3987/nhibernate-ipreupdateeventlistener-ipreinserteventlistener)
Een manier is bvb om dirty field checks te doen met reflectie:
```csharp
public static Dictionary<string, object> GetFieldValues(this Type type, object obj)
{
return type.GetProperties().ToDictionary(
property => property.Name,
property => property.GetValue(obj, null));
}
private static void Set(IEntityPersister persister, object[] state, string propertyName, object value)
{
var index = Array.IndexOf(persister.PropertyNames, propertyName);
if (index ###### -1)
return;
state[index] = value;
}
// ...
var initialFieldValues = @event.Entity.GetType().GetFieldValues(@event.Entity);
// invoke [makes some fields dirty]
UpdateDirtyFieldValuesInState(@event, state, initialFieldValues);
private static void UpdateDirtyFieldValuesInState(AbstractPreDatabaseOperationEvent @event, object[] state, Dictionary<string, object> initialFieldValues)
{
foreach (var actualValue in @event.Entity.GetType().GetFieldValues(@event.Entity))
{
if (!Equals(initialFieldValues[actualValue.Key], actualValue.Value))
{
Set(@event.Persister, state, actualValue.Key, actualValue.Value);
}
}
}
```
############ Identity generators ############
:exclamation: `identity` gebruikt de native autoincrement aan de DB maar is helemaal niet performant, maakt `batch_size` redundant - veel roundtrips nodig. Een alternatief bijvoorbeeld:
* [NHibernate Custom Id-generator based on hilo](http://daniel.wertheim.se/2011/03/08/nhibernate-custom-id-generator/)
Zie ook [Hibernate doc: mappings](http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html) voor alle mogelijkheden.
Een custom generator die een tabel gebruikt met een kolom die de entity weergeeft werkt zo:
```csharp
public class NHibIdGenerator : TableHiLoGenerator
{
public override void Configure(IType type, IDictionary<string, string> parms, Dialect dialect)
{
if (!parms.ContainsKey("table"))
parms.Add("table", "NHibHiLoIdentities");
if (!parms.ContainsKey("column"))
parms.Add("column", "NextHiValue");
if (!parms.ContainsKey("max_lo"))
parms.Add("max_lo", "100");
if (!parms.ContainsKey("where"))
parms.Add("where", string.Format("EntityName='{0}'", parms["target_table"]));
base.Configure(type, parms, dialect);
}
}
```
En dan in de hibernate mapping:
```xml
<id name######"Id" column"`id`">
<generator class="Utilities.Database.NHibIdGenerator, Utilities" />
</id>
```
Na de komma staat de full-qualified assembly.
############ Probleemoplossing ############
###### can only generate ids as part of bulk insert with either sequence or post-insert style generators ######
Identity generator voor die bepaalde tabel moet een custom post-insert generator zijn (zoals bovenstaande `hilo` generator). Waarom? Dit gaat:
1. eerst in bluk inserts doen
1. dan in bulk ids bepalen afhankelijk van custom generator (bvb tabel met next id)
1. dan in bulk update uitvoeren om id te plaatsten in db
Dit betekent ook dat de ID kolom nullable moet zijn en er geen native generator in de weg mag zitten.
###### There is already an open DataReader associated with this Connection which must be closed first ######
```
Exception:
Exception has been thrown by the target of an invocation.
Inner Exception:
MySql.Data.MySqlClient.MySqlException (0x80004005): There is already an open DataReader associated with this Connection which must be closed first. at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception) at MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() at MySql.Data.MySqlClient.MySqlTransaction.Rollback() at NHibernate.Transaction.AdoTransaction.Dispose(Boolean isDisposing) in d:<br/>BuildAgents<br/>BuildAgentTwo<br/>work<br/>9126a46c2421d993<br/>PFW.Base<br/>NHibernate<br/>Transaction<br/>AdoTransaction.cs:line 368 at NHibernate.Transaction.AdoTransaction.Dispose() in d:<br/>BuildAgents<br/>BuildAgentTwo<br/>work<br/>9126a46c2421d993<br/>PFW.Base<br/>NHibernate<br/>Transaction<br/>AdoTransaction.cs:line 340 at
...
Exception:Exception has been thrown by the target of an invocation.Inner Exception:System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first. at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) at System.Data.SqlClient.SqlInternalTransaction.Rollback() at System.Data.SqlClient.SqlInternalTransaction.Dispose(Boolean disposing) at System.Data.SqlClient.SqlTransaction.Dispose(Boolean disposing) at NHibernate.Transaction.AdoTransaction.Dispose(Boolean isDisposing) at PFW.Utilities.Layers.ServiceLayer.TransactionalAttribute.OnExit(MethodExecutionArgs args) at ServiceLayer.Person.PersonBaseSL.Persist(IPersonBase person) at FacadeLayer.Person.PersonBaseRF.Persist(HttpRequest request) Exception:Exception has been thrown by the target of an invocation.Inner Exception:System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first. at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) at System.Data.SqlClient.SqlInternalTransaction.Rollback() at System.Data.SqlClient.SqlInternalTransaction.Dispose(Boolean disposing) at System.Data.SqlClient.SqlTransaction.Dispose(Boolean disposing) at NHibernate.Transaction.AdoTransaction.Dispose(Boolean isDisposing) at
...
```
Als we kijken in de code van `MySqlCommand` vinden we:
```csharp
private void CheckState()
{
if (this.connection ###### null)
this.Throw((Exception) new InvalidOperationException("Connection must be valid and open."));
if (this.connection.State != ConnectionState.Open && !this.connection.SoftClosed)
this.Throw((Exception) new InvalidOperationException("Connection must be valid and open."));
if (!this.connection.IsInUse || this.internallyCreated)
return;
this.Throw((Exception) new MySqlException("There is already an open DataReader associated with this Connection which must be closed first."));
}
```
`IsInUse` wordt gezet in de setter van `Reader` in `MySqlConnection`
* Zowel in `MySqlClient` als `SqlClient`, dus client onafhankelijk
* Volgens google betekent dit dat we `ISession` objecten delen over verschillende threads/requests
:exclamation: Probleem was dat wij [PostSharp](http://www.postsharp.net/aspects/examples/transaction) gebruiken maar op de attribute class state bijhielden (de transactie zelf) om die bij onexit te kunnen committen. Andere users herbruiken diezelfde klasse blijkbaar, waarbij user1 transacties van user2 gaat committen etc. Correcte implementatie - zie link postsharp als voorbeeld; of:
```csharp
[Serializable]
public class TransactionalAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
NHibernateFactory.CurrentSession.BeginTransaction();
base.OnEntry(args);
}
public override void OnExit(MethodExecutionArgs args)
{
NHibernateFactory.CurrentSession.Transaction.Dispose();
base.OnExit(args);
}
public override void OnSuccess(MethodExecutionArgs args)
{
NHibernateFactory.CurrentSession.Transaction.Commit();
base.OnSuccess(args);
}
}
```
Blijkbaar mag ook `MethodExecutionArgs` gebruikt worden om tijdelijk state in te storen die je bij `OnExit()` terug kan resolven - zie voorbeeld op de [PostSharp website](http://www.postsharp.net/aspects/examples/transaction).
###### Detached entity passed to persist (in een test) ######
Uw Id niet zelf meegeven, steekt een generator in uw mapping...
###### System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. ######
Oplossing: in hibernate mapping file staan twee keer kolommen gedefiniëerd (eventueel onder een `composite-id`) - deze moet `update` en `insert` attributes op `false` hebben, of niet dubbel gemapped worden, hier kan Hibernate blijkbaar niet mee om gaan...
###### No data type for node [entityProperty] ######
Bij een `HQL` query, wanneer je meer dan 8 properties select, **moet** je een alias gebruiken:
```
select entity.one, entity.two, entity.three, ... from Entity entity where entity.Id in (10, 11)
```
en dus niet
```
select one, two, three from Entity where Id in (10, 11)
```
###### The multi-part identifier "occupation0_.functieid" could not be bound. ######
Impliciete en expliciete joins worden gemixed in uw select statement (al dan niet gewild door NHibernate). Probleem:
```sql
SELECT tbl1.col1, tbl2.col2, tbl3.col3
FROM tbla tbl1, tblb tbl2
INNER JOIN tblc tbl3 on tbl1.joincol = tbl1.joincol
WHERE tbl1.joincol2 = tbl2.joincol2
AND tbl2.joincol3 = tbl3.joincol3
```
er wordt zowel met `INNER JOIN` als met `WHERE` een join gelegd naar andere tabellen. In MSSQL geeft dit problemen (sommige andere DBs niet?). Mogelijke oplossingen in NHibernate:
1. Gebruik Criteria om alles expliciet te joinen (joepie...)
1. Selecteer in een LINQ query geen entiteit maar de Id en map die achteraf
###### Error Code: 1054. Unknown column 'personlite2_.WerknemerID' in 'on clause' ######
* Multiple join in HQL die in de verkeerde volgorde staat? Draai `join x as y join y as z` eens om, zodat de joins andersom gelegd worden.
Concreet voorbeeld:
```sql
SELECT col1, col2, col3
FROM bliebloe
INNER JOIN tabel alias ON alias.x = bliebloe.y,
col4,
INNER JOIN tabel2 alias2 ON alias2.x = bliebloe.y
```
Zou moeten zijn:
```sql
SELECT col1, col2, col3
FROM bliebloe
INNER JOIN tabel alias ON alias.x = bliebloe.y,
INNER JOIN tabel2 alias2 ON alias2.x = bliebloe.y,
col4
```
Maar hoe vertellen we `Hibernate` dit? **zet expliciete joins in uw HQL** in de gewenste volgorde:
''select a.x, b.y, c.z
from a
join a.h as b
join a.i as c''
* In MySQL: syntax join mixen ###### no go, zoals select * from table1, table2 where table1.id table2.key join bla join blie - zowel met komma als met de join operator joinen. Doet Hibernate normaal niet.

View File

@ -1,269 +0,0 @@
+++
title = "reflectie"
draft = false
tags = [
"code",
"csharp",
"reflectie"
]
date = "2015-02-09"
+++
# Reflectie
## Get Type based on string
Probleem: een fully qualified classname in string vorm is geen `Type` en `Type.GetType()` gaat standaard in de huidige assembly kijken of die klasse daar in steekt. Hoe haal ik dit type op als ik niet vanbuiten weet in welke assembly ik moet gaan kijken? Via uw `AppDomain`:
```csharp
return AppDomain.CurrentDomain.GetAssemblies()
.Single(app ######> app.GetType(fullClassName) ! null)
.GetType(fullClassName);
```
## Get Subclasses/interfaces of class
Gebruik `type.Assembly.GetTypes()` en filter verder.
1. Als je een **interface** wil hebben, moet je `IsAssignableFrom()` gebruiken (in de omgekeerde richting).
2. Als je een **subklasse** wil hebben, moet je ofwel de `.BaseType` property gebruiken als direct kind, ofwel de `IsSubclassOf()` method.
```csharp
public string HandleMessage(IHostService hostService)
{
var requestType = typeof (IHostServiceNativeRequest);
var handlerType = requestType.Assembly.GetTypes()
.Where(requestType.IsAssignableFrom)
.Single(t ######> (NativeRequestInstance(t)).Key Key);
return NativeRequestInstance(handlerType).ParseRequest(hostService);
}
private IHostServiceNativeRequest NativeRequestInstance(Type t)
{
return (IHostServiceNativeRequest) Activator.CreateInstance(t);
}
```
## Reflective instantiation
Zie vorig voorbeeld; een nieuwe instantie van een `Type` maken kan via `Activator.CreateInstance()`.
##### Protected constructor with arguments
```csharp
return (T)Activator.CreateInstance(typeof(T),
BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.Instance,
null, new object[] { arg1 }, CultureInfo.CurrentCulture);
```
## AppDomains
##### Q: Ik wil een DLL dynamisch laden
Gebruik `Assembly.LoadFrom(string)`.
##### Q: Ik wil loopen over alle AppDomains
Niet zo simpel te realiseren: (zie [http:*stackoverflow.com/questions/14758915/get-all-processes-with-their-corresponding-app-domains](http:*stackoverflow.com/questions/14758915/get-all-processes-with-their-corresponding-app-domains))
```csharp
private static List<AppDomainInf> GetAppDomains()
{
IList<AppDomain> mAppDomainsList = new List<AppDomain>();
List<AppDomainInf> mAppDomainInfos = new List<AppDomainInf>();
IntPtr menumHandle = IntPtr.Zero;
ICorRuntimeHost host = new CorRuntimeHost();
try
{
host.EnumDomains(out menumHandle);
object mTempDomain = null;
//add all the current app domains running
while (true)
{
host.NextDomain(menumHandle, out mTempDomain);
if (mTempDomain ###### null) break;
AppDomain tempDomain = mTempDomain as AppDomain;
mAppDomainsList.Add((tempDomain));
}
//retrieve every app domains detailed information
foreach (var appDomain in mAppDomainsList)
{
AppDomainInf domainInf = new AppDomainInf();
domainInf.Assemblies = GetAppDomainAssemblies(appDomain);
domainInf.AppDomainName = appDomain.FriendlyName;
mAppDomainInfos.Add(domainInf);
}
return mAppDomainInfos;
}
catch (Exception)
{
throw; //rethrow
}
finally
{
host.CloseEnum(menumHandle);
Marshal.ReleaseComObject(host);
}
}
```
Ref toevoegen, mscoree.tld in .NET root folder.
############= Generic Type arguments & reflectie ############=
###### Q: Ik wil een Type meegeven dat moet extenden van een basisklasse, waarna ik dat type wil instantiëren. ######
```csharp
protected IList<TInsertable> Load<TInsertable>() where TInsertable : DatabaseInsertable
{
var myInstance = Activator.CreateInstance(typeof(TInsertable));
}
```
:exclamation: `Type` zelf is niet generic omdat dit at-runtime gebruikt wordt voor typeinformatie en de andere dingen at-compiletime. Je kan dus geen `Type<T> where T : MyClass` gebruiken, zoals in Java bijvoorbeeld `Class<? extends MyClass>` gebruikt wordt. Merk op dat in Java er met het generic type argument geen klasse aangemaakt kan worden, zie [code/java/reflectie]({{< relref "wiki/code/java/reflectie.md" >}}) voor java.
###### Q: Ik wil een variabel aantal generic type argumenten definiëren ######
Genaaid, dit gaat niet. Kijk maar naar bijvoorbeeld `Func<>`:
1. `Func<in T1, in T2, out Result>`
2. `Func<in T1, in T2, in T3, out Result>`
3. `Func<in T1, in T2, in T3, in T4, out Result>`
4. ...
Je kan die wel allemaal laten refereren naar één (private) methode die `params[]` gebruikt, bijvoorbeeld onderstaande count:
```csharp
protected int Count<TInsertable>()
where TInsertable : DatabaseInsertable
{
return Count(typeof (TInsertable));
}
protected int Count<TInsertable1, TInsertable2>()
where TInsertable1 : DatabaseInsertable
where TInsertable2 : DatabaseInsertable
{
return Count(typeof (TInsertable1), typeof (TInsertable2));
}
protected int Count<TInsertable1, TInsertable2, TInsertable3>()
where TInsertable1 : DatabaseInsertable
where TInsertable2 : DatabaseInsertable
where TInsertable3 : DatabaseInsertable
{
return Count(typeof (TInsertable1), typeof (TInsertable2), typeof (TInsertable3));
}
private int Count(params Type[] insertableTypes)
{
var count = 0;
foreach (var type in insertableTypes)
{
var select = "select count(*) from " + GetTableOfType(type);
count += Int32.Parse(factory.CreateCommand(this.connection, select).ExecuteScalar().ToString());
}
return count;
}
```
############= Reflectie en dynamisch code genereren ############=
Mogelijk met **Reflection EMIT**, om dynamisch IL code te genereren. IL is de bytecode tussenlaag in .NET, die je ook in C# kan schrijven.
Compleet voorbeeld: http://www.codeproject.com/Articles/121568/Dynamic-Type-Using-Reflection-Emit
Bijvoorbeeld, om een getal te delen door een ander met `getal / other`, genereert de volgende code dit in IL:
```csharp
MethodBuilder mDivide = tbuilder.DefineMethod("Divide", MethodAttributes.Public |
MethodAttributes.HideBySig |
MethodAttributes.NewSlot |
MethodAttributes.Virtual |
MethodAttributes.Final,
CallingConventions.Standard,
typeof(System.Single),
new Type[] { typeof(System.Int32), typeof(System.Int32) });
mDivide.SetImplementationFlags(MethodImplAttributes.Managed);
ILGenerator dil = mDivide.GetILGenerator();
dil.Emit(OpCodes.Nop);
Label lblTry = dil.BeginExceptionBlock();
dil.Emit(OpCodes.Nop);
dil.Emit(OpCodes.Ldarg_1);
dil.Emit(OpCodes.Ldarg_2);
dil.Emit(OpCodes.Div);
dil.Emit(OpCodes.Conv_R4); // Converts to Float32
dil.Emit(OpCodes.Stloc_1);
dil.Emit(OpCodes.Leave, lblTry);
dil.BeginCatchBlock(typeof(DivideByZeroException));
dil.Emit(OpCodes.Stloc_0);
dil.Emit(OpCodes.Nop);
dil.Emit(OpCodes.Ldstr, "ZeroDivide exception : {0}");
dil.Emit(OpCodes.Ldloc_0);
MethodInfo minfo = typeof(DivideByZeroException).GetMethod("get_Message");
dil.Emit(OpCodes.Callvirt, minfo);
MethodInfo wl = typeof(System.Console).GetMethod("WriteLine", new Type[]
{ typeof(string), typeof(object) });
dil.Emit(OpCodes.Call, wl);
dil.Emit(OpCodes.Nop);
dil.Emit(OpCodes.Ldc_R4, 0.0);
dil.Emit(OpCodes.Stloc_1);
dil.Emit(OpCodes.Leave_S, lblTry);
dil.EndExceptionBlock();
dil.Emit(OpCodes.Nop);
dil.Emit(OpCodes.Ldloc_1);
dil.Emit(OpCodes.Ret);
```
Genereert dit in IL:
```
.method public hidebysig newslot virtual final
instance float32 Divide(int32 firstnum,
int32 secondnum) cil managed
{
// Code size 39 (0x27)
.maxstack 2
.locals init (class [mscorlib]System.DivideByZeroException V_0,
float32 V_1)
IL_0000: nop
.try
{
IL_0001: nop
IL_0002: ldarg.1
IL_0003: ldarg.2
IL_0004: div
IL_0005: conv.r4
IL_0006: stloc.1
IL_0007: leave.s IL_0024
} // end .try
catch [mscorlib]System.DivideByZeroException
{
IL_0009: stloc.0
IL_000a: nop
IL_000b: ldstr "ZeroDivide exception : {0}"
IL_0010: ldloc.0
IL_0011: callvirt instance string [mscorlib]System.Exception::get_Message()
IL_0016: call void [mscorlib]System.Console::WriteLine(string,
object)
IL_001b: nop
IL_001c: ldc.r4 0.0
IL_0021: stloc.1
IL_0022: leave.s IL_0024
} // end handler
IL_0024: nop
IL_0025: ldloc.1
IL_0026: ret
}
```

View File

@ -1,148 +0,0 @@
+++
title = "resources"
draft = false
tags = [
"code",
"csharp",
"resources"
]
date = "2015-10-09"
+++
# C# Resources
## In Tests
Zie [code/csharp/testing]({{< relref "wiki/code/csharp/testing.md" >}})
## Web config
Zie http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
`.NET 4` voorziet een manier om de `Web.config` file automatisch te **transformeren** afhankelijk van uw build configuratie (Debug, Release, custom). Je hebt hier 2 files:
* Web.config (base)
* Web.[BuildConfigName].config (transformer)
Wat in de tweede file staat, gaat toegepast worden op de eerste file. Je kan dus niet zomaar zaken copypasten en overschrijven, maar moet tags die je wil replacen **XDT** transformaties op definiëren:
```xml
<appSettings>
<add key######"Bla" value"blie"/>
</appSettings>
```
met transformer
```xml
<appSettings xdt:Transform="Replace">
<add key######"Bla" value"bloebloe"/>
</appSettings>
```
Zal de hele `appSettings` tag vervangen in de base file. Vergeet dat attribuut en er gebeurt niets.
## Embedded resources ophalen
```csharp
private Stream GetIconAsStream(string icon)
{
return Assembly.GetExecutingAssembly()
.GetManifestResourceStream(
"Full.Namespace.Of.Class.dir.to.image" +
icon);
}
private void CopyIconsToDir(string dir, params string[] iconNames)
{
foreach (var icon in iconNames)
{
var downloadStream = GetIconAsStream(icon);
var tmpFileCreate = File.Create(dir + "<br/><br/>" + icon);
downloadStream.CopyTo(tmpFileCreate);
tmpFileCreate.Close();
downloadStream.Close();
}
}
```
## .CSPROJ file inlezen & parsen
Waarom is dit handig? Om bijvoorbeeld te kunnen kijken welke files allemaal included zijn in uw project en met een test alle SQL files verplicht te laten embedden. <br/><br/>
(Op die manier staan ze niet als "Content" in de XML structuur). Regex op loslaten of XML parsen.
```csharp
private static string ReadProjectFile()
{
var dbAssembly = typeof(AbstractUpdater).Assembly;
* format: 'file:*/C:/Sources/project/UnitTestproject/bin/Debug/project.UnitTest.DLL'
var projectDir = dbAssembly.CodeBase.Substring(0, dbAssembly.CodeBase.IndexOf(".UnitTest", StringComparison.InvariantCulture));
var csprojFile = Directory.GetFiles(projectDir.Replace("file:///", ""), "*.csproj")[0];
var csproj = File.ReadAllText(csprojFile);
return csproj;
}
```
## Managed resources disposen
:exclamation: Zie [Dispose Pattern @ MSDN](http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=vs.110).aspx); volgende template:
```csharp
public class DisposableResourceHolder : IDisposable {
private SafeHandle resource; // handle to a resource
public DisposableResourceHolder(){
this.resource = ... // allocates the resource
}
public void Dispose(){
Dispose(true);
GC.SuppressFinalize(this); // tell the GC disposing it isn't needed anymore
}
protected virtual void Dispose(bool disposing){
if (disposing){
if (resource!= null) resource.Dispose();
}
}
}
```
#### using()
De .NET CLR vertaalt
```csharp
using (MyResource myRes = new MyResource())
{
myRes.DoSomething();
}
```
naar
```csharp
{ // limits scope of myRes
MyResource myRes= new MyResource();
try
{
myRes.DoSomething();
}
finally
{
// Check for a null resource.
if (myRes!= null)
// Call the object's Dispose method.
((IDisposable)myRes).Dispose();
}
}
```
Moet dan uw object de interface `IDisposable` implementeren? Harde cast toch?
#### Java VS C#
Beiden plaatsten objecten in een finalizer queue maar het uitvoeren hiervan is nooit gegarandeerd (crash process, iets anders dat kan gebeuren, ...). `IDisposable` kan gebruikt worden om managed resources op te kuisen, **maar moet manueel aangeroepen worden** door clients die dit object gebruiken - hier is ook nog niets van gegarandeerd! Behalve in een `using(obj) { }` block - hierna wordt `Dispose()` aangeroepen, ook als er ondertussen een of andere Exception opgetreden is. In Java 6 en lager moet je dit met `try { } finally { }` manueel doen.
Zie [java resources wiki pagina]({{< relref "wiki/code/java/resources.md" >}})

View File

@ -1,37 +0,0 @@
+++
title = "signing"
draft = false
tags = [
"code",
"csharp",
"signing"
]
date = "2014-07-11"
+++
# Signing
#### Compile fouten: 'cannot import the following key file'
```
C:<br/>Windows<br/>Microsoft.NET<br/>Framework<br/>v4.0.30319<br/>Microsoft.Common.targets(2455, 5): error MSB3325: Cannot import the following key file: ign.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_0E36C1B21D0EBCA4
```
Oplossen door met `sntool` te registreren en die container naam aan te maken (VS_KEY_...)
#### Assemblies signen
Properties -> Signing -> Sign the assembly aanvinken. Choose a strong name key file... (browse)
#### Friend classes & signed assemblies
In `AssemblyInfo.cs` ook de public key meegeven van de friend assembly:
```csharp
[assembly: InternalsVisibleTo("ServiceLayer.UnitTest, PublicKey=00240000048000002a51cadd46bbd321cda4e67d2...c125d7eb")]
```
##### De public key opvragen van een assembly
Met `sn.exe`, geïnstalleerd onder uw .NET SDK dir, bijvoorbeeld `C:<br/>Program Files (x86)<br/>Microsoft SDKs<br/>Windows<br/>v7.0A<br/>Bin`
`sn -Tp [assembly.dll]` uitvoeren. Of de sign file vastnemen en deze uitlezen. Zie [MSDN Strong Name Tool help](http://msdn.microsoft.com/en-us/library/k5b5tt23(v=vs.110).aspx).

View File

@ -1,130 +0,0 @@
+++
title = "testing"
draft = false
tags = [
"code",
"csharp",
"testing"
]
date = "2014-06-27"
+++
# Testing met C#/.NET
## Test frameworks
### Selenium/WebDriver
Zie http://www.joecolantonio.com/2012/07/31/getting-started-using-selenium-2-0-webdriver-for-ie-in-visual-studio-c/ - essentiëel identiek aan Java.
#### Chaining - fluent acceptance criteria definitions
Een typische test zou er dan zo kunnen uitzien:
```csharp
[Test]
public void OpenAdminAuthenticationManagement()
{
LogInto()
.OpenAdministrationAuthenticationManagement()
.AuthenticationGrid
.ShouldContainMinAmountRows(1)
.DoubleClickOnRowNr(0)
.ExpectOpened<ModifyUserDetailWindow>()
.UserNameShouldContainSomeValue();
}
```
1. Gebruik overal `return this`
2. Wanneer je niet wil upcasten en in een abstract component `ClickSave()` uw subtype moet retourneren: `public class Panel<T> : Window where T : Panel<T>` en `return (T) this`
3. Wanneer je niet weet wat het volgend scherm is, gebruik `ExpectOpened<Type>()` dat via [code/csharp/reflectie]({{< relref "wiki/code/csharp/reflectie.md" >}}) een instantie aanmaakt van uw component.
### NUnit
#### Attributes
Zoals in JUnit's annotaties `@Before` en `@Test` kan je hier `[SetUp]` en `[Test]` gebruiken. Een test klasse moet met de attribute `[TestFixture]` geplakt worden.
Zie [MSTest en NUnit comparison](http://blogs.msdn.com/b/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx)
**Hoe kan ik dit via command-line uitvoeren?**
Installeer [NUnit](http://nunit.org/?p=download) en pas uw `PATH` aan zodat de install dir er in steekt (program files<br/>nunit). Vanaf dan kan je `nunit-console test.dll` via commandline gebruiken om de test zo uit te voeren.
### MSTest
#### Attributes
Zoals in JUnit's annotaties `@Before` en `@Test` kan je hier `[TestInitialize]` en `[TestMethod]` gebruiken. Er zijn enkele "pitfalls" -
`[ClassInitialize]`, zogezegd het equivalent van `@BeforeClass`, werkt **niet** op base classes: zie http://blogs.msdn.com/b/densto/archive/2008/05/16/using-a-base-class-for-your-unit-test-classes.aspx
Een mogelijke "oplossing" is dit: (let op, niet helemaal hetzelfde)
```csharp
[TestClass]
public abstract class TestBase
{
[AssemblyInitializeAttribute]
public static void Initialize(TestContext context)
{
// put your initialize code here
}
}
```
Of overal de base aanroepen...
## Mocking en stubbing
### Microsoft Fakes
Zie http://msdn.microsoft.com/en-US/library/hh549175
Als je `Fakes` toevoegt als reference, gebeurt er het volgende (enkel voor interfaces):
> The special piece of magic here is the class StubIStockFeed. For every interface in the referenced assembly, the Microsoft Fakes mechanism generates a stub class. The name of the stub class is the derived from the name of the interface, with "Fakes.Stub" as a prefix, and the parameter type names appended.
### Rhino Mocks
Zie http://www.hibernatingrhinos.com/oss/rhino-mocks
##### Automatisch mocking fields initializeren
```csharp
public abstract class AbstractTestCase
{
[TestInitialize]
public void CreateMocksBasedOnNamingConvention()
{
this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.Name.EndsWith("Mock")).All(InitMock);
}
private bool InitMock(FieldInfo field)
{
field.SetValue(this, MockRepository.GenerateMock(field.FieldType, new Type[]{}));
return true;
}
}
```
Hupla.
## Resources en deployment
[How to deploy files for tests](http://msdn.microsoft.com/en-us/library/ms182475.aspx)
Er moeten aan een aantal condities voldaan worden:
* een mstest `.testsettings` XML file waar de tag `<DeploymentEnabled/>` op `true` staat (extra te deployen files zijn daar kinderen van) - dit kan automatisch geëdit worden met VS2010 maar blijkbaar niet meer met VS2012... Als de tag zelf niet voorkomt werkt het in 2012 ook nog (?)
* een resource hebben die op `Content` en `Copy` staat
* Een `DeploymentItem` attribute hebben die de te kopiëren file specifiëert (merk op dat subfolders hier ook ingevuld moeten zijn)
```csharp
[TestClass]
[DeploymentItem("IEDriverServer.exe")]
public abstract class EndToEndTestCase
{
}
```
De deployment items zijn niet nodig als de testen uitgevoerd worden vanuit de bin folder. Meestal is dit een aparte MSTest locatie (temp zoals `C:<br/>Users<br/>bkwog<br/>AppData<br/>Local<br/>Temp<br/>TestResults<br/>bkwog_HI18261 2013-12-23 10_28_54`) waar dan resources niet bij steken maar enkel DLLs en PDBs - bijgevolg problemen...

View File

@ -1,168 +0,0 @@
+++
title = "tfs"
draft = false
tags = [
"code",
"csharp",
"tfs"
]
date = "2013-07-26"
+++
# Tfs communicator
#### TFS informatie vanuit .NET uitlezen
[OData TFS v2](http://blogs.msdn.com/b/briankel/archive/2013/01/07/odata-service-for-team-foundation-server-v2.aspx) is een tussenlaag `REST API` die je zelf nog op `IIS` kan deployen...
Onderstaande code doet hetzelfde (veel eenvoudiger) in een console appke
```csharp
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
namespace TfsCommunicator
{
[ExcludeFromCodeCoverage]
public class BuildCommunicator : IBuildCommunicator
{
private string tfsServerAddress;
public BuildCommunicator(string tfsServerAddress)
{
this.tfsServerAddress = tfsServerAddress;
}
public BuildStatus GetBuildInformation(int maxDays ###### 5, int maxRuns 10, string teamProject ###### "*", string buildDefinition "")
{
var buildStatus = new BuildStatus();
var builds = GetBuildsFromTfs(maxDays, teamProject, buildDefinition);
var currentDefinition = string.Empty;
foreach (var build in builds)
{
string definitionName = build.BuildDefinition.Name;
var project = MapBuildToProject(build, definitionName);
if (definitionName ###### currentDefinition)
{
AddBuiltToParentProject(buildStatus, definitionName, project, maxRuns);
}
else
{
currentDefinition = definitionName;
buildStatus.Projects.Add(project);
}
}
return buildStatus;
}
private IOrderedEnumerable<IBuildDetail> GetBuildsFromTfs(int maxDays, string teamProject, string buildDefinition)
{
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsServerAddress));
IBuildServer buildServer = tfs.GetService<IBuildServer>();
IBuildDetailSpec spec = string.IsNullOrEmpty(buildDefinition) ?
buildServer.CreateBuildDetailSpec(teamProject) :
buildServer.CreateBuildDetailSpec(teamProject, buildDefinition);
spec.MinFinishTime = DateTime.Now.Subtract(TimeSpan.FromDays(maxDays));
spec.MaxFinishTime = DateTime.Now;
spec.QueryDeletedOption = QueryDeletedOption.IncludeDeleted;
var builds ###### buildServer.QueryBuilds(spec).Builds.OrderBy(b > b.BuildDefinition.Name).ThenByDescending(b => b.FinishTime);
return builds;
}
private static Project MapBuildToProject(IBuildDetail build, string definitionName)
{
var project = new Project
{
DefinitionName = definitionName,
Name = build.TeamProject,
Status = build.Status.ToString(),
StartTime = build.StartTime,
FinishTime = build.FinishTime
};
return project;
}
private void AddBuiltToParentProject(BuildStatus buildStatus, string definitionName, Project project, int maxRuns)
{
var parent ###### buildStatus.Projects.First(p > p.DefinitionName ###### definitionName);
if (parent.Runs.Count < maxRuns)
{
parent.Runs.Add(project);
}
}
}
}
```
```csharp
using System;
using System.Collections.Generic;
namespace TfsCommunicator
{
public class Project
{
public Project()
{
Runs = new List<Project>();
}
public string DefinitionName { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public DateTime StartTime { get; set; }
public DateTime FinishTime { get; set; }
public List<Project> Runs { get; set; }
}
}
```
Deze informatie dan bijvoorbeeld wegschrijven naar een JSON file
```csharp
private static void Main(string[] args)
{
Console.WriteLine("TFS Build status; connecting...");
BuildCommunicator communicator = new BuildCommunicator(ConfigurationManager.AppSettings["tfsServer"]);
while (true)
{
Console.WriteLine("Getting TFS Build info for all projects...");
BuildStatus info = communicator.GetBuildInformation();
CleanBuildStatusFile();
WriteBuildStatusToFile(info);
Console.WriteLine("Written build info to buildstatus.json. [waiting...] ");
Thread.Sleep(20000);
}
}
private static void WriteBuildStatusToFile(BuildStatus info)
{
StreamWriter streamWriter = File.CreateText("buildstatus.json");
new JsonSerializer().Serialize(streamWriter, info);
streamWriter.Close();
}
private static void CleanBuildStatusFile()
{
try
{
File.Delete("buildstatus.json");
}
catch
{
}
}
```

View File

@ -1,51 +0,0 @@
+++
title = "threads"
draft = false
tags = [
"code",
"csharp",
"threads"
]
date = "2013-12-06"
+++
# Threads
### Locking en singletons
See [C#In Depth: Implementing the Singleton pattern in C#](http://csharpindepth.com/Articles/General/Singleton.aspx)
een `lock()` is heel duur om uit te voeren, daarom wordt er een null check hierrond nog eens geschreven, dat heet **double-check locking**:
```csharp
internal static ContextViewPresenter instance;
private static readonly Object syncRoot = new Object();
public static ContextViewPresenter Instance
{
get
{
if (instance ###### null)
{
lock (syncRoot)
{
if (instance ###### null)
{
instance = new ContextViewPresenter(UserEnvironmentDataProviderSingleton.Instance);
}
}
}
return instance;
}
}
```
############ Thread-local static variables ############
In java kan men `ThreadLocal<>` gebruiken om iets per thread te storen (zoals de gebruiker van een webpagina die per request van de `WebServlet` één nieuwe Thread aanmaakt). <br/><br/>
In C# kan dit ook met de attribute `[ThreadStatic]` voor een field te plaatsen.
:exclamation: Opgelet met ASP.NET - IIS heeft dan een shared threadpool geconfigureerd waar jij geen controle over hebt. Dit wil zeggen dat x threads herbruikt worden, en dus ook uw threadlocal storage.
Oplossing(en): (zie ook [hier](http://piers7.blogspot.be/2005/11/threadstatic-callcontext-and_02.html))
1. Clear waarde op einde van elke request
2. Gebruik `HttpContext` van ASP.NET zelf in plaats van `[ThreadStatic]`. (Zou probleem kunnen zijn in uw domein laag...)

View File

@ -1,250 +0,0 @@
+++
title = "utils"
draft = false
tags = [
"code",
"csharp",
"utils"
]
date = "2014-03-17"
+++
# Utils Partials
### ObjectExtensions
Waarom? Deep clone van een object maken zonder de boel te (de)-serialiseren.
Bron: https://raw.github.com/Burtsev-Alexey/net-object-deep-copy/master/ObjectExtensions.cs - thank you Alexey
```csharp
public static class ObjectExtensions
{
private static readonly MethodInfo CloneMethod = typeof (Object).GetMethod("MemberwiseClone",
BindingFlags.NonPublic | BindingFlags.Instance);
public static bool IsPrimitive(this Type type)
{
if (type ###### typeof (String)) return true;
return (type.IsValueType & type.IsPrimitive);
}
public static Object Copy(this Object originalObject)
{
return InternalCopy(originalObject, new Dictionary<Object, Object>(new ReferenceEqualityComparer()));
}
private static Object InternalCopy(Object originalObject, IDictionary<Object, Object> visited)
{
if (originalObject ###### null) return null;
var typeToReflect = originalObject.GetType();
if (IsPrimitive(typeToReflect)) return originalObject;
if (typeof (XElement).IsAssignableFrom(typeToReflect)) return new XElement(originalObject as XElement);
if (visited.ContainsKey(originalObject)) return visited[originalObject];
if (typeof (Delegate).IsAssignableFrom(typeToReflect)) return null;
var cloneObject = CloneMethod.Invoke(originalObject, null);
if (typeToReflect.IsArray)
{
var arrayType = typeToReflect.GetElementType();
if (IsPrimitive(arrayType) ###### false)
{
Array clonedArray = (Array) cloneObject;
clonedArray.ForEach(
(array, indices) =>
array.SetValue(InternalCopy(clonedArray.GetValue(indices), visited), indices));
}
}
visited.Add(originalObject, cloneObject);
CopyFields(originalObject, visited, cloneObject, typeToReflect);
RecursiveCopyBaseTypePrivateFields(originalObject, visited, cloneObject, typeToReflect);
return cloneObject;
}
private static void RecursiveCopyBaseTypePrivateFields(object originalObject,
IDictionary<object, object> visited, object cloneObject, Type typeToReflect)
{
if (typeToReflect.BaseType != null)
{
RecursiveCopyBaseTypePrivateFields(originalObject, visited, cloneObject, typeToReflect.BaseType);
CopyFields(originalObject, visited, cloneObject, typeToReflect.BaseType,
BindingFlags.Instance | BindingFlags.NonPublic, info => info.IsPrivate);
}
}
private static void CopyFields(object originalObject, IDictionary<object, object> visited, object cloneObject,
Type typeToReflect,
BindingFlags bindingFlags =
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy,
Func<FieldInfo, bool> filter = null)
{
foreach (FieldInfo fieldInfo in typeToReflect.GetFields(bindingFlags))
{
if (filter != null && filter(fieldInfo) ###### false) continue;
if (IsPrimitive(fieldInfo.FieldType)) continue;
var originalFieldValue = fieldInfo.GetValue(originalObject);
var clonedFieldValue = InternalCopy(originalFieldValue, visited);
fieldInfo.SetValue(cloneObject, clonedFieldValue);
}
}
public static T Copy<T>(this T original)
{
return (T) Copy((Object) original);
}
}
public class ReferenceEqualityComparer : EqualityComparer<Object>
{
public override bool Equals(object x, object y)
{
return ReferenceEquals(x, y);
}
public override int GetHashCode(object obj)
{
if (obj ###### null) return 0;
return obj.GetHashCode();
}
}
```
:exclamation: **Let op met XElement**; sommige API classes voorzien copy constructors die je beter gebruikt ipv via reflectie alle fields over te kopiëren. Bijgevolg if type blabla...
############ EqualsBuilder ############
```csharp
public class EqualsBuilder<T>
{
private readonly T left;
private readonly object right;
private bool areEqual = true;
public EqualsBuilder(T left, object right)
{
this.left = left;
this.right = right;
if (ReferenceEquals(left, right))
{
areEqual = true;
return;
}
if (ReferenceEquals(left, null))
{
areEqual = false;
return;
}
if (ReferenceEquals(right, null))
{
areEqual = false;
return;
}
if (left.GetType() != right.GetType())
{
areEqual = false;
return;
}
}
public EqualsBuilder<T> With<TProperty>(Expression<Func<T, TProperty>> propertyOrField)
{
if (!areEqual)
{
return this;
}
if (left ###### null || right ###### null)
{
return this;
}
var expression = propertyOrField.Body as MemberExpression;
if (expression ###### null)
{
throw new ArgumentException("Expecting Property or Field Expression of an object");
}
Func<T, TProperty> func = propertyOrField.Compile();
TProperty leftValue = func(left);
TProperty rightValue = func((T) right);
if (leftValue ###### null && rightValue ###### null)
{
areEqual &= true;
return this;
}
if (leftValue != null && rightValue ###### null)
{
areEqual &= false;
return this;
}
if (leftValue ###### null && rightValue != null)
{
areEqual &= false;
return this;
}
areEqual &= leftValue.Equals(rightValue);
return this;
}
public bool Equals()
{
return areEqual;
}
}
```
Gebruik:
```csharp
public override bool Equals(object obj)
{
return new EqualsBuilder<FlexMedischGegeven>(this, obj)
.With(x => x.Rownr)
.With(x => x.ColumnName)
.With(x => x.Value)
.With(x => x.Creator)
.Equals();
}
```
############ Mocking DateTime.Now ############
Schrijf een wrapper rond `Now` met behulp van lambda's:
```csharp
using System;
public static class SystemTime
{
private static Func<DateTime> _now;
public static Func<DateTime> Now
{
get
{
if (_now ###### null)
{
Reset();
}
return _now;
}
set { _now = value; }
}
public static void Reset()
{
Now ###### () > DateTime.Now;
}
}
```
Gebruik:
* in `[TestCleanup]` de `Reset()` method aanroepen.
* in uw test body indien gewenst `SystemTime.Now ###### () > new DateTime(2001, 1, 1);` steken.

View File

@ -1,15 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"db",
"home"
]
date = "2013-03-12"
+++
# code:db >> Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>

View File

@ -1,248 +0,0 @@
+++
title = "mssql"
draft = false
tags = [
"code",
"db",
"mssql"
]
date = "2016-05-24"
+++
# MSSQL
### clustered indexen aanpassen door ze eerst te resolven in een cursor
Onderstaand stukje code for future reference...
```sql
DECLARE @constraint NVARCHAR(MAX)
DECLARE @cmd NVARCHAR(MAX)
DECLARE @table NVARCHAR(MAX)
DECLARE FKCURSOR CURSOR FOR
select distinct name,object_name(parent_object_id) from sys.objects where object_id in
( select fk.constraint_object_id from sys.foreign_key_columns as fk
where fk.referenced_object_id =
(select object_id from sys.tables where name = 'Reference')
)
OPEN FKCURSOR
FETCH NEXT FROM FKCURSOR
INTO @constraint, @table
WHILE @@FETCH_STATUS = 0
BEGIN
SET @cmd = N'ALTER TABLE [dbo].['+@table+'] DROP CONSTRAINT ' + @constraint
EXEC sp_executeSQL @cmd;
FETCH NEXT FROM FKCURSOR
INTO @constraint, @table
END
CLOSE FKCURSOR;
DEALLOCATE FKCURSOR;
```
### constraints met auto-names verwijderen als een kolom hierop depent
Gebruik information schemes om de data hier uit te halen.
Bvb onderstaande code verwijdert de kolom 'isDefault', nadat alle constraints hierrond verwijderd zijn.
```sql
declare @cname varchar(100)
declare @query nvarchar(max)
set @cname = (
SELECT
default_constraints.name
FROM
sys.all_columns
INNER JOIN
sys.tables
ON all_columns.object_id = tables.object_id
INNER JOIN
sys.schemas
ON tables.schema_id = schemas.schema_id
INNER JOIN
sys.default_constraints
ON all_columns.default_object_id = default_constraints.object_id
WHERE
schemas.name = 'dbo'
AND tables.name = 'tblhtmltemplate'
AND all_columns.name = 'isdefault')
set @query = 'alter table tblhtmltemplate drop constraint ' + @cname
if @cname is not null begin
exec sp_executesql @query
end
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name######'tblHtmlTemplate' AND column_name 'isDefault')
BEGIN
alter table tblhtmltemplate drop column isdefault;
END;
```
### functies aanmaken om MySQL syntax te mimicken
```sql
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION ifnull
(
-- Add the parameters for the function here
@value1 datetime, @returnvalue int
)
RETURNS datetime
AS
BEGIN
return isnull(@value1, @returnvalue)
END
GO
```
Zou `IFNull` moeten mimicken, maar je kan enkel `select dbo.ifnull()` doen ipv de native syntax...
### Waar zijn de DB files op de schijf ergens geplaatst?
```sql
SELECT name, physical_name AS current_file_location
FROM sys.master_files
```
Zie ook [MSDN: MSSQL DB file locations](https://msdn.microsoft.com/en-us/library/ms143547.aspx)
### Alter databases gaan traag
1. uitvoeren met `WITH ROLLBACK IMMEDIATE;`
2. uitvoeren in `SINGLE_USER` mode (set op db niveau, dan terug naar `MULTI_USER` zetten)
### Query notifications
Service broker aan zetten: `ALTER DATABASE db_name SET ENABLE_BROKER with rollback immediate`
Hoe checken of reeds enabled is? `select name, database_id, service_broker_guid from sys.databases where is_broker_enabled = 1;`
:exclamation: service broker GUIDs zijn dezelfde indien DB gekopiëerd is, bijgevolg krijg je deze fout indien je `ENABLE_BROKER` tracht uit te voeren op zo'n kopie:
```
cannot be enabled because there is already an enabled Service Broker with the same ID
```
Fix: ([bron](http://www.mssqltips.com/sqlservertip/2789/sql-server-service-broker-error-database-cannot-be-enabled/)) maak een nieuwe broker GUID aan met `SET NEW_BROKER`.
##### In combinatie met NHibernate Syscache2
Zie
* [http:*developer.empinia.org/svn/empinia/vendor/bin/nhibernate/trunk/Doc/html/caches.html](http:*developer.empinia.org/svn/empinia/vendor/bin/nhibernate/trunk/Doc/html/caches.html)
* [http:*tamingcode.com/2013/07/01/cacheable-queries-pitfalls/](http:*tamingcode.com/2013/07/01/cacheable-queries-pitfalls/)
#### Hoe weet ik nu of notification works?
We moeten zien of de **Broker:Conversation** berichten correct op- en afgestuurd worden. Dit kan je best nagaan in SQL Server Profiler:
<img style='float: left; width: nolink |px;' src='/img//code/db/sqlprofiling.png'>
Volgende dingen zouden moeten gebeuren:
1. STARTED_OUTBOUND bericht (conversation)
2. CONVERSING bericht (conversation) van .Net SqlClient applicationName
3. QN:Subscription van .Net SqlClient applicationName
4. QN:Dynamics event subclass Clock run om te zien of het event gequeued is.
#### Pitfalls en errors
##### System.InvalidOperationException: When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance.
[Bron](http://richarddingwall.name/2009/10/09/nhibernate-caches-syscache2-dont-forget-to-call-sqldependency-start/)
`SqlDependency.Start(conString)` aanroepen vóór de setup van bvb de NHibernate session factory. Dit moet je zelf doen, ook al gebruik je SysCache2 met regions.
:exclamation: altijd eerst Stop aanroepen!
##### Cannot execute as the database principal because the principal "dbo" does not exist
In SQL Server profiler zichtbaar bij broker events - dit komt vanwege te weinig rechten.
`use [DBNAME] EXEC sp_changedbowner 'sa`' lost dit probleem op (zie profiling)
### MSSQL specifieke syntax
##### Batch processing
`GO`:
The GO command isn't a Transact-SQL statement, but a special command recognized by several MS utilities including SQL Server Management Studio code editor.
The GO command is used to group SQL commands into batches which are sent to the server together. The commands included in the batch, that is, the set of commands since the last GO command or the start of the session, must be logically consistent. For example, you can't define a variable in one batch and then use it in another since the scope of the variable is limited to the batch in which it's defined.
Zie ook [http:*msdn.microsoft.com/en-us/library/ms188037.aspx](http:*msdn.microsoft.com/en-us/library/ms188037.aspx).
:exclamation: Dit is blijkbaar ook wijzigbaar naar een karakterset naar keuze in Management studio options:
<img style='float: left; width: nolink |px;' src='/img//code/db/go_option_mssql.png'>
##### Rename columns
```sql
EXEC sp_RENAME 'TableName.OldColumnName' , 'NewColumnName', 'COLUMN'
```
##### werken met datums
`GETDATE()` is een now timestamp (in MySQL is dit `CURDATE()`. Records selecteren met een bepaalde timestamp ("vanaf"):
```sql
select * from table where datecolumn >= Convert(datetime, '2014-09-11');
```
In Oracle is dit bijvoorbeeld `TO_DATE('26/JAN/2011','dd/mon/yyyy')` in plaats van `Convert()` - in MySQL kan dit rechtstreeks in een bepaald formaat: `WHERE start_date >'2012-11-18';`
### Monitoring
##### ADO .NET Connection pool monitoring
Mogelijk met **Performance monitor** in Win32 (Run -> `perfmon`).
Step-by-step uitleg: (oude versie) [Monitoring DB connections using performance counters](http://www.c-sharpcorner.com/uploadfile/CMouli/monitoring-database-connections-using-performance-counters/)
[Mogelijke counters - MSDN](http://msdn.microsoft.com/en-us/library/ms254503.aspx):
1. NumberOfActiveConnections
2. NumberOfFreeConnections
3. NumberOfPooledConnections
4. ...
<img style='float: left;' src='/img//code/db/addcounters.png |'>
Alles ivm DB connecties in .NET is ook mogelijk te bekijken met de [ANTS Performance profiler](http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/).
##### Aantal momenteel actieve threads bezien
```sql
SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NumberOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
```

View File

@ -1,69 +0,0 @@
+++
title = "mysql"
draft = false
tags = [
"code",
"db",
"mysql"
]
date = "2014-09-11"
+++
# MySQL
### DB Syncing
Mogelijk met verschillende tools, over verschillende DB types heen. Bvb om schema's te syncen tussen MSSQL DBs en MySQL DBs, etc etc. Enkele voorbeeldtools:
* MSSQL: AdeptSQL Diff [http:*www.adeptsql.com/](http:*www.adeptsql.com/)
* MYSQL: SQLyog [https:*www.webyog.com/](https:*www.webyog.com/)
Maakt een SQL DDL aan met het verschil tussen database schema's naar keuze.
<img style='float: left; width: nolink |px;' src='/img//code/db/powertools.png'>
### ADO.NET connection
##### Pooling
Enabled by default, zie [Connector .NET Connection options](http://dev.mysql.com/doc/connector-net/en/connector-net-connection-options.html); voorbeeld:
`Server######server; Port3306; Database######db; Uidroot; Pwd######root; Poolingtrue;`
Dingen als maximum pool size, initial size etc ook instelbaar (zie link)
### Monitoring
##### configuratie properties via SQL uitlezen
Bijvoorbeeld **max connections**: `show variables like "max_connections";`
Allemaal aanpasbaar via `set global max_connections = 200;` (root rechten required)
##### Aantal momenteel actieve threads bezien
`SHOW GLOBAL STATUS where variable_name like '%Threads%';` geeft:
```
Variable_name value
----------------------------
Delayed_insert_threads 0
Slow_launch_threads 0
Threads_cached 8
Threads_connected 56
Threads_created 138
Threads_running 2
```
##### Huidige connecties killen
Zie [Mass killing of MySQL connections](http://www.mysqlperformanceblog.com/2009/05/21/mass-killing-of-mysql-connections/)
Gaat **niet rechtstreeks**; eerst een file maken met `kill` commands en die dan sourcen in een mysql command line:
`select concat('KILL ', id, ';') from information_schema.processlist where host like '%myhost%' into outfile 'c:<br/>a.txt';`
:exclamation: Forward slashen in Windows gebruiken, of dubbele backslash.
Stap 2: `source c:/a.txt` - géén single quotes hierrond (anders error code 22) en geen single baskslash (anders error code 2, = file not found)
MySQL command line opstarten: ga naar bin dir van installed server, en execute `mysql --user###### --pass`.

View File

@ -1,59 +0,0 @@
+++
title = "oledb"
draft = false
tags = [
"code",
"db",
"oledb"
]
date = "2014-02-27"
+++
# Oledb
## Named parameter problem
Blijkbaar werkt `OleDbCommand` nooit met named parameters, maar is de **volgorde van toevoegen** zeer belangrijk. In De query zelf worden '?' tekens gebruikt om een parameter aan te duiden. Dit is zeer vervelend, en maakt het abstraheren van de DB laag moeilijk - andere DB providers staan bijvoorbeeld `@parameter` toe, waarbij de naam wel uitmaakt. Hoe lossen we dat op?
#### Convert named parameters into positional ones
Hocus pocus: (zie ook http://stackoverflow.com/questions/2407685/oledbparameters-and-parameter-names etc)
```csharp
public static OleDbCommand ConvertNamedParametersToPositionalParameters(OleDbCommand command)
{
// OleDb does NOT use named parameters, but we want them! (uses '?')
var newParameters = new List<OleDbParameter>();
command.CommandText ###### Regex.Replace(command.CommandText, "(@<br/><br/>w*)", match >
{
var parameter ###### command.Parameters.OfType<OleDbParameter>().FirstOrDefault(a > a.ParameterName ###### match.Groups[1].Value);
if (parameter != null)
{
var parameterIndex = newParameters.Count;
var newParameter = command.CreateParameter();
newParameter.OleDbType = parameter.OleDbType;
newParameter.ParameterName = "param_" + match + "_" + parameterIndex.ToString();
newParameter.Value = parameter.Value;
newParameters.Add(newParameter);
}
return "?";
});
command.Parameters.Clear();
command.Parameters.AddRange(newParameters.ToArray());
return command;
}
```
######= Gewenste Resultaat ######=
Maakt het mogelijk om dit te doen:
* `SELECT * FROM TABLE WHERE column ###### @name1 AND column2 @name2`
* voeg aan command `new OleDbParameter("@name1", value)` toe
* wordt automagically vervangen door vorige method (kan als extension gebruikt worden)
:exclamation: In [code/db/sqlite]({{< relref "wiki/code/db/sqlite.md" >}}) wordt dit by default ondersteund...

View File

@ -1,48 +0,0 @@
+++
title = "postgresql"
draft = false
tags = [
"code",
"db",
"postgresql"
]
date = "2013-08-09"
+++
# PostgreSQL
Documentatie: http://www.postgresql.org/docs/9.1/static/view-pg-locks.html
pgAdmin: http://www.pgadmin.org/
:exclamation: Heeft géén commit & rollbacks, alles wat uitgevoerd wordt kan niet teruggedraaid worden!
#### Metadata tabellen bekijken
##### Alle views van een bepaald schema
`SELECT count(*) FROM information_schema.views where table_schema = 'public';`, vergeet niet dat `table_schema` `pg_catalog` is voor de metadata tabellen die altijd bestaan in postgres.
##### Alle kolommen
Voorbeeld om alle floats te selecteren (kan afrondingsfouten bevatten, gebruik `numeric` in de plaats):
```sql
SELECT * FROM information_schema.columns where
(data_type = 'real' or
data_type like 'double%')
and table_schema = 'public'
and table_name not like 'view_%'
and table_name not like 'lookup_%';
```
#### Dump van DB nemen
Gebruik hiervoor `pgdump` in bin folder van postgres install dir:
```
C:<br/>Program Files<br/>PostgreSQL<br/>9.1<br/>bin>pg_dump --host######10.16.42.35 --port5432 --username######postgres --schemapublic --format=c --schema-only repository.db > postgresdump_20111020.dmp
```
Verklaring:
* `--format`: c (custom), d (directory), t (tar), p (plain text)
* `--schema`: dump enkel dit stuk

View File

@ -1,213 +0,0 @@
+++
title = "sql"
draft = false
tags = [
"code",
"db",
"sql"
]
date = "2013-09-03"
+++
# code:db >> Sql
## Stored procedures
### Oproepen
Zie http://stackoverflow.com/questions/3991721/run-stored-procedure-in-sql-developer
Gegeven: een procedure `GETPERMISSIONSALL` als volgt gedeclareerd:
```sql
create or replace
PROCEDURE "GETPERMISSIONALL" ( v_actCreator in VARCHAR2, v_repGuid in VARCHAR2, v_userid INT, v_retHasPermission out SMALLINT)
```
De laatste parameter is de return waarde (kunnen meerdere dingen zijn dus). Hoe roep ik nu zoiets aan?
#### In SQL Developer
Definiëer eerst uw variabelen, om ze daarna eventueel af te drukken -
```sql
SET serveroutput on;
DECLARE
v_actCreator VARCHAR2(100);
v_repGuid VARCHAR2(100);
v_userid int;
Output smallint;
BEGIN
/* Assign values to IN parameters */
v_actCreator := '19980121164845.106.1 7';
v_repGuid := '2466B39EFDA94D5E9249D252FF25C4D6';
v_userid := 540;
/* Call procedure within package, identifying schema if necessary */
GETPERMISSIONALL(v_actCreator, v_repGuid, v_userid, Output);
/* Display OUT parameters */
dbms_output.put_line('Output: ' || Output);
END;
/
-- Display OUT parameters
-- print :Output;
```
##### Werken met REF CURSOR
Probleemstelling:
1. Uw procedure retourneert een `REF CURSOR` als IN en OUT variabele
2. Je wil over deze gaan loopen en ergens een resultaat afdrukken of vergelijken
3. openen van een `REF CURSOR` gaat niet.
Gebruik in een `LOOP` dadelijk `FETCH` `INTO`:
```sql
SET serveroutput ON;
DECLARE
P_USERID NUMBER;
MY_P_CURSOR C2MV5_DEV.PKG_WFSEC.Validation_Send_Item_Cursor;
cursor_element C2MV5_DEV.PKG_WFSEC.WFSEC_Send_Item_T;
BEGIN
P_USERID := 11;
PKG_WFSEC.FETCHSENDITEMS(
P_USERID => P_USERID,
P_CURSOR => MY_P_CURSOR
);
WHILE TRUE LOOP
FETCH MY_P_CURSOR INTO cursor_element;
EXIT WHEN MY_P_CURSOR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(cursor_element.executingdoctorname);
END LOOP;
END;
```
Merk op dat hier bijvoorbeeld `cursor_element` van een bepaald type is dat in een package gedefinieerd is, dat de cursor ook retourneert (`TYPE Validation_Send_Item_Cursor IS REF CURSOR RETURN WFSEC_Send_Item_T;`)
#### In C#
```csharp
public object QueryProcedure(string procedure, IDictionary<string, object> parameters, string outputParameter)
{
var command = new OleDbCommand(procedure);
foreach (var item in parameters)
{
command.Parameters.AddWithValue(item.Key, item.Value);
}
var output = command.Parameters.AddWithValue(outputParameter, 0);
output.Direction = ParameterDirection.Output;
QueryProcedure(command);
return output.Value;
}
```
### Unit testen
#### Met SQL Developer
zie [Oracle docs: Unit Testing in SQL Developer 3+](http://docs.oracle.com/cd/E15846_01/doc.21/e15222/unit_testing.htm)
:exclamation: Read this first: [Unit Testing PL/SQL In SQL Developer problems](http://www.fuzzy.cz/en/articles/unit-testing-plsql-code-in-sql-developer-problems/) - toch niet zo geweldig? <br/><br/>
Kan blijkbaar al niet apart gerund worden (mee in de build? een of nadere bat file van SQLDev zelf?)
<img style='float: left;' src='/img//code/db/unittest_sqldev.png |'>
Als uw stored procedure data wijzigt kan je in de startup en teardown process stappen toevoegen: "table or row copy", om die daarna terug te zetten.
##### Test gerelateerde tabellen opkuisen
Als je database-onafhankelijk testen wil draaien, kan je deze ook exporteren en importeren, en daarna runnen. Een import verwijdert echter niet oude niet-relevante unit tests, dus opkuisen van de UT repository is wel vereist. Hier is een `SQL` stored proc. om de boel te automatiseren:
```sql
SET serveroutput ON;
DECLARE
queryStr VARCHAR2(100);
tableName VARCHAR2(900);
cursor tableCursor is SELECT table_name FROM dba_tables where owner ='user' and table_name like 'UT_TEST_%' or table_name like 'UT_SUITE_%';
BEGIN
dbms_output.enable(10000);
DBMS_OUTPUT.PUT_LINE('Cleaning unit test tables');
open tableCursor;
fetch tableCursor into tableName;
WHILE (tableCursor%FOUND) LOOP
queryStr := 'delete from ' ||tableName;
execute immediate queryStr;
--DBMS_OUTPUT.PUT_LINE(queryStr);
fetch tableCursor into tableName;
END LOOP;
close tableCursor;
commit;
DBMS_OUTPUT.PUT_LINE('SUCCESS - all cleaned!');
END;
/
```
Dit kan je runnen met `sqlplus` op de volgende manier:
```
sqlplus user/pass@db @"fullpath_to_filename.sql"
```
:exclamation: Let op met spaties in filename, gebruik daarom dubbele quotes hierboven.
##### Command-line testen runnen
```
ututil -run -suite -name [name] -repo [repo] -db [db] -log 3
```
Uw repository naam is dezelfde als de DB naam als je Tools > Unit Test > Create/Update Repository... gekozen hebt via SQL Developer.
:exclamation: `ututil` kan de db connectie namen **niet resolven bij TNS** - Gebruik **Connection Identifier** (copypaste desnoods van `tnsnames.ora`)<br/><br/>
Fout die je anders krijgt:
```
D:<br/>oracle<br/>sqldeveloper<br/>sqldeveloper<br/>bin>ututil -run -test -name GETPERMISSIONALL -repo CHCDEV -db CHCTEST -log 3
SEVERE oracle.jdeveloper.db.ConnectionException: Could not connect to database CHCTEST. The error encountered was: Ongeldige verbindingsgegevens opgeg
even.
Controleer de notatie van de URL voor de opgegeven driver.
oracle.jdeveloper.db.DatabaseConnections.getUniqueConnection(DatabaseConnections.java:514)
SEVERE null - oracle.dbtools.unit_test.utils.UtUtils.getRunnerConnection(UtUtils.java:141)
Unable to run test
```
##### Integratie met de build: C#
Een `SqlDeveloperTest` klasse die het volgende doet:
1. voer `sqlplus` uit met bovenstaande cleanup script dat alle repository tabellen cleart
2. voer `ututil` uit met `-imp -repo [repo] -file [xmlfile]`
3. voer `ututil` uit met `-run` zoals boven aangegeven.
De eigenlijke unit testen leven dan in uw source control omgeving zoals `TFS`, in die ene xml file. Op die manier kan je branchen en zo zonder dat die testen vasthangen aan je DB schema. Joepie!
## Problemen
#### NOT IN retourneert geen enkele resultaten ??
voorbeeld:
```sql
select * from sch_vac.VAC_TAKEN
where ikl_id is not null
and ikl_id not in (select iklnummer from VAC_WERFRES_KANDIDATEN)
```
> There are serious problems with subqueries that may return NULL values. It is a good idea to discourage the use of the NOT IN clause (which invokes a subquery) and to prefer **NOT EXISTS** (which invokes a correlated subquery), since the query returns no rows if any rows returned by the subquery contain null values.
Oplossing is dus:
```sql
select * from vac_taken taak where ikl_id is not null
and not exists (select 1 from vac_werfres_kandidaten where iklnummer = taak.ikl_id)
```

View File

@ -1,249 +0,0 @@
+++
title = "sqlite"
draft = false
tags = [
"code",
"db",
"sqlite"
]
date = "2015-07-17"
+++
# SQLite
### DDLs copypasten van Oracle
Bijvoorbeeld de gegenereerde versie (SQL tab) van Oracle SQL Developer overnemen gaat niet zomaar.
Er zijn enkele verschillen:
1. `NOT NULL ENABLE` wegdoen. `NOT NULL` maakt niets uit aangezien het in-memory is om te testen!
2. `USING INDEX` blabla na de `PRIMARY KEY` statements zijn ook allemaal niet nodig (`STORAGE` etc)
3. speciale defaults of syscalls zoals `sys_guid()` bestaan niet.
4. definities van groottes: wegdoen van `BYTE`: `VARCHAR2(26)` dus.
5. opletten met datums: zie onder.
6. Namespace mag ook weg bij `CREATE TABLE "SPACE"."NAME" (`
### Connection strings
Zie http://www.connectionstrings.com/sqlite/
##### File based
```
Data Source######c:<br/>mydb.db;Version3;
```
##### In-memory
```
Data Source######:memory:;Version3;New=True;
```
Conventie `Data Source=` notatie gehanteerd door [http:*www.connectionstrings.com/sqlite/](http:*www.connectionstrings.com/sqlite/)
Andere notatie
```
FullUri######file::memory:?cacheshared
```
Notatie gehanteerd door [https:*www.sqlite.org/inmemorydb.html](https:*www.sqlite.org/inmemorydb.html)
Versie en New hoeft blijkbaar niet (?)
:exclamation: Elke keer als je een connectie opendoet gaat SQLite de inmemory DB state restoren naar default (dus leeg). Als je dus bvb;
1. connectie open
2. `CREATE TABLE;` brol uitvoeren
3. connectie sluiten
4. roep andere method aan
1. connectie open
1. `SELECT * FROM TABLE;` brol uitvoeren
BOEM no such table...
Zie ook [SQLite in memory create table does not work](http://stackoverflow.com/questions/17477246/sqlite-in-memory-database-create-table-does-not-work).
:exclamation: Hou dus 1x een connectie open voor unit testen bij een `[SetUp]` en geef referenties door.
##### Extra opties meegeven via de connection string
Je kan `PRAGMA` parameters zoals [deze](http://www.sqlite.org/pragma.html#pragma_locking_mode) meegeven.
### Integreren met C#
#### DB Connectie
Gebruik http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki (package `System.data.SQLite (x86/x64)`)
Voor `OleDb` C# code, is er voor elke klasse een equivalent in de `SQLite` namespace, bijvoorbeeld:
```csharp
private SQLiteConnection SqLiteDbConnection()
{
return new SQLiteConnection()
{
ConnectionString ###### "Data Sourcemydb.s3db;",
Flags = SQLiteConnectionFlags.LogAll
};
}
public void SetupDb()
{
using (var connection = SqLiteDbConnection())
{
connection.Open();
var transaction = connection.BeginTransaction();
var sqLiteCommand = new SQLiteCommand()
{
Connection = (SQLiteConnection) connection,
CommandType = CommandType.Text,
CommandText = GetSchemaCreateSql()
};
sqLiteCommand.ExecuteNonQuery();
transaction.Commit();
}
}
```
#### Builden op x86/x64 systemen
Afhankelijk van welke package manager je gebruikt (NuGet bvb.) kan een `SQLite.interop.dll` in submapjes `x86` en `x64` geplaatst worden (Copy always als content). Lokaal werkt dit, maar op de build pc (die bijvoorbeeld enkel 32-bit is) niet, omdat de DLL op dezelfde plaats als de executable verwacht wordt. Hier zijn een paar mogelijke oplossingen voor:
1. Gebruik enkel de 32bit versie. (er is zo'n specifieke package voor)
2. "Hint" de DLL loader om de juiste te gebruiken
```csharp
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet ###### System.Runtime.InteropServices.CharSet.Unicode, SetLastError true)]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
```
```csharp
[STAThread]
static void Main()
{
int wsize = IntPtr.Size;
string libdir ###### (wsize 4)?"x86":"x64";
string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
SetDllDirectory(System.IO.Path.Combine(appPath, libdir));
// ...
}
```
Zie ook [http:*stackoverflow.com/questions/13028069/unable-to-load-dll-sqlite-interop-dll](http:*stackoverflow.com/questions/13028069/unable-to-load-dll-sqlite-interop-dll)
#### .NET dates en SQLite dates
Als je een `DATE` kolom hebt, en een SQL zoals gewoon `select * from blah;` uitvoert, kan je de volgende fout krijgen:
```
String was not recognized as a valid DateTime
```
Dit komt doordat SQLite dynamisch getypeerd is en voor hem een date hetzelfde als een char is, gebruik daarvoor de `date()` functie om zelf te parsen! Beetje vervelend in de queries...
Een andere mogelijkheid is `DateTimeFormat=Ticks` in de connection string meegeven.
#### Creating integration tests, using Record objects
Maak objecten die extenden van `DatabaseInsertable`:
```csharp
public abstract class DatabaseInsertable
{
protected abstract string GetTable();
public override string ToString()
{
var fieldDict = FieldDictionary();
var fields = "(" + string.Join(",", fieldDict.Keys) + ")";
var values = "(" + string.Join(",", fieldDict.Values) + ")";
return "insert into " + GetTable() + fields + " values " + values;
}
public void Save()
{
DbConnection.Instance.CreateCommand(ToString()).ExecuteNonQuery();
}
private Dictionary<string, string> FieldDictionary()
{
var dictionary = new Dictionary<string, string>();
foreach (var info in this.GetType().GetFields())
{
if (info.GetValue(this) != null)
{
dictionary.Add(info.Name, "'" + info.GetValue(this).ToString() + "'");
}
}
return dictionary;
}
}
```
Zoals bijvoorbeeld
```csharp
internal class UnitRecord : DatabaseInsertable
{
public string creator;
public string guid;
protected override string GetTable()
{
return "UNIT";
}
}
```
Gebruik:
```csharp
new UnitRecord() { creator ###### "bla"; guid "lala"; }.Save(); // done!
// execute your SUT stuff here
```
`DbConnection` gebruikt dan de SQLite versie om een "unit" record aan te maken in de DB. Merk op dat de properties 100% moeten overeenkomen.
Het enige speciale wat in `IntegrationTestCase` gedefiniëerd is, is de "gewone" `OleDbConnection` vervangen door de SQLite verie:
```csharp
public abstract class IntegrationTestCase
{
protected SqLitedbConnection connection;
[TestInitialize]
public void CleanDb()
{
this.connection = new SqLitedbConnection();
DbConnection.Instance = connection; // instead of OleDbConnection, lazyloaded singleton getter property.
}
}
```
Omdat Ole en SQLite soms andere interfaces hebben moeten we er zelf een anticorruptie laag (de IConnection interface) tussen zetten:
```csharp
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
public interface IdbConnection
{
object QueryProcedure(string procedure, IDictionary<string, object> parameters, string outputParameter);
DbParameter CreateParameter(string field, object value);
DbCommand CreateCommand(string query);
DataSet Query(DbCommand command);
DataSet Query(string query);
}
```
Het verschil is altijd een `SQLiteCommand` in plaats van een `OleDbCommand` aanmaken. Er zijn soms ook subtiele verschillen in het aanmaken en doorgeven van de parameters.

View File

@ -1,45 +0,0 @@
+++
title = "dev"
draft = false
tags = [
"code",
"dev"
]
date = "2013-03-12"
+++
# code >> Dev
## Tools etc
Notepad++ **JSON Formatter**:
`JSONViewer` voor notepad++: http://sourceforge.net/projects/nppjsonviewer/ - doet:
1. json viewer treeview geselecteerde json
2. format json (heel handig voor `POST` body gepaste hierin)
## Links
#### Mocking tools
* https://gomockingbird.com/ (niet gratis, van Jan zijn werkgroepje)
* http://balsamiq.com/products/mockups (gratis maar om de 5 minuten een dialog wegklikken)
* http://www.mockflow.com/
#### Algemene development tools
##### Tracking
* https://www.pivotaltracker.com/ - simple, collaborative, single-view project tracking/management
* http://leankitkanban.com/ - online Kanban tracking (betalend)
#### Tech blogs
* http://www.dzone.com/links/index.html
Voor **javascript**: zie [Javascript home page]({{< relref "wiki/code/javascript/index.md" >}})
#### Designer blogs
* http://www.smashingmagazine.com/
* http://www.alistapart.com/
* http://css-tricks.com/

View File

@ -1,305 +0,0 @@
+++
title = "dynamiclangs"
draft = false
tags = [
"code",
"dynamiclangs"
]
date = "2013-03-12"
+++
# Dynamic Languages: Constructs vergelijken
Deze pagina vergelijkt verschillende dynamische talen in een poging om een overzicht te maken tussen de alsmaar groeiende lijst. De meest gebruikte features van zulke talen worden hieronder opgelijst.
## Het verschil tussen MOPs en Prototypal inheritance
:exclamation: Javascript heeft géén **Meta Object Protocol** (MOP) dat de taal dynamisch maakt, maar bouwt verder op prototypes. Dat wil zeggen dat het klassieke inheritance systeem niet bestaat in Javascript, maar wel nagebootst kan worden door objecten te laten afleiden van objecten. De vergelijkingstabellen hieronder tonen hoe Javascript zich kan *gedragen* als een klassieke OO taal, dat wil niet automatisch zeggen dat dit de beste manier is om JS te gebruiken!
De volgende dynamische talen beschikken wel over een MOP:
1. Groovy
2. Python
3. Ruby
4. Smalltalk dialecten
5. LISP dialecten (bvb. Runtime MOPs via `CLOS`)
6. Perl 6
7. OpenC++ (bvb. Compiletime MOPs door C++ te parsen en analyseren)
[Ruby VS Javascript metaprogramming](http://fingernailsinoatmeal.com/post/292301859/metaprogramming-ruby-vs-javascript):
> The most interesting thing about the Javascript example is that it is exactly the same as the example of adding a dynamic method to a class. There is no difference because Javascript functions **are** closures. The ubiquity of closures in Javascript is extremely powerful and, makes metaprogramming very easy.
Voor meer informatie, zie wiki entry over **[Javascript inheritance]({{< relref "wiki/code/javascript/inheritance.md" >}})**
# Vergelijkingstabellen
## Dynamica van de taal: Metaprogramming
### Methods toevoegen
#### Op klasse niveau
^ Javascript ^ Groovy ^
| ```javascriptString.prototype.isTrue = function() {
return this ###### "true";
}``` | ```javaString.metaClass.isTrue = {
delegate ###### "true"
}``` |
Javascript bevat enkele *common pitfalls* hierrond, zie [JS Inheritance]({{< relref "wiki/code/javascript/inheritance.md" >}}).
Groovy staat ook toe om *constructors* toe te voegen op deze manier. <br/><br/>
Methods "lenen" gaat ook met de **&.** operator in Groovy om de pointer naar een method vast te krijgen. In JS gewoon de "key" (methodnaam) als referentie gebruiken.
######= Op instance niveau ######=
^ Javascript ^ Groovy ^
| ```javascript"someString".isTrue = function() {
return this ###### "true";
}``` | ```java"someString".metaClass.isTrue = {
delegate ###### "true"
}``` |
Voor beide talen op exact dezelfde manier dus, op een *instance* zelf.((Groovy 1.6+ heeft dit standaard, anders uw metaClass nog correct aanpassen! Zie http://groovy.codehaus.org/Per-Instance+MetaClass ))
Als Groovy problemen geeft, kan het zijn doordat `ExpandoMetaClass` niet geconfigureerd staat voor *inheritance*:
```java
ExpandoMetaClass.enableGlobally()
```
############ Methods catchen ############
Met "catchen" wordt "*decoreren*" bedoeld. van alle calls op van method namen die niet bestaan en doe ermee wat je wilt.
^ Javascript ^ Groovy ^
| **niet** mogelijk | ```javaSomeClass.metaClass.methodMissing = { name, arguments ->
switch(name) {
case "bla": return "blaing eh"
break;
}
}
assert "blaing eh" ###### new SomeClass().bla()
``` |
Groovy kan ook **alle methods** opvangen, ook de bestaande, door de MOP hook `invokeMethod`, `get/setProperty`, `propertyMissing` etc te overriden - op `Object` of `metaClass` niveau, op deze manier:
```java
class SomeClass {
def invokeMethod(String name, args) {
switch(name) {
case "bla": return "blaing eh"
break;
default:
// delegate.invokeMethod name, arguments makes an infinite loop! it's a tarp!
delegate.metaClass.getMetaMethod(name, arguments).invoke(delegate, arguments)
}
}
}```
En ja, dat werkt [Ook met static methods in Groovy](http://groovy.codehaus.org/ExpandoMetaClass+-+Overriding+static+invokeMethod)!
:exclamation: Rhino en SpiderMonkey implementaties van JavaScript (Firefox' JS parser bijvoorbeeld) ondersteunen wel een magic missing method, genaamd `__noSuchMethod__` en een hele hoop andere nifty dingen zoals `__defineGetter__` en `__lookupSetter__`. Meer informatie in [deze blogpost](http://offthelip.org/?p=101) te vinden. Voorbeeld in Firefox+Firebug:
```javascript
SomeClass.prototype.__noSuchMethod__ = function(name, arguments) {
console.log("calling method " + name + " with arguments " + arguments);
if(name ###### "bla") {
return "blaing eh";
}
}
"blaing eh" ###### new SomeClass().bla() // true
```
Merk op dat in Groovy zoiets niet bestaat, we overriden **ender welke methodCall**, daarom dat in de `default` van het `switch` statement nog altijd een delegate invoke moet gebeuren!
############ Properties toevoegen ############
^ Javascript ^ Groovy ^
| ```javascriptvar gapingHoleInTheGalaxy = function() {}
gapingHoleInTheGalaxy.theSun = "extraHot"; // method 1
gapingHoleInTheGalaxy['theSun'] = "extraHot"; // method 2
gapingHoleInTheGalaxy.explode = function() {
console.log("Explosion!")
}``` | ```javadef gapingHoleInTheGalaxy = new Expando()
gapingHoleInTheGalaxy.theSun = "extraHot" // method 1
gapingHoleInTheGalaxy['theSun'] = "extraHot" // method 2
gapingHoleInTheGalaxy.explode = {
println "Explosion!"
}``` |
:exclamation: Groovy heeft een speciale klasse `Expando` die dynamisch toelaat om eender wat toe te voegen, zowel *closures* als *properties* op dezelfde manier. Enige nadeel: deze code kan niet gemengd worden met Java als byte code. Bij gewone klassen kan dit niet en moet dit via de `metaClass` gaan. Bij Javascript werkt dit omdat op eender welk moment het prototype van een object veranderd kan worden en er geen onderscheid is tussen closures en functions.
Merk op dat hier de quotes nodig zijn om via de `[]` operator closures aan iets te hangen.
Het is wél mogelijk om properties via `metaClass` toe te voegen door de methodnaam de javaBean specificatie te laten volgen, bvb `metaClass.getBrol ###### {}` zodat men `def x inst.brol` kan uitvoeren.
############ Itereren over methods ############
^ Javascript ^ Groovy ^
| ```javascriptfor(propertyName in someInstance) {
var propertyValue = someInstance[propertyName]
if(typeof propertyValue ###### "function") {
var retVal = eval("someInstance." + propertyName + "(args)"); // method 1
retVal = propertyValue(args) // method 2
} else {
console.log(propertyName + " property with value " + propertyValue);
}
}``` | ```javaString.metaClass.methods.each {
def methodName = it.name // now what? methods are on class level
def retVal = someInstanceOfString."${methodName}"
}
someInstanceOfString.properties.each {
println "${it.key} property with value ${it.value}"
}``` |
############= Variable arguments ############=
############ varargs core ############
^ Javascript ^ Groovy ^
| ```javascriptfunction bla() {
for(arg in arguments) { console.log(arg); }
}
bla(1, 2, 3);
``` | ```javadef bla(Object[] args) { // method 1
def bla(Object... args) { // classic Java 1.5 method 2
args.each{ println it }
}
bla(1, 2, 3);
}``` |
Een map meegeven gaat altijd natuurlijk, om argumenten expressiever te maken, zoals configuratie: (Groovy vb.)
```java
def bla(Map args) {
println args.stuff
}
bla(stuff: "wow", c: 3)
```
############ Argument spreading ############
^ Javascript ^ Groovy ^
| ```javascriptfunction bla(a, b) {
return a + b + 2;
}
var args = [1, 2];
bla(1, 2) ###### bla.apply(this, args) // 5
``` | ```javadef bla(a, b) {
a + b + 2
}
def args = [1, 2]
bla(1, 2) ###### bla(*args)
``` |
############ Fixed arguments ############
^ Javascript ^ Groovy ^
| ```javascriptfunction bla(a, b, c) {
if(!c) var c = 0;
console.log("a: " + a + ", b: " + b + ", c: " + c);
}
bla(1, 2) // 1, 2, 0
bla(1, 2, 3); // 1, 2, 3
``` | ```javadef bla(a, b, c = 0) {
println "a: $a, b: $b, c: $c"
}
def blaWow = bla.curry(1)
blaWow(2) // 5, 2, 0
bla(1, 2) // 1, 2, 0
bla(1, 2, 3) // 1, 2, 3
``` |
Merk op dat bij JS er gecontroleerd moet worden of een variabele daadwerkelijk is ingevuld of niet. `curry` is niet standaard aanwezig maar kan eenvoudig geïmplementeerd worden, zoals deze snippet van het *Prototype* framework:
```javascript
function curry() {
if (!arguments.length) return this;
var __method ###### this, args slice.call(arguments, 0);
return function() {
var a = merge(args, arguments);
return __method.apply(this, a);
}
}
```
Dit roept in essentie de eigenlijke method op (met `apply`) met een aantal parameters predefined.
############= String interpolatie ############=
^ Javascript ^ Groovy ^
| **niet** mogelijk | ```javadef dinges = "mijn dingetje"
"$dinges is a dong" ###### "mijn dingetje is a dong"
``` |
JS extentie om dit mogelijk te maken: zie [Prototype JS interpolate](http://www.prototypejs.org/api/string/interpolate), bvb:<br/><br/>
`"#{dinges} is a dong".interpolate({dinges: "mijn dingetje"}) ###### "mijn dingetje is a dong"`<br/><br/>
Merk op dat dit eenvoudig een regex door de string laat lopen.
Merk op dat bij Groovy dit zeer krachtig is en hele expressies in strings kunnen gegoten worden zoals `"bla ${this.method} jong"`. Ook methods aanroepen zoals this."${methodName}" werkt.
############ Template parsing ############
Grotere brokken tekst interpoleren werkt via *templates*. In Prototype JS is er een `Template` klasse [aanwezig](http:*www.prototypejs.org/api/template), in Groovy zit een uitgebreide en uitbreidbare [template engine](http:*groovy.codehaus.org/Groovy+Templates):
^ Javascript ^ Groovy ^
| ```javascriptvar myTemplate = new Template('The TV show #{title} was created by #{author}.');
var show = {title: 'The Simpsons', author: 'Matt Groening', network: 'FOX' };
myTemplate.evaluate(show);``` | ```javadef string = "The TV Show ${title} was created by ${author}."
def myTemplate = new groovy.text.SimpleTemplateEngine().createTemplate(string)
def show = [ title: "The Simpsons", author: "Matt Groening", network: "FOX" ]
myTemplate.make(show).toString()
``` |
############= Evaluatie van expressies ############=
^ Javascript ^ Groovy ^
|```javascriptvar y = 20;
var X = function() {
this.y = 10;
this.boem = function() {
console.log(eval("10 * this.y")); // 100, without "this" = 200 (window scope)
}
}
new X().boem()``` | ```javaclass X {
def y = 20
def boem = {
def y = 10
println Eval.x(y, "10 * y") // 100
}
}
new X().boem()``` |
Groovy voorziet gemakkelijkheidshalve een paar methods op `Eval` zoals `Eval.me` (zonder params), x/xy/xyz. Wanneer iets uitgebreidere evaluatie nodig is gebruiken we `GroovyShell`:
```java
def binding = new Binding(x: 10, y: 100)
def shell = new GroovyShell(binding)
def retVal = shell.evaluate('''
def local = "uncatchable"
catchable = x * y
10
''')
assert retVal ###### 10
assert binding.catchable ###### 100 // method 1
assert binding.getVariable("catchable") ###### 100 // method 2
```
Alles wat geëvalueerd wordt zit binnen een `Script` klasse, daarom dat het `def` keyword niet nodig is, en enkel dient om lokale variabele te instantiëren. Merk op dat het zelfs zo mogelijk is om nieuwe klassen in te laden, of om Groovy code te evalueren met `GroovyShell` binnen Java klassen!
############= Scope chain aanpassen ############=
Dit is voor beide talen niet 100% hetzelfde: Groovy maakt het mogelijk om objecten te extenden on-the-fly met `use`, terwijl Javascript de lexicale scope chain kan aanpassen met `with`.
^ Javascript ^ Groovy ^
|```javascriptwith(window.screen) {
console.log(width);
}``` | ```javadir = new File("/tmp")
use(ClassWithEachDirMethod.class) {
dir.eachDir {
println it
}
}
``` |

View File

@ -1,59 +0,0 @@
+++
title = "htaccess"
draft = false
tags = [
"code",
"htaccess"
]
date = "2015-01-06"
+++
# .htaccess stuff
Basisprincipe van rewriterules: altijd `RewriteEngine On` en `RewriteBase /` toevoegen.
Daarna: `RewriteCond` slaat enkel op **éérstvolgende** `RewriteRule` regel.
#### Request exceeded the limit of 10 internal redirects due to probable configuration error
[bron](http://stackoverflow.com/questions/1611506/request-exceeded-the-limit-of-10-internal-redirects-due-to-probable-configuratio)
Gebruik `!^map/` voor de rule om bepaalde folders uit te sluiten als ze al herschreven zijn.
#### square bracket rules: rewrite flags
[zie ook docs](http://httpd.apache.org/docs/2.2/rewrite/flags.html)
1. NC: case insensitive
2. L: stop processing other rules (final)
3. R=123: redirect HTTP code
#### Redirecten - moved
[bron](http://enarion.net/web/htaccess/migrate-domains/)
Van oud naar nieuw domeinnaam:
```
RewriteCond %{HTTP_HOST} savesourdough.com$ [NC]
RewriteRule ^(.*)$ http://www.redzuurdesem.be/$1 [L,R=301]
```
1. Kan ook om bvb van `www` naar `http` of omgekeerd te redirecten.
2. `^(.*)$` catcht alles achter het domein in een parameter `$1`
#### Redirecten - verschillende domeinen
```
RewriteEngine On
#ADD TRAILING SLASH TO DIRECTORY IF NONE EXISTS
RewriteRule ^([^<br/>.]+[^/])$ http://%{HTTP_HOST}/$1/ [L]
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$ [NC]
RewriteCond %{REQUEST_URI} !site1/ [NC]
RewriteRule ^(.*)$ /site1/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$ [NC]
RewriteCond %{REQUEST_URI} !site/ [NC]
RewriteRule ^(.*)$ /site2/$1 [L]
```

View File

@ -1,14 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"home"
]
date = "2013-07-10"
+++
# code >> Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>

View File

@ -1,63 +0,0 @@
+++
title = "java"
draft = false
tags = [
"code",
"java"
]
date = "2013-05-17"
+++
# Java Stuff
## Inhoudsopgave
<img style='' src='/img/indexmenu>java|js context navbar nocookie'>
## Snippets
#### Upcasting hacks & tricks
Vies van `instanceof`? Gebruik `isAssignableFrom` om op een abstracte logica te implementeren die een interface nodig heeft enkele niveaus verder.<br/><br/>
Op die manier hebben we geen diamond inheritance nodig! Check it out:
```java
@SuppressWarnings("unchecked")
final void generateUidIfNotYetFilledIn() {
if (HasUid.class.isAssignableFrom(this.getClass())) {
HasUid hasUid = (HasUid) this;
if (isEmpty(hasUid.getUid())) {
hasUid.setUid(getEntityUidGenerator().generateFor((Class<? extends HasUid>) this.getClass()));
}
}
}
```
#### ReplaceAll case Insensitive
Geen `StringUtils` van apache commons method beschikbaar als `replaceIgnoreCase`... Stom!
```java
public class Main {
public static void main(String[] argv) throws Exception {
String str = "Abc abc";
String result = str.replaceAll("(?i)abc", "DEF");
System.out.println("After replacement:<br/>n" + " " + result);
}
}
```
Vergeet niet speciale regex karakters te escapen zoals `<br/><br/>[` de *brackets* etc.
## Pitfalls
#### Java versies
1. Java 7 & java 6 mixen: gebruik `-XX:-UseSplitVerifier` als VM argument wanneer exceptions zoals "expecting invalid stackmap frame..." zich voordoen. - Wat doet dit arumgent eigenlijk? [Java 7 Bytecode verification](http://chrononsystems.com/blog/java-7-design-flaw-leads-to-huge-backward-step-for-the-jvm.)
#### APIs
1. `Arrays.asList()` retourneert een *read-only* lijst! `add()` throwt een `UnsupportedOperationException`.
2. guava's `transform()` ea zijn **lazy-loaded**, let op met transacties en inner class state!

View File

@ -1,15 +0,0 @@
+++
title = "home"
draft = false
tags = [
"code",
"java",
"home"
]
date = "2014-01-29"
+++
# code:java >> Home
## Inhoudsopgave
<img style='' src='/img/indexmenu>.|js navbar nocookie'>

View File

@ -1,48 +0,0 @@
+++
title = "dynamica"
draft = false
tags = [
"code",
"java",
"dynamica"
]
date = "2013-03-12"
+++
# Dynamica
Hier zitten stukjes code om java meer dynamiek te geven (voorzover dat mogelijk is...)
Veel collectie gerelateerde dingen (`filter`, `map` etc) is reeds geïmplementeerd: http://code.google.com/p/guava-libraries/
### Reduce met optellen
```java
public class CollectionUtil {
public static interface EnkelvoudigeTeller<TellerType> {
boolean magMeegeteldWorden(TellerType object);
}
public static interface MeervoudigeTeller<TellerType> {
int geefAantalMeegeteld(TellerType object);
}
public static <TellerType> int tel(Collection<TellerType> objecten, MeervoudigeTeller<TellerType> teller) {
int geteld = 0;
for (TellerType object : objecten) {
geteld += teller.geefAantalMeegeteld(object);
}
return geteld;
}
public static <TellerType> int tel(Collection<TellerType> objecten, final EnkelvoudigeTeller<TellerType> teller) {
return tel(objecten, new MeervoudigeTeller<TellerType>() {
@Override
public int geefAantalMeegeteld(TellerType object) {
return teller.magMeegeteldWorden(object) ? 1 : 0;
}
});
}
}
```

View File

@ -1,153 +0,0 @@
+++
title = "aspectj"
draft = false
tags = [
"code",
"java",
"dynamica",
"aspectj"
]
date = "2013-03-12"
+++
# Loadtime weaving met aspectJ
## Spring weaving
Zie **demo projectje**: <img style='' src='/img//code/java/dynamica/weaving-test.zip|'>
:exclamation: Vanaf versie 3.0 moet `spring-instrument` in plaats van `spring-agent` gebruikt worden! (bestaat niet meer)
Zie http://static.springsource.org/spring/docs/3.1.0.RELEASE/reference/htmlsingle/#aop
Weavers:
1. **aspectj jar** `-javaagent:C:<br/>dvl.home<br/>env<br/>aspectj<br/>aspectjweaver-1.6.11.jar`
2. **spring-instrument jar** `-javaagent:C:/dvl.home/prj/comeet/tools/spring-instrument-3.1.0.RELEASE.jar`
#### Wat heb je nodig om loadtime weaving te laten werken
##### applicationContext.xml
* met spring-configured (zelfde als `org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect` bean, zie [spring docs](http://static.springsource.org/spring/docs/3.0.0.RC2/reference/html/ch07s08.html))
* met `load-time-weaver` op
```xml
<?xml version######"1.0" encoding"UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http:*www.springframework.org/schema/beans http:*www.springframework.org/schema/beans/spring-beans-3.0.xsd
http:*www.springframework.org/schema/context http:*www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:spring-configured/>
<context:component-scan base-package="be.test"/>
<context:load-time-weaver/>
</beans>
```
##### juiste manier van opzetten beans
-> Een bean die `@Component` annotated is waar een andere bean die `@Configurable` ge-`new`t wordt, die via `@Autowired` injecties bevat
bijvroobeeld:
-> `SomeBean`
```java
@Component
public class SomeBean {
private final SomeBeanToInject someBeanToInject;
@Autowired
public SomeBean(SomeBeanToInject someBeanToInject) {
System.out.println("creating some bean, got injected: " + someBeanToInject);
this.someBeanToInject = someBeanToInject;
}
public OtherBean createOtherBean() {
return new OtherBean();
}
}
```
-> `OtherBean`
```java
@Configurable
public class OtherBean {
private SomeBeanToDynamicallyInject someBeanToDynamicallyInject;
@Autowired
public void setSomeBeanToDynamicallyInject(SomeBeanToDynamicallyInject someBeanToDynamicallyInject) {
System.out.println("Setting some dynamically injected bean! : " + someBeanToDynamicallyInject);
this.someBeanToDynamicallyInject = someBeanToDynamicallyInject;
}
}
```
-> `SomeBeanToDynamicallyInject`
```java
@Component
public class SomeBeanToDynamicallyInject {
public String message = "dynamically injected";
}
```
#### AspectJ en Junit testing
De annotatie `@EnableLoadTimeWeaving` heb je **NIET** nodig. Het is ook niet nodig om java config klasse te verwijzen, de context xml pikt dit met component scanning op!
```java
@ContextConfiguration(locations = { "../../applicationContext.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class SomeBeanTest {
@Autowired
private SomeBean someBean;
@Test
public void someBeanIsDynamicallyInjected() {
Assert.assertTrue(someBean.createOtherBean().isDynamicallyInjected());
}
}
```
:exclamation: **Unit- en Integratietesten opsplitsen in andere source folders**! Waarom?<br/><br/>
Omdat, ééns als een class file ingeladen is door de JVM, deze in het geheugen blijft zitten, en de volgende keer dat een andere test binnen dezelfde suite deze wilt gebruiken en verwacht dat die enhanched is (dus `@Autowired` geïnjecteerd), dit niet zo is, omdat een vorige gewone unit test hier een `new` van gedaan heeft en dit reeds in het geheugen steekt.
Is hier een oplossing voor? `ClassLoader` cache clearen op een of andere manier? Zie http://members.iinet.net.au/~macneall/Java/ClassReloading.html -
> Java classes themselves are dumped from memory when the classloader that loaded them is garbage collected. So the way to dynamically reload a class is to make sure that you control the classloader for that class. So when, all the references to instances of that class are gone, and you null the classloader itself, the runtime should collect the class itself. Then, next time an object of that class is used, it needs to be loaded again.
Probleem doet zich voor met `mvn clean install` maar soms niet in eclipse??
## aop.xml configuratie
Deze wordt blijkbaar gebruikt om te bepalen wat er precies gewoven moet worden - als die er NIET is gaat hij by default alles weaven en een warning tonen in de console log:
```
[AppClassLoader@17943a4] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
```
File moet in **src/main/resources/META-INF/aop.xml** staan (op classpath). Content bvb:
```xml
<?xml version="1.0"?>
<aspectj>
<aspects>
<weaver options="-Xlint:ignore -nowarn">
<include within="@org.springframework.beans.factory.annotation.Configurable be.bla.blie..*" />
</weaver>
</aspects>
</aspectj>
```
##### options
1. `-Xlint:ignore -nowarn` negeert alle warnings dat bepaalde zaken niet gewoven kunnen worden
2. `-verbose` print meer debuginfo
3. `-showWeaveInfo` print wat wanneer gewoven wordt.

Some files were not shown because too many files have changed in this diff Show More