[{"data":1,"prerenderedAt":3917},["ShallowReactive",2],{"\u002F":3},[4,71,233,793,2005,2066],{"id":5,"title":6,"body":7,"date":57,"description":58,"extension":59,"image":60,"meta":61,"navigation":63,"path":64,"published":63,"seo":65,"snippet":66,"stem":67,"tags":68,"video":54,"__hash__":70},"articles\u002Farticles\u002Freimagining-my-blog-yet-again.md","Reimagining my blog yet again",{"type":8,"value":9,"toc":53},"minimark",[10,28,31,39,42,45],[11,12,13,14,21,22,27],"p",{},"As with my previous upgrade, it's time to update my blog and portfolio site yet again. This decision stems not from a dislike of ",[15,16,20],"a",{"href":17,"rel":18},"https:\u002F\u002Fgridsome.org\u002F",[19],"nofollow","Gridsome",", but rather a consideration of long-term maintainability. Despite the initial excitement surrounding Gridsome in 2021, it has regrettably lost momentum and turned into an abandoned project over the past couple of years. Fortunately, there's ",[15,23,26],{"href":24,"rel":25},"https:\u002F\u002Fcontent.nuxtjs.org\u002F",[19],"Nuxt Content","—an extension for Nuxt with a similar goal to that of Gridsome.",[11,29,30],{},"Fortunately, my familiarity with Nuxt due to its use in both my previous and current jobs made the transition from Gridsome to Nuxt Content seem like a breeze after delving into the Nuxt Content documentation.",[11,32,33,34,38],{},"The entire process only took a couple of afternoons. Initially, I migrated the content (markdown files, video and images) to Gridsome with some minor adjustments to file references such as images and videos. Then, I replicated all the components. For the components, the only necessary change was replacing the GraphQL queries with the ",[35,36,37],"code",{},"queryContent()"," function, which employs a query style akin to MongoDB.",[11,40,41],{},"And that's about all there was to it—quite straightforward.",[11,43,44],{},"If you're still utilizing Gridsome but exploring alternatives within the Vue ecosystem, I wholeheartedly recommend giving Nuxt Content a try.",[11,46,47,48],{},"image by ",[15,49,52],{"href":50,"rel":51},"https:\u002F\u002Fwww.artstation.com\u002Fclementdartigues",[19],"clément dartigues",{"title":54,"searchDepth":55,"depth":55,"links":56},"",2,[],"2023-08-25","As with my previous upgrade, it's time to update my blog and portfolio site yet again. This decision stems not from a dislike of Gridsome, but rather a consideration of long-term maintainability. Despite the initial excitement surrounding Gridsome in 2021, it has regrettably lost momentum and turned into an abandoned project over the past couple of years. Fortunately, there's Nuxt Content—an extension for Nuxt with a similar goal to that of Gridsome.","md","\u002Fimages\u002Freimagining-my-blog-yet-again.png",{"slug":62},"reimagining-my-blog-yet-again",true,"\u002Farticles\u002Freimagining-my-blog-yet-again",{"title":6,"description":58},"A brief account of migrating my blog from Gridsome to Nuxt Content.","articles\u002Freimagining-my-blog-yet-again",[69],"Web-development","5yCRU3ny8BUIUAHfjUGHhn_6bdeLz5grp5Dme4SdMxY",{"id":72,"title":73,"body":74,"date":219,"description":220,"extension":59,"image":221,"meta":222,"navigation":63,"path":224,"published":63,"seo":225,"snippet":226,"stem":227,"tags":228,"video":231,"__hash__":232},"articles\u002Farticles\u002Freaper-alternating-track-background.md","Reaper alternating track background",{"type":8,"value":75,"toc":217},[76,91,103,122,127,149,169,176,190,208],[11,77,78,79,82,83,86,87,90],{},"Lets start with going to preferences ",[35,80,81],{},"REAPER > Preferences"," and navigate to the ",[35,84,85],{},"Appearance"," tab. On the ",[35,88,89],{},"Divide arrange view vertically every"," and check it and select the desired amount of measures you want it to alternate. I use 8.",[11,92,93,99,100],{},[94,95],"img",{"alt":96,"src":97,"title":98},"Alternating settings","\u002Fimages\u002Freaper-alternating-track-background\u002F2-alternating-settings.png","alternating settings","\nIn some cases these changes may not be visible, this depends on the theme you are using.\n",[94,101],{"alt":96,"src":102,"title":98},"\u002Fimages\u002Freaper-alternating-track-background\u002F3-alternating-track-background.png",[11,104,105,106,109,110,113,114,117,118,121],{},"In case you want this fixed or change the colors we need to make some tweaks to the theme. To do this open the Actions panel ",[35,107,108],{},"Actions > Show Actions list",". Next type ",[35,111,112],{},"Tweak theme"," in the filter field. Select ",[35,115,116],{},"Theme development: Show theme tweak\u002Fconfiguration window"," and press the run button, this will open the ",[35,119,120],{},"Theme development\u002Ftweaker"," panel. From here we can tweak the following colors to get the desired result.",[11,123,124],{},[94,125],{"alt":96,"src":126,"title":98},"\u002Fimages\u002Freaper-alternating-track-background\u002F4-open-theme-tweak.png",[128,129,130,134,137,140,143,146],"ul",{},[131,132,133],"li",{},"Track background (odd tracks)",[131,135,136],{},"Track background (even tracks)",[131,138,139],{},"Track background selected (odd tracks)",[131,141,142],{},"Track background selected (even tracks)",[131,144,145],{},"Empty arrange view area",[131,147,148],{},"Empty arrange view area vertical grid shading",[150,151,153,162],"div",{"style":152},"display: flex;",[150,154,156],{"style":155},"width: 50%;",[11,157,158],{},[94,159],{"alt":160,"src":161,"title":98},"image","\u002Fimages\u002Freaper-alternating-track-background\u002F5-theme-track-background.png",[150,163,164],{"style":155},[11,165,166],{},[94,167],{"alt":160,"src":168,"title":98},"\u002Fimages\u002Freaper-alternating-track-background\u002F6-theme-arrange-background.png",[11,170,171,172,175],{},"The ",[35,173,174],{},"Track background"," colors will only affect the background area of the tracks.",[11,177,178,179,181,182,184,185,187,188],{},"If you want the empty arrangement area to also show alternating colors every 8 bars you can edit the ",[35,180,145],{},"to match the color of ",[35,183,133],{}," and ",[35,186,148],{}," to match the color of ",[35,189,136],{},[150,191,192,200],{"style":152},[150,193,194],{"style":155},[11,195,196,199],{},[94,197],{"alt":160,"src":198,"title":98},"\u002Fimages\u002Freaper-alternating-track-background\u002F1-default-look.png","\nWe went from this...",[150,201,202],{"style":155},[11,203,204,207],{},[94,205],{"alt":96,"src":206,"title":98},"\u002Fimages\u002Freaper-alternating-track-background\u002F7-alternating-track-background-and-arangment-background.png","\nTo this.",[11,209,210,211,216],{},"Thats it, hope this was helpful to anyone, if you have any questions or feedback you're always welcome to send me a message on twitter ",[15,212,215],{"href":213,"rel":214},"https:\u002F\u002Ftwitter.com\u002FLiamEderzeel",[19],"@liamederzeel",".",{"title":54,"searchDepth":55,"depth":55,"links":218},[],"2022-12-03","Lets start with going to preferences REAPER > Preferences and navigate to the Appearance tab. On the Divide arrange view vertically every and check it and select the desired amount of measures you want it to alternate. I use 8.","\u002Fimages\u002Freaper-alternating-track-background\u002Fcover.png",{"slug":223},"reaper-alternating-track-background","\u002Farticles\u002Freaper-alternating-track-background",{"title":73,"description":220},"How to set the tack background to alternate colors every 8 bars.","articles\u002Freaper-alternating-track-background",[229,230],"Reaper","Music",null,"ac7ZrQapnaXFZOFATc8ArrxLozq9NsyNPfffcRBxmEo",{"id":234,"title":235,"body":236,"date":776,"description":777,"extension":59,"image":778,"meta":779,"navigation":63,"path":781,"published":63,"seo":782,"snippet":783,"stem":784,"tags":785,"video":231,"__hash__":792},"articles\u002Farticles\u002Fan-elegant-way-of-managing-your-dot-files-with-git.md","An elegant way of managing your dot files with git",{"type":8,"value":237,"toc":767},[238,245,248,255,260,263,266,270,273,276,291,321,335,340,385,388,426,430,433,436,442,445,453,456,462,465,516,519,523,526,589,596,681,684,703,706,710,719,723,729,733,763],[11,239,240,241,244],{},"How to juggle all your configuration files between machines? a question probably asked many times. Lots of people store there configuration files or also so called dotfiles in git repos to more easily share them between machine. A commonly used method is having a repo with all the dotfiles in the $HOME directory and symbolic link the config files to the desired location like so ",[35,242,243],{},"ln -s ~\u002F.dotfiles\u002F.zshrc ~\u002F.zshrc",". Syncing dotfiles with symbolic links can still be quite a chore especially when you clone your repo to a new machine and have to create all those symbolic links again.",[11,246,247],{},"Not to worry fortunately there is a more elegant way no more symbolic links and it only dependency is git.",[11,249,250,251,254],{},"How does it work, by making use of a bare repository you effectively only get the repository state without its working tree. With some flags you can use this repository with the ",[35,252,253],{},"$HOME"," directory as its working tree eliminating the need for carefully managing you symbolic links because all files are already in the right place. Neat right?",[256,257,259],"h2",{"id":258},"lest-get-started","Lest get started",[11,261,262],{},"If you have not tracked you dotfiles in a git repo you can get started in the next section right away..",[11,264,265],{},"If you already have a repository skip to the \"Migrate existing repository\".",[256,267,269],{"id":268},"setup-from-scratch","Setup from scratch",[11,271,272],{},"If you already track your dotfiles in a git repository.",[11,274,275],{},"with setting up your own dotfiles repo.",[11,277,278,279,282,283,286,287,290],{},"First things first lets create a folder for the bare repo ",[35,280,281],{},"mkdir ~\u002F.dots","\nnext we ",[35,284,285],{},"cd ~\u002F.dots"," and run ",[35,288,289],{},"git init --bare"," to setup our bare repo.",[11,292,293,294,297,298,301,302,305,306,297,309,312,313,316,317,320],{},"Next we're going to add an alias to our ",[35,295,296],{},"~\u002F.zshrc"," or ",[35,299,300],{},"~\u002F.bashrc","\nadd ",[35,303,304],{},"alias dots='\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'"," to a place of you liking, save and run ",[35,307,308],{},"source ~\u002F.zshrc",[35,310,311],{},"source ~\u002F.bashrc",".\nNow you can use the ",[35,314,315],{},"dots"," alias just as how you normally use the ",[35,318,319],{},"git"," command in a project folder.",[11,322,323,324,327,328,331,332,334],{},"Lets check our repos status with ",[35,325,326],{},"dots status",". As you can see git tries to make you aware that all you files in the home directory are untracked. this makes things a bit unclear. We can solve this by configuring the repo to only show changes that are already tracked by running ",[35,329,330],{},"dots config --local status.showUntrackedFiles no",". If we now run ",[35,333,326],{}," again we see there are no changes in the working tree.",[11,336,337,338,216],{},"We are all set to start tracking files. Lets commit our ",[35,339,296],{},[341,342,346],"pre",{"className":343,"code":344,"language":345,"meta":54,"style":54},"language-bash shiki shiki-themes github-light github-dark","dots status\ndots add ~\u002F.zshrc\ndots commit -m \"feat: add zsh config\"\n","bash",[35,347,348,360,370],{"__ignoreMap":54},[349,350,353,356],"span",{"class":351,"line":352},"line",1,[349,354,315],{"class":355},"sScJk",[349,357,359],{"class":358},"sZZnC"," status\n",[349,361,362,364,367],{"class":351,"line":55},[349,363,315],{"class":355},[349,365,366],{"class":358}," add",[349,368,369],{"class":358}," ~\u002F.zshrc\n",[349,371,373,375,378,382],{"class":351,"line":372},3,[349,374,315],{"class":355},[349,376,377],{"class":358}," commit",[349,379,381],{"class":380},"sj4cs"," -m",[349,383,384],{"class":358}," \"feat: add zsh config\"\n",[11,386,387],{},"The only thing left to do is to add a remote and push our changes.",[341,389,391],{"className":343,"code":390,"language":345,"meta":54,"style":54},"dots remote add origin \u003Cyour-remote-repository>\ndots push\n",[35,392,393,419],{"__ignoreMap":54},[349,394,395,397,400,402,405,409,412,416],{"class":351,"line":352},[349,396,315],{"class":355},[349,398,399],{"class":358}," remote",[349,401,366],{"class":358},[349,403,404],{"class":358}," origin",[349,406,408],{"class":407},"szBVR"," \u003C",[349,410,411],{"class":358},"your-remote-repositor",[349,413,415],{"class":414},"sVt8B","y",[349,417,418],{"class":407},">\n",[349,420,421,423],{"class":351,"line":55},[349,422,315],{"class":355},[349,424,425],{"class":358}," push\n",[256,427,429],{"id":428},"migrate-existing-repository","Migrate existing repository",[11,431,432],{},"If you are setting up from scratch you can skip this section.",[11,434,435],{},"If you already track your files in a git repository you can easily migrate to this approach.",[11,437,438,439,441],{},"First off make sure the file and folder structure of your current dotfile repository mirrors your ",[35,440,253],{}," folder one to one.",[11,443,444],{},"For example something like this.",[341,446,451],{"className":447,"code":449,"language":450},[448],"language-text","dotfiles\n│   README.md\n│   .zshrc    \n│   .gitconfig\n│\n└───alacritty\n│   │   alacritty.conf\n│   \n└───htop\n    │   htoprc\n","text",[35,452,449],{"__ignoreMap":54},[11,454,455],{},"Should be changed to resemble your home directory like so.",[341,457,460],{"className":458,"code":459,"language":450},[448],"dotfiles\n│   README.md\n│   .zshrc    \n│   .gitconfig\n│\n└───.config\n    │\n    └───alacritty\n    │   │   alacritty.conf\n    │\n    └───htop\n        │   htoprc\n",[35,461,459],{"__ignoreMap":54},[11,463,464],{},"Next add this alias to you shell configuration file.",[341,466,468],{"className":343,"code":467,"filename":296,"language":345,"meta":54,"style":54},"# ~\u002F.zshrc\n\n...\n\nalias dots='\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'\n\n...\n",[35,469,470,476,481,486,491,506,511],{"__ignoreMap":54},[349,471,472],{"class":351,"line":352},[349,473,475],{"class":474},"sJ8bj","# ~\u002F.zshrc\n",[349,477,478],{"class":351,"line":55},[349,479,480],{"emptyLinePlaceholder":63},"\n",[349,482,483],{"class":351,"line":372},[349,484,485],{"class":380},"...\n",[349,487,489],{"class":351,"line":488},4,[349,490,480],{"emptyLinePlaceholder":63},[349,492,494,497,500,503],{"class":351,"line":493},5,[349,495,496],{"class":407},"alias",[349,498,499],{"class":414}," dots",[349,501,502],{"class":407},"=",[349,504,505],{"class":358},"'\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'\n",[349,507,509],{"class":351,"line":508},6,[349,510,480],{"emptyLinePlaceholder":63},[349,512,514],{"class":351,"line":513},7,[349,515,485],{"class":380},[11,517,518],{},"From then on it's the same as setting up a fresh machine follow the instructions from the next section to complete your migration.",[256,520,522],{"id":521},"setup-a-new-machine","Setup a new machine",[11,524,525],{},"To install your dotfiles to a new machine looks something like this.",[341,527,529],{"className":343,"code":528,"language":345,"meta":54,"style":54},"git clone --bare \u003Cyour-remote-repository> ~\u002F.dots\nalias dots='\u002Fusr\u002Fbin\u002Fgit --git-dir=$HOME\u002F.dots\u002F --work-tree=$HOME'\ndots config --local status.showUntrackedFiles no \ndots checkout\n",[35,530,531,553,563,582],{"__ignoreMap":54},[349,532,533,535,538,541,543,545,547,550],{"class":351,"line":352},[349,534,319],{"class":355},[349,536,537],{"class":358}," clone",[349,539,540],{"class":380}," --bare",[349,542,408],{"class":407},[349,544,411],{"class":358},[349,546,415],{"class":414},[349,548,549],{"class":407},">",[349,551,552],{"class":358}," ~\u002F.dots\n",[349,554,555,557,559,561],{"class":351,"line":55},[349,556,496],{"class":407},[349,558,499],{"class":414},[349,560,502],{"class":407},[349,562,505],{"class":358},[349,564,565,567,570,573,576,579],{"class":351,"line":372},[349,566,315],{"class":355},[349,568,569],{"class":358}," config",[349,571,572],{"class":380}," --local",[349,574,575],{"class":358}," status.showUntrackedFiles",[349,577,578],{"class":358}," no",[349,580,581],{"class":414}," \n",[349,583,584,586],{"class":351,"line":488},[349,585,315],{"class":355},[349,587,588],{"class":358}," checkout\n",[11,590,591,592,595],{},"Running ",[35,593,594],{},"dots checkout"," can result in something like this.",[341,597,599],{"className":343,"code":598,"language":345,"meta":54,"style":54},"error: The following untracked working tree files would be overwritten by checkout:\n    .zshrc\nPlease move or remove them before you can switch branches.\nAborting\n",[35,600,601,639,644,676],{"__ignoreMap":54},[349,602,603,606,609,612,615,618,621,624,627,630,633,636],{"class":351,"line":352},[349,604,605],{"class":355},"error:",[349,607,608],{"class":358}," The",[349,610,611],{"class":358}," following",[349,613,614],{"class":358}," untracked",[349,616,617],{"class":358}," working",[349,619,620],{"class":358}," tree",[349,622,623],{"class":358}," files",[349,625,626],{"class":358}," would",[349,628,629],{"class":358}," be",[349,631,632],{"class":358}," overwritten",[349,634,635],{"class":358}," by",[349,637,638],{"class":358}," checkout:\n",[349,640,641],{"class":351,"line":55},[349,642,643],{"class":355},"    .zshrc\n",[349,645,646,649,652,655,658,661,664,667,670,673],{"class":351,"line":372},[349,647,648],{"class":355},"Please",[349,650,651],{"class":358}," move",[349,653,654],{"class":358}," or",[349,656,657],{"class":358}," remove",[349,659,660],{"class":358}," them",[349,662,663],{"class":358}," before",[349,665,666],{"class":358}," you",[349,668,669],{"class":358}," can",[349,671,672],{"class":358}," switch",[349,674,675],{"class":358}," branches.\n",[349,677,678],{"class":351,"line":488},[349,679,680],{"class":355},"Aborting\n",[11,682,683],{},"You have two options:",[685,686,687,693],"ol",{},[131,688,689,690,216],{},"overwrite the existing files if you feel confident you are not losing anything by running ",[35,691,692],{},"dots checkout -f",[131,694,695,696,699,700,702],{},"backup the existing files by renaming them like so ",[35,697,698],{},"mv ~\u002F.zshrc ~\u002F.zshrc.backup"," and when you're done, to backup your files run ",[35,701,594],{}," again.",[11,704,705],{},"At this point all your dotfiles should be in the right place.",[256,707,709],{"id":708},"alternatives","Alternatives",[11,711,712,713,718],{},"I prefer this method of managing dotfiles for its simplicity, but this is just one approach of many. If you're interested in other ways of managing your dotfiles I recommend checking out ",[15,714,717],{"href":715,"rel":716},"https:\u002F\u002Fdotfiles.github.io\u002F",[19],"dotfiles.github.io",". It has a lot of references of other people's dotsfiles, tutorials and projects centered around dotfiles.",[256,720,722],{"id":721},"wrapping-up","Wrapping up",[11,724,725,726,216],{},"Hope this post helps out a fellow developer on their config journey. If you have any questions or feedback you're always welcome to send me a message on ",[15,727,215],{"href":213,"rel":728},[19],[256,730,732],{"id":731},"sources","Sources",[128,734,735,745,754],{},[131,736,737,740,741],{},[349,738,739],{},"1"," ",[15,742,743],{"href":743,"rel":744},"https:\u002F\u002Fnews.ycombinator.com\u002Fitem?id=11070797",[19],[131,746,747,740,750],{},[349,748,749],{},"2",[15,751,752],{"href":752,"rel":753},"https:\u002F\u002Fwww.atlassian.com\u002Fgit\u002Ftutorials\u002Fdotfiles",[19],[131,755,756,740,759],{},[349,757,758],{},"3",[15,760,761],{"href":761,"rel":762},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=tBoLDpTWVOM",[19],[764,765,766],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":54,"searchDepth":55,"depth":55,"links":768},[769,770,771,772,773,774,775],{"id":258,"depth":55,"text":259},{"id":268,"depth":55,"text":269},{"id":428,"depth":55,"text":429},{"id":521,"depth":55,"text":522},{"id":708,"depth":55,"text":709},{"id":721,"depth":55,"text":722},{"id":731,"depth":55,"text":732},"2022-07-29","How to juggle all your configuration files between machines? a question probably asked many times. Lots of people store there configuration files or also so called dotfiles in git repos to more easily share them between machine. A commonly used method is having a repo with all the dotfiles in the $HOME directory and symbolic link the config files to the desired location like so ln -s ~\u002F.dotfiles\u002F.zshrc ~\u002F.zshrc. Syncing dotfiles with symbolic links can still be quite a chore especially when you clone your repo to a new machine and have to create all those symbolic links again.","\u002Fimages\u002Fdot-files.png",{"slug":780},"an-elegant-way-of-managing-your-dot-files-with-git","\u002Farticles\u002Fan-elegant-way-of-managing-your-dot-files-with-git",{"title":235,"description":777},"How to use a git bare repo to manage and sync your dotfiles the easy why.","articles\u002Fan-elegant-way-of-managing-your-dot-files-with-git",[786,787,788,789,790,791],"Linux","Config","Bash","Zsh","Terminal","Git","NBMerbxK6qgbZ4h_PZrCqlAVsRR_hpQL-lwM2GyTfEg",{"id":794,"title":795,"body":796,"date":1994,"description":1995,"extension":59,"image":1996,"meta":1997,"navigation":63,"path":1999,"published":63,"seo":2000,"snippet":2001,"stem":2002,"tags":2003,"video":231,"__hash__":2004},"articles\u002Farticles\u002Ftmux-project-laucher.md","Build a Tmux project laucher",{"type":8,"value":797,"toc":1989},[798,803,812,827,830,833,847,851,858,878,881,884,887,1064,1067,1070,1073,1099,1102,1133,1136,1225,1232,1272,1275,1341,1345,1348,1929,1935,1941,1967,1970,1973,1975,1986],[799,800,802],"h1",{"id":801},"rationale","Rationale",[11,804,805,806,811],{},"I found myself growing increasingly frustrated with the need to rapidly switch between multiple coding projects. To tackle this, I resorted to managing various terminal sessions, utilizing ",[15,807,810],{"href":808,"rel":809},"https:\u002F\u002Fgithub.com\u002Fianyh\u002FAmethyst",[19],"Amethyst"," – a tiling window manager for macOS. The challenge arose when these sessions began to stack up, often reaching three or more terminals in full-screen mode, making it easy to lose track of which window corresponded to which project.",[11,813,814,815,820,821,826],{},"Although I had previously tried my hand at using ",[15,816,819],{"href":817,"rel":818},"https:\u002F\u002Fgithub.com\u002Ftmux\u002Ftmux\u002Fwiki",[19],"Tmux"," and even delved into experimenting with ",[15,822,825],{"href":823,"rel":824},"https:\u002F\u002Fgithub.com\u002Ftmuxinator\u002Ftmuxinator",[19],"Tmuxinator",", neither option truly resonated with me. The process of managing and navigating sessions was less intuitive than my initial expectations. Tasks like crafting sessions, renaming them, or typing out the complete tmuxinator command alongside the project name often felt cumbersome.",[11,828,829],{},"Recently, I was inspired by a video of ThePrimeagen, He implemented fzf a fuzzy search program for selecting his project folders, enabling seamless switching between projects, even when not yet within a tmux session.",[11,831,832],{},"This inspiration prompted me to develop a similar program with the following key objectives:",[128,834,835,838,841,844],{},[131,836,837],{},"It should exclusively list project directories.",[131,839,840],{},"It should instantiate a new tmux session at the root of the selected project.",[131,842,843],{},"It should provide the capability to attach from outside of tmux to an existing session, if one is available.",[131,845,846],{},"It should switch to an existing session, provided that it is already attached to an other a tmux session.",[799,848,850],{"id":849},"lets-get-started","Lets get started",[11,852,853,854,857],{},"Let's begin by creating a file named project-launcher within the ~\u002F.local\u002Fbin\u002F directory and open ",[35,855,856],{},"~\u002F.local\u002Fbin\u002Fproject-launcher"," in your text editor of choice.",[341,859,863],{"className":860,"code":861,"language":862,"meta":54,"style":54},"language-console shiki shiki-themes github-light github-dark","#!\u002Fusr\u002Fbin\u002Fenv bash\n\n...\n","console",[35,864,865,870,874],{"__ignoreMap":54},[349,866,867],{"class":351,"line":352},[349,868,869],{"class":380},"#!\u002Fusr\u002Fbin\u002Fenv bash\n",[349,871,872],{"class":351,"line":55},[349,873,480],{"emptyLinePlaceholder":63},[349,875,876],{"class":351,"line":372},[349,877,485],{"class":380},[11,879,880],{},"Let's begin by addressing our inputs, specifically the project folders that we intend to present as options. All of my project directories are situated within ~\u002Fprojects, categorized into either personal projects or various organization projects. The structure involves a distinct directory for personal projects and multiple directories housing organizational projects.",[11,882,883],{},"Consequently, our objective is to accommodate the passage of multiple paths, which will subsequently feature in our fuzzy search functionality. To achieve this, we'll designate these paths under the -d flag. Furthermore, we should account for handling the --help and -h flags, while ensuring that any other scenarios prompt an appropriate error message.",[11,885,886],{},"With the aid of optargs, our implementation might take the following form:",[341,888,890],{"className":860,"code":889,"language":862,"meta":54,"style":54},"...\n\noptstring=\":hd:-:\"\nwhile getopts ${optstring} arg; do\n  case ${arg} in\n    -)\n      case \"${OPTARG}\" in\n        help)\n            usage\n            ;;\n        *)\n            if [ \"$OPTERR\" = 1 ] && [ \"${optspec:0:1}\" != \":\" ]; then\n                echo \"Invalid option --${OPTARG}\" >&2\n            fi\n            ;;\n      esac;;\n    h)\n      usage\n      ;;\n    d)\n      multi+=(\"$OPTARG\")\n      ;;\n    ?)\n      echo \"Invalid option: -${OPTARG}.\"\n      exit 2\n      ;;\n  esac\ndone\nshift $(expr $OPTIND - 1 )\n\n...\n",[35,891,892,896,900,905,910,915,920,925,931,937,943,949,955,961,967,972,978,984,990,996,1002,1008,1013,1019,1025,1031,1036,1042,1048,1054,1059],{"__ignoreMap":54},[349,893,894],{"class":351,"line":352},[349,895,485],{"class":380},[349,897,898],{"class":351,"line":55},[349,899,480],{"emptyLinePlaceholder":63},[349,901,902],{"class":351,"line":372},[349,903,904],{"class":380},"optstring=\":hd:-:\"\n",[349,906,907],{"class":351,"line":488},[349,908,909],{"class":380},"while getopts ${optstring} arg; do\n",[349,911,912],{"class":351,"line":493},[349,913,914],{"class":380},"  case ${arg} in\n",[349,916,917],{"class":351,"line":508},[349,918,919],{"class":380},"    -)\n",[349,921,922],{"class":351,"line":513},[349,923,924],{"class":380},"      case \"${OPTARG}\" in\n",[349,926,928],{"class":351,"line":927},8,[349,929,930],{"class":380},"        help)\n",[349,932,934],{"class":351,"line":933},9,[349,935,936],{"class":380},"            usage\n",[349,938,940],{"class":351,"line":939},10,[349,941,942],{"class":380},"            ;;\n",[349,944,946],{"class":351,"line":945},11,[349,947,948],{"class":380},"        *)\n",[349,950,952],{"class":351,"line":951},12,[349,953,954],{"class":380},"            if [ \"$OPTERR\" = 1 ] && [ \"${optspec:0:1}\" != \":\" ]; then\n",[349,956,958],{"class":351,"line":957},13,[349,959,960],{"class":380},"                echo \"Invalid option --${OPTARG}\" >&2\n",[349,962,964],{"class":351,"line":963},14,[349,965,966],{"class":380},"            fi\n",[349,968,970],{"class":351,"line":969},15,[349,971,942],{"class":380},[349,973,975],{"class":351,"line":974},16,[349,976,977],{"class":380},"      esac;;\n",[349,979,981],{"class":351,"line":980},17,[349,982,983],{"class":380},"    h)\n",[349,985,987],{"class":351,"line":986},18,[349,988,989],{"class":380},"      usage\n",[349,991,993],{"class":351,"line":992},19,[349,994,995],{"class":380},"      ;;\n",[349,997,999],{"class":351,"line":998},20,[349,1000,1001],{"class":380},"    d)\n",[349,1003,1005],{"class":351,"line":1004},21,[349,1006,1007],{"class":380},"      multi+=(\"$OPTARG\")\n",[349,1009,1011],{"class":351,"line":1010},22,[349,1012,995],{"class":380},[349,1014,1016],{"class":351,"line":1015},23,[349,1017,1018],{"class":380},"    ?)\n",[349,1020,1022],{"class":351,"line":1021},24,[349,1023,1024],{"class":380},"      echo \"Invalid option: -${OPTARG}.\"\n",[349,1026,1028],{"class":351,"line":1027},25,[349,1029,1030],{"class":380},"      exit 2\n",[349,1032,1034],{"class":351,"line":1033},26,[349,1035,995],{"class":380},[349,1037,1039],{"class":351,"line":1038},27,[349,1040,1041],{"class":380},"  esac\n",[349,1043,1045],{"class":351,"line":1044},28,[349,1046,1047],{"class":380},"done\n",[349,1049,1051],{"class":351,"line":1050},29,[349,1052,1053],{"class":380},"shift $(expr $OPTIND - 1 )\n",[349,1055,1057],{"class":351,"line":1056},30,[349,1058,480],{"emptyLinePlaceholder":63},[349,1060,1062],{"class":351,"line":1061},31,[349,1063,485],{"class":380},[11,1065,1066],{},"Next, our focus is on utilizing the paths provided under the -d flag to generate two lists: one consisting of paths to all subdirectories containing projects, and the other containing project names to be displayed when we select a project.",[11,1068,1069],{},"To accomplish this, consider the following approach:",[11,1071,1072],{},"To begin, we pass the project paths to the find command, specifying an argument to limit the search to a single level deep.",[341,1074,1076],{"className":860,"code":1075,"language":862,"meta":54,"style":54},"...\n\nprojectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n\n...\n",[35,1077,1078,1082,1086,1091,1095],{"__ignoreMap":54},[349,1079,1080],{"class":351,"line":352},[349,1081,485],{"class":380},[349,1083,1084],{"class":351,"line":55},[349,1085,480],{"emptyLinePlaceholder":63},[349,1087,1088],{"class":351,"line":372},[349,1089,1090],{"class":380},"projectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n",[349,1092,1093],{"class":351,"line":488},[349,1094,480],{"emptyLinePlaceholder":63},[349,1096,1097],{"class":351,"line":493},[349,1098,485],{"class":380},[11,1100,1101],{},"Additionally, we require the name of the session to which we are currently attached, along with a list of active sessions.",[341,1103,1105],{"className":860,"code":1104,"language":862,"meta":54,"style":54},"...\n\nattachedSessionName=$(tmux display-message -p \\#S)\nsessions=$(tmux list-session -F \\#S)\n\n...\n",[35,1106,1107,1111,1115,1120,1125,1129],{"__ignoreMap":54},[349,1108,1109],{"class":351,"line":352},[349,1110,485],{"class":380},[349,1112,1113],{"class":351,"line":55},[349,1114,480],{"emptyLinePlaceholder":63},[349,1116,1117],{"class":351,"line":372},[349,1118,1119],{"class":380},"attachedSessionName=$(tmux display-message -p \\#S)\n",[349,1121,1122],{"class":351,"line":488},[349,1123,1124],{"class":380},"sessions=$(tmux list-session -F \\#S)\n",[349,1126,1127],{"class":351,"line":493},[349,1128,480],{"emptyLinePlaceholder":63},[349,1130,1131],{"class":351,"line":508},[349,1132,485],{"class":380},[11,1134,1135],{},"We iterate through each project path to create a roster of project names, which will be display through fzf. Moreover, we assess the activity status of the session, accentuating the name in blue if it's active. Furthermore, if the project name corresponds to the existing tmux session name, we emphasize this particular project in yellow.",[341,1137,1139],{"className":860,"code":1138,"language":862,"meta":54,"style":54},"...\n\nprojectDisplayNames=()\nprojectNames=()\n\nfor key in ${projectPaths[@]}; do\n  value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n    projectNames+=($value)\n  if [[ $value == $attachedSessionName ]]; then \n    projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n  elif $(contains ${value} ${sessions[@]}); then \n    projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n  else\n    projectDisplayNames+=($value)\n  fi\ndone\n\n...\n",[35,1140,1141,1145,1149,1154,1159,1163,1168,1173,1178,1183,1188,1193,1198,1203,1208,1213,1217,1221],{"__ignoreMap":54},[349,1142,1143],{"class":351,"line":352},[349,1144,485],{"class":380},[349,1146,1147],{"class":351,"line":55},[349,1148,480],{"emptyLinePlaceholder":63},[349,1150,1151],{"class":351,"line":372},[349,1152,1153],{"class":380},"projectDisplayNames=()\n",[349,1155,1156],{"class":351,"line":488},[349,1157,1158],{"class":380},"projectNames=()\n",[349,1160,1161],{"class":351,"line":493},[349,1162,480],{"emptyLinePlaceholder":63},[349,1164,1165],{"class":351,"line":508},[349,1166,1167],{"class":380},"for key in ${projectPaths[@]}; do\n",[349,1169,1170],{"class":351,"line":513},[349,1171,1172],{"class":380},"  value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n",[349,1174,1175],{"class":351,"line":927},[349,1176,1177],{"class":380},"    projectNames+=($value)\n",[349,1179,1180],{"class":351,"line":933},[349,1181,1182],{"class":380},"  if [[ $value == $attachedSessionName ]]; then \n",[349,1184,1185],{"class":351,"line":939},[349,1186,1187],{"class":380},"    projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n",[349,1189,1190],{"class":351,"line":945},[349,1191,1192],{"class":380},"  elif $(contains ${value} ${sessions[@]}); then \n",[349,1194,1195],{"class":351,"line":951},[349,1196,1197],{"class":380},"    projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n",[349,1199,1200],{"class":351,"line":957},[349,1201,1202],{"class":380},"  else\n",[349,1204,1205],{"class":351,"line":963},[349,1206,1207],{"class":380},"    projectDisplayNames+=($value)\n",[349,1209,1210],{"class":351,"line":969},[349,1211,1212],{"class":380},"  fi\n",[349,1214,1215],{"class":351,"line":974},[349,1216,1047],{"class":380},[349,1218,1219],{"class":351,"line":980},[349,1220,480],{"emptyLinePlaceholder":63},[349,1222,1223],{"class":351,"line":986},[349,1224,485],{"class":380},[11,1226,1227,1228,1231],{},"Now, utilizing ",[35,1229,1230],{},"projectDisplayNames"," and prompt the user to select an option using fzf. The chosen option will then be used to retrieve the corresponding project path.",[341,1233,1235],{"className":860,"code":1234,"language":862,"meta":54,"style":54},"...\n\nselectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n\nindex=$(indexOf ${selectedProjectName} ${projectNames[@]})\nselectedPath=\"${projectPaths[$index]}\"\n\n...\n",[35,1236,1237,1241,1245,1250,1254,1259,1264,1268],{"__ignoreMap":54},[349,1238,1239],{"class":351,"line":352},[349,1240,485],{"class":380},[349,1242,1243],{"class":351,"line":55},[349,1244,480],{"emptyLinePlaceholder":63},[349,1246,1247],{"class":351,"line":372},[349,1248,1249],{"class":380},"selectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n",[349,1251,1252],{"class":351,"line":488},[349,1253,480],{"emptyLinePlaceholder":63},[349,1255,1256],{"class":351,"line":493},[349,1257,1258],{"class":380},"index=$(indexOf ${selectedProjectName} ${projectNames[@]})\n",[349,1260,1261],{"class":351,"line":508},[349,1262,1263],{"class":380},"selectedPath=\"${projectPaths[$index]}\"\n",[349,1265,1266],{"class":351,"line":513},[349,1267,480],{"emptyLinePlaceholder":63},[349,1269,1270],{"class":351,"line":927},[349,1271,485],{"class":380},[11,1273,1274],{},"The final step is to utilize the output from fzf, and us this to attach, switch to, or create a new tmux session. In case the user opts not to make a selection, we gracefully exit the process.",[341,1276,1278],{"className":860,"code":1277,"language":862,"meta":54,"style":54},"if [[ -z $selectedProjectName ]]; then\n    exit 0\nfi\n\nif ! $(contains ${selectedProjectName} ${sessions[@]} ); then\n  tmux new-session -ds $selectedProjectName -c $selectedPath\nfi\n\nif ! [[ -z $TMUX ]]; then\n  tmux switch-client -t $selectedProjectName\nelse\n  tmux attach-session -t=$selectedProjectName\nfi\n\n",[35,1279,1280,1285,1290,1295,1299,1304,1309,1313,1317,1322,1327,1332,1337],{"__ignoreMap":54},[349,1281,1282],{"class":351,"line":352},[349,1283,1284],{"class":380},"if [[ -z $selectedProjectName ]]; then\n",[349,1286,1287],{"class":351,"line":55},[349,1288,1289],{"class":380},"    exit 0\n",[349,1291,1292],{"class":351,"line":372},[349,1293,1294],{"class":380},"fi\n",[349,1296,1297],{"class":351,"line":488},[349,1298,480],{"emptyLinePlaceholder":63},[349,1300,1301],{"class":351,"line":493},[349,1302,1303],{"class":380},"if ! $(contains ${selectedProjectName} ${sessions[@]} ); then\n",[349,1305,1306],{"class":351,"line":508},[349,1307,1308],{"class":380},"  tmux new-session -ds $selectedProjectName -c $selectedPath\n",[349,1310,1311],{"class":351,"line":513},[349,1312,1294],{"class":380},[349,1314,1315],{"class":351,"line":927},[349,1316,480],{"emptyLinePlaceholder":63},[349,1318,1319],{"class":351,"line":933},[349,1320,1321],{"class":380},"if ! [[ -z $TMUX ]]; then\n",[349,1323,1324],{"class":351,"line":939},[349,1325,1326],{"class":380},"  tmux switch-client -t $selectedProjectName\n",[349,1328,1329],{"class":351,"line":945},[349,1330,1331],{"class":380},"else\n",[349,1333,1334],{"class":351,"line":951},[349,1335,1336],{"class":380},"  tmux attach-session -t=$selectedProjectName\n",[349,1338,1339],{"class":351,"line":957},[349,1340,1294],{"class":380},[256,1342,1344],{"id":1343},"the-final-product","The final product",[11,1346,1347],{},"The end result should resemble something like this.",[341,1349,1351],{"className":860,"code":1350,"filename":856,"language":862,"meta":54,"style":54},"#!\u002Fusr\u002Fbin\u002Fenv bash\n\nfunction usage {\n  echo \"Project Launcher\"\n  echo \"\"\n  echo \"Launch tmux session at your project directory or attach\u002Fswitch to an existing session\"\n  echo \"Supports fuzzy search power by fzf in multiple project directories\"\n  echo \"\"\n  echo \"Usage: $(basename $0) [-d \u003Carg>...] [--] [DIRECTORY...]\" 2>&1\n  echo \"\"\n  echo \"projectPaths:\"\n  echo \"   -d           add directory for fuzzy search\"\n  echo \"   -h|--help    show usage\"\n  exit 1\n}\n\noptstring=\":hd:-:\"\nwhile getopts ${optstring} arg; do\n  case ${arg} in\n    -)\n      case \"${OPTARG}\" in\n        help)\n            usage\n            ;;\n        *)\n            if [ \"$OPTERR\" = 1 ] && [ \"${optspec:0:1}\" != \":\" ]; then\n                echo \"Invalid option --${OPTARG}\" >&2\n            fi\n            ;;\n      esac;;\n    h)\n      usage\n      ;;\n    d)\n      multi+=(\"$OPTARG\")\n      ;;\n    ?)\n      echo \"Invalid option: -${OPTARG}.\"\n      exit 2\n      ;;\n  esac\ndone\nshift $(expr $OPTIND - 1 )\n\nfunction contains () {\n  local value=$1\n  shift\n  local elements=(\"$@\")\n\n  for el in ${elements[@]}; do\n    if [[ \"${el}\" = \"${value}\" ]]; then\n      return 0\n    fi\n  done\n\n  return 1\n}\n\nfunction indexOf () {\n  local value=$1\n  shift\n  local elements=(\"$@\")\n\n  for i in \"${!elements[@]}\"; do\n    if [[ \"${elements[$i]}\" = \"${value}\" ]]; then\n      echo \"${i}\";\n      break;\n    fi\n  done\n}\n\nif [[ $# -eq 1 ]]; then\n    selectedProjectName=$1\nelse\n  projectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n\n    attachedSessionName=$(tmux display-message -p \\#S)\n    sessions=$(tmux list-session -F \\#S)\n    projectDisplayNames=()\n    projectNames=()\n\n    for key in ${projectPaths[@]}; do\n      value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n        projectNames+=($value)\n      if [[ $value == $attachedSessionName ]]; then \n        projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n      elif $(contains ${value} ${sessions[@]}); then \n        projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n      else\n        projectDisplayNames+=($value)\n      fi\n    done\n\n    selectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n\n    index=$(indexOf ${selectedProjectName} ${projectNames[@]})\n    selectedPath=\"${projectPaths[$index]}\"\nfi\n\nif [[ -z $selectedProjectName ]]; then\n    exit 0\nfi\n\nif ! $(contains ${selectedProjectName} ${sessions[@]} ); then\n  tmux new-session -ds $selectedProjectName -c $selectedPath\nfi\n\nif ! [[ -z $TMUX ]]; then\n  tmux switch-client -t $selectedProjectName\nelse\n  tmux attach-session -t=$selectedProjectName\nfi\n",[35,1352,1353,1357,1361,1366,1371,1376,1381,1386,1390,1395,1399,1404,1409,1414,1419,1424,1428,1432,1436,1440,1444,1448,1452,1456,1460,1464,1468,1472,1476,1480,1484,1488,1493,1498,1503,1508,1513,1518,1523,1528,1533,1538,1543,1548,1553,1559,1565,1571,1577,1582,1588,1594,1600,1606,1612,1617,1623,1628,1633,1639,1644,1649,1654,1659,1665,1671,1677,1683,1688,1693,1698,1703,1709,1715,1720,1726,1731,1737,1743,1749,1755,1760,1766,1772,1778,1784,1790,1796,1802,1808,1814,1820,1826,1831,1837,1842,1848,1854,1859,1864,1869,1874,1879,1884,1889,1894,1899,1904,1909,1914,1919,1924],{"__ignoreMap":54},[349,1354,1355],{"class":351,"line":352},[349,1356,869],{"class":380},[349,1358,1359],{"class":351,"line":55},[349,1360,480],{"emptyLinePlaceholder":63},[349,1362,1363],{"class":351,"line":372},[349,1364,1365],{"class":380},"function usage {\n",[349,1367,1368],{"class":351,"line":488},[349,1369,1370],{"class":380},"  echo \"Project Launcher\"\n",[349,1372,1373],{"class":351,"line":493},[349,1374,1375],{"class":380},"  echo \"\"\n",[349,1377,1378],{"class":351,"line":508},[349,1379,1380],{"class":380},"  echo \"Launch tmux session at your project directory or attach\u002Fswitch to an existing session\"\n",[349,1382,1383],{"class":351,"line":513},[349,1384,1385],{"class":380},"  echo \"Supports fuzzy search power by fzf in multiple project directories\"\n",[349,1387,1388],{"class":351,"line":927},[349,1389,1375],{"class":380},[349,1391,1392],{"class":351,"line":933},[349,1393,1394],{"class":380},"  echo \"Usage: $(basename $0) [-d \u003Carg>...] [--] [DIRECTORY...]\" 2>&1\n",[349,1396,1397],{"class":351,"line":939},[349,1398,1375],{"class":380},[349,1400,1401],{"class":351,"line":945},[349,1402,1403],{"class":380},"  echo \"projectPaths:\"\n",[349,1405,1406],{"class":351,"line":951},[349,1407,1408],{"class":380},"  echo \"   -d           add directory for fuzzy search\"\n",[349,1410,1411],{"class":351,"line":957},[349,1412,1413],{"class":380},"  echo \"   -h|--help    show usage\"\n",[349,1415,1416],{"class":351,"line":963},[349,1417,1418],{"class":380},"  exit 1\n",[349,1420,1421],{"class":351,"line":969},[349,1422,1423],{"class":380},"}\n",[349,1425,1426],{"class":351,"line":974},[349,1427,480],{"emptyLinePlaceholder":63},[349,1429,1430],{"class":351,"line":980},[349,1431,904],{"class":380},[349,1433,1434],{"class":351,"line":986},[349,1435,909],{"class":380},[349,1437,1438],{"class":351,"line":992},[349,1439,914],{"class":380},[349,1441,1442],{"class":351,"line":998},[349,1443,919],{"class":380},[349,1445,1446],{"class":351,"line":1004},[349,1447,924],{"class":380},[349,1449,1450],{"class":351,"line":1010},[349,1451,930],{"class":380},[349,1453,1454],{"class":351,"line":1015},[349,1455,936],{"class":380},[349,1457,1458],{"class":351,"line":1021},[349,1459,942],{"class":380},[349,1461,1462],{"class":351,"line":1027},[349,1463,948],{"class":380},[349,1465,1466],{"class":351,"line":1033},[349,1467,954],{"class":380},[349,1469,1470],{"class":351,"line":1038},[349,1471,960],{"class":380},[349,1473,1474],{"class":351,"line":1044},[349,1475,966],{"class":380},[349,1477,1478],{"class":351,"line":1050},[349,1479,942],{"class":380},[349,1481,1482],{"class":351,"line":1056},[349,1483,977],{"class":380},[349,1485,1486],{"class":351,"line":1061},[349,1487,983],{"class":380},[349,1489,1491],{"class":351,"line":1490},32,[349,1492,989],{"class":380},[349,1494,1496],{"class":351,"line":1495},33,[349,1497,995],{"class":380},[349,1499,1501],{"class":351,"line":1500},34,[349,1502,1001],{"class":380},[349,1504,1506],{"class":351,"line":1505},35,[349,1507,1007],{"class":380},[349,1509,1511],{"class":351,"line":1510},36,[349,1512,995],{"class":380},[349,1514,1516],{"class":351,"line":1515},37,[349,1517,1018],{"class":380},[349,1519,1521],{"class":351,"line":1520},38,[349,1522,1024],{"class":380},[349,1524,1526],{"class":351,"line":1525},39,[349,1527,1030],{"class":380},[349,1529,1531],{"class":351,"line":1530},40,[349,1532,995],{"class":380},[349,1534,1536],{"class":351,"line":1535},41,[349,1537,1041],{"class":380},[349,1539,1541],{"class":351,"line":1540},42,[349,1542,1047],{"class":380},[349,1544,1546],{"class":351,"line":1545},43,[349,1547,1053],{"class":380},[349,1549,1551],{"class":351,"line":1550},44,[349,1552,480],{"emptyLinePlaceholder":63},[349,1554,1556],{"class":351,"line":1555},45,[349,1557,1558],{"class":380},"function contains () {\n",[349,1560,1562],{"class":351,"line":1561},46,[349,1563,1564],{"class":380},"  local value=$1\n",[349,1566,1568],{"class":351,"line":1567},47,[349,1569,1570],{"class":380},"  shift\n",[349,1572,1574],{"class":351,"line":1573},48,[349,1575,1576],{"class":380},"  local elements=(\"$@\")\n",[349,1578,1580],{"class":351,"line":1579},49,[349,1581,480],{"emptyLinePlaceholder":63},[349,1583,1585],{"class":351,"line":1584},50,[349,1586,1587],{"class":380},"  for el in ${elements[@]}; do\n",[349,1589,1591],{"class":351,"line":1590},51,[349,1592,1593],{"class":380},"    if [[ \"${el}\" = \"${value}\" ]]; then\n",[349,1595,1597],{"class":351,"line":1596},52,[349,1598,1599],{"class":380},"      return 0\n",[349,1601,1603],{"class":351,"line":1602},53,[349,1604,1605],{"class":380},"    fi\n",[349,1607,1609],{"class":351,"line":1608},54,[349,1610,1611],{"class":380},"  done\n",[349,1613,1615],{"class":351,"line":1614},55,[349,1616,480],{"emptyLinePlaceholder":63},[349,1618,1620],{"class":351,"line":1619},56,[349,1621,1622],{"class":380},"  return 1\n",[349,1624,1626],{"class":351,"line":1625},57,[349,1627,1423],{"class":380},[349,1629,1631],{"class":351,"line":1630},58,[349,1632,480],{"emptyLinePlaceholder":63},[349,1634,1636],{"class":351,"line":1635},59,[349,1637,1638],{"class":380},"function indexOf () {\n",[349,1640,1642],{"class":351,"line":1641},60,[349,1643,1564],{"class":380},[349,1645,1647],{"class":351,"line":1646},61,[349,1648,1570],{"class":380},[349,1650,1652],{"class":351,"line":1651},62,[349,1653,1576],{"class":380},[349,1655,1657],{"class":351,"line":1656},63,[349,1658,480],{"emptyLinePlaceholder":63},[349,1660,1662],{"class":351,"line":1661},64,[349,1663,1664],{"class":380},"  for i in \"${!elements[@]}\"; do\n",[349,1666,1668],{"class":351,"line":1667},65,[349,1669,1670],{"class":380},"    if [[ \"${elements[$i]}\" = \"${value}\" ]]; then\n",[349,1672,1674],{"class":351,"line":1673},66,[349,1675,1676],{"class":380},"      echo \"${i}\";\n",[349,1678,1680],{"class":351,"line":1679},67,[349,1681,1682],{"class":380},"      break;\n",[349,1684,1686],{"class":351,"line":1685},68,[349,1687,1605],{"class":380},[349,1689,1691],{"class":351,"line":1690},69,[349,1692,1611],{"class":380},[349,1694,1696],{"class":351,"line":1695},70,[349,1697,1423],{"class":380},[349,1699,1701],{"class":351,"line":1700},71,[349,1702,480],{"emptyLinePlaceholder":63},[349,1704,1706],{"class":351,"line":1705},72,[349,1707,1708],{"class":380},"if [[ $# -eq 1 ]]; then\n",[349,1710,1712],{"class":351,"line":1711},73,[349,1713,1714],{"class":380},"    selectedProjectName=$1\n",[349,1716,1718],{"class":351,"line":1717},74,[349,1719,1331],{"class":380},[349,1721,1723],{"class":351,"line":1722},75,[349,1724,1725],{"class":380},"  projectPaths=($(find ${multi[@]} -mindepth 1 -maxdepth 1 -type d))\n",[349,1727,1729],{"class":351,"line":1728},76,[349,1730,480],{"emptyLinePlaceholder":63},[349,1732,1734],{"class":351,"line":1733},77,[349,1735,1736],{"class":380},"    attachedSessionName=$(tmux display-message -p \\#S)\n",[349,1738,1740],{"class":351,"line":1739},78,[349,1741,1742],{"class":380},"    sessions=$(tmux list-session -F \\#S)\n",[349,1744,1746],{"class":351,"line":1745},79,[349,1747,1748],{"class":380},"    projectDisplayNames=()\n",[349,1750,1752],{"class":351,"line":1751},80,[349,1753,1754],{"class":380},"    projectNames=()\n",[349,1756,1758],{"class":351,"line":1757},81,[349,1759,480],{"emptyLinePlaceholder":63},[349,1761,1763],{"class":351,"line":1762},82,[349,1764,1765],{"class":380},"    for key in ${projectPaths[@]}; do\n",[349,1767,1769],{"class":351,"line":1768},83,[349,1770,1771],{"class":380},"      value=$(basename \"$(dirname \"${key}\")\")\"\u002F\"$(basename \"${key}\")\n",[349,1773,1775],{"class":351,"line":1774},84,[349,1776,1777],{"class":380},"        projectNames+=($value)\n",[349,1779,1781],{"class":351,"line":1780},85,[349,1782,1783],{"class":380},"      if [[ $value == $attachedSessionName ]]; then \n",[349,1785,1787],{"class":351,"line":1786},86,[349,1788,1789],{"class":380},"        projectDisplayNames+=(\"\u001b[33m$value\u001b[0m\")\n",[349,1791,1793],{"class":351,"line":1792},87,[349,1794,1795],{"class":380},"      elif $(contains ${value} ${sessions[@]}); then \n",[349,1797,1799],{"class":351,"line":1798},88,[349,1800,1801],{"class":380},"        projectDisplayNames+=(\"\u001b[34m$value\u001b[0m\")\n",[349,1803,1805],{"class":351,"line":1804},89,[349,1806,1807],{"class":380},"      else\n",[349,1809,1811],{"class":351,"line":1810},90,[349,1812,1813],{"class":380},"        projectDisplayNames+=($value)\n",[349,1815,1817],{"class":351,"line":1816},91,[349,1818,1819],{"class":380},"      fi\n",[349,1821,1823],{"class":351,"line":1822},92,[349,1824,1825],{"class":380},"    done\n",[349,1827,1829],{"class":351,"line":1828},93,[349,1830,480],{"emptyLinePlaceholder":63},[349,1832,1834],{"class":351,"line":1833},94,[349,1835,1836],{"class":380},"    selectedProjectName=$(printf \"%s\\n\" \"${projectDisplayNames[@]}\" | fzf --ansi)\n",[349,1838,1840],{"class":351,"line":1839},95,[349,1841,480],{"emptyLinePlaceholder":63},[349,1843,1845],{"class":351,"line":1844},96,[349,1846,1847],{"class":380},"    index=$(indexOf ${selectedProjectName} ${projectNames[@]})\n",[349,1849,1851],{"class":351,"line":1850},97,[349,1852,1853],{"class":380},"    selectedPath=\"${projectPaths[$index]}\"\n",[349,1855,1857],{"class":351,"line":1856},98,[349,1858,1294],{"class":380},[349,1860,1862],{"class":351,"line":1861},99,[349,1863,480],{"emptyLinePlaceholder":63},[349,1865,1867],{"class":351,"line":1866},100,[349,1868,1284],{"class":380},[349,1870,1872],{"class":351,"line":1871},101,[349,1873,1289],{"class":380},[349,1875,1877],{"class":351,"line":1876},102,[349,1878,1294],{"class":380},[349,1880,1882],{"class":351,"line":1881},103,[349,1883,480],{"emptyLinePlaceholder":63},[349,1885,1887],{"class":351,"line":1886},104,[349,1888,1303],{"class":380},[349,1890,1892],{"class":351,"line":1891},105,[349,1893,1308],{"class":380},[349,1895,1897],{"class":351,"line":1896},106,[349,1898,1294],{"class":380},[349,1900,1902],{"class":351,"line":1901},107,[349,1903,480],{"emptyLinePlaceholder":63},[349,1905,1907],{"class":351,"line":1906},108,[349,1908,1321],{"class":380},[349,1910,1912],{"class":351,"line":1911},109,[349,1913,1326],{"class":380},[349,1915,1917],{"class":351,"line":1916},110,[349,1918,1331],{"class":380},[349,1920,1922],{"class":351,"line":1921},111,[349,1923,1336],{"class":380},[349,1925,1927],{"class":351,"line":1926},112,[349,1928,1294],{"class":380},[11,1930,1931,1932,216],{},"to use the program we have writen you can run ",[35,1933,1934],{},"project-launcher -d ~\u002Fprojects\u002Fpersonal\u002F -d ~\u002Fprojects\u002Fwork",[11,1936,1937,1938,1940],{},"I prever to put this command behind an alias in my ",[35,1939,296],{}," like so",[341,1942,1944],{"className":860,"code":1943,"language":862,"meta":54,"style":54},"...\n\nalias p=\"project-launcher -d ~\u002Fprojects\u002Fpersonal\u002F -d ~\u002Fprojects\u002Fwork\"\n\n...\n",[35,1945,1946,1950,1954,1959,1963],{"__ignoreMap":54},[349,1947,1948],{"class":351,"line":352},[349,1949,485],{"class":380},[349,1951,1952],{"class":351,"line":55},[349,1953,480],{"emptyLinePlaceholder":63},[349,1955,1956],{"class":351,"line":372},[349,1957,1958],{"class":380},"alias p=\"project-launcher -d ~\u002Fprojects\u002Fpersonal\u002F -d ~\u002Fprojects\u002Fwork\"\n",[349,1960,1961],{"class":351,"line":488},[349,1962,480],{"emptyLinePlaceholder":63},[349,1964,1965],{"class":351,"line":493},[349,1966,485],{"class":380},[256,1968,1969],{"id":721},"Wrapping Up",[11,1971,1972],{},"I've been using this little script for a few weeks, and I must say, I'm committed to continuing using tmux this time. I hope that this serves as motivation for you to also develop your personal tools, ultimately enhancing both your productivity and workflow.",[256,1974,732],{"id":731},[128,1976,1977],{},[131,1978,1979,740,1981],{},[349,1980,739],{},[15,1982,1985],{"href":1983,"rel":1984},"https:\u002F\u002Fgithub.com\u002FThePrimeagen\u002F.dotfiles\u002Fblob\u002Fdbfcb9f56e74e035212dcfdeb1675583d13210c6\u002Fbin\u002F.local\u002Fbin\u002Ftmux-sessionizer",[19],"https:\u002F\u002Fgithub.com\u002FThePrimeagen\u002F.dotfiles",[764,1987,1988],{},"html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":54,"searchDepth":55,"depth":55,"links":1990},[1991,1992,1993],{"id":1343,"depth":55,"text":1344},{"id":721,"depth":55,"text":1969},{"id":731,"depth":55,"text":732},"2022-07-27","I found myself growing increasingly frustrated with the need to rapidly switch between multiple coding projects. To tackle this, I resorted to managing various terminal sessions, utilizing Amethyst – a tiling window manager for macOS. The challenge arose when these sessions began to stack up, often reaching three or more terminals in full-screen mode, making it easy to lose track of which window corresponded to which project.","\u002Fimages\u002Fbuild-a-tmux-project-launcher.png",{"slug":1998},"build-a-tmux-project-launcher","\u002Farticles\u002Ftmux-project-laucher",{"title":795,"description":1995},"Build a Tmux project laucher in shell script in a few minutes.","articles\u002Ftmux-project-laucher",[790,819,789,788],"vKLt6oJTDl6uLO-TmTxnX7IRceTWTBpgelhicfsSrxE",{"id":2006,"title":2007,"body":2008,"date":2057,"description":2012,"extension":59,"image":2058,"meta":2059,"navigation":63,"path":2061,"published":63,"seo":2062,"snippet":2012,"stem":2063,"tags":2064,"video":54,"__hash__":2065},"articles\u002Farticles\u002Fnew-blog.md","New blog",{"type":8,"value":2009,"toc":2055},[2010,2013,2016,2027,2030,2044,2047,2050],[11,2011,2012],{},"It was time for a change. A post on how I simplefied my blog so its less about maintain a website and more about posting.",[11,2014,2015],{},"Initially, I thought that WordPress would offer the quickest and easiest solution for sharing my publications. I couldn't have been more mistaken. WordPress, with its myriad features, wasn't the right fit for me. I prefer to steer clear of it in the future. Several aspects particularly bothered me:",[128,2017,2018,2021,2024],{},[131,2019,2020],{},"The lack of a user-friendly method to construct custom themes",[131,2022,2023],{},"Sluggish performance",[131,2025,2026],{},"A never-ending cascade of plugins...",[11,2028,2029],{},"Goals for the new blog:",[128,2031,2032,2035,2038,2041],{},[131,2033,2034],{},"Static site generation",[131,2036,2037],{},"Generated from markdown",[131,2039,2040],{},"Simplified maintenance",[131,2042,2043],{},"Incorporation of a dedicated portfolio section",[11,2045,2046],{},"In the past, I've dabbled with Angular 1, 2, and React. However, I ultimately settled on Vue as my favored frontend framework. Initially, Nuxt was my top pick, but after conducting thorough research, I stumbled upon Gridsome, which proved to be remarkably straightforward to set up and populate with content.",[11,2048,2049],{},"to be continued...",[11,2051,47,2052],{},[15,2053,52],{"href":50,"rel":2054},[19],{"title":54,"searchDepth":55,"depth":55,"links":2056},[],"2021-04-12","\u002Fimages\u002Ftest.png",{"slug":2060},"new-blog","\u002Farticles\u002Fnew-blog",{"title":2007,"description":2012},"articles\u002Fnew-blog",[69],"C_-WeIAM1zNoSREMHJRX4JZsKdEExQJdNFgzfsqhsjQ",{"id":2067,"title":2068,"body":2069,"date":3906,"description":2077,"extension":59,"image":3907,"meta":3908,"navigation":63,"path":3910,"published":63,"seo":3911,"snippet":3912,"stem":3913,"tags":3914,"video":231,"__hash__":3916},"articles\u002Farticles\u002Fa-generic-object-pool-for-unity3d.md","A Generic Object Pool for Unity3D",{"type":8,"value":2070,"toc":3903},[2071,2075,2078,2082,2099,2101,2104,2107,2123,2125,2136,2188,2203,2276,2282,2285,2354,2357,2488,2491,2537,2548,2582,2593,2664,2675,2955,2969,3222,3225,3228,3258,3267,3301,3304,3309,3317,3326,3554,3560,3881,3883,3891,3894,3897,3900],[799,2072,2074],{"id":2073},"what-is-an-object-pool","What is an object pool?",[11,2076,2077],{},"An object pool is a design pattern where a set of initialized objects is kept ready for use. Rather than instantiating and destroying objects you request an available object from the pool or release an object back to the pool for reuse later.",[799,2079,2081],{"id":2080},"why-use-object-pooling","Why use object pooling?",[11,2083,2084,2085,184,2095,2098],{},"Most of us will encounter somewhere along the way developing games in Unity3D the performance hit by calling ",[35,2086,2089,2092],{"className":2087,"language":2088,"style":54},"language-csharp shiki shiki-themes github-light github-dark","csharp",[349,2090,2091],{"class":355},"Instantiate",[349,2093,2094],{"class":414},"()",[35,2096,2097],{},"Destroy()"," in large quantities. A object pool can mitigate this problem.",[799,2100,802],{"id":801},[11,2102,2103],{},"There are a lot of great tutorials out there for writing your very first object pool and develop better understanding of the concept. However what you see in most tutorials are written in such a way that only capable of pooling GameObject derived classes as its members and tracks the availability of its members by MonoBehaviour.enabled field which in most situations I prefer to avoid.",[11,2105,2106],{},"The goal of this tutorial is to write a generic implementation of an object pool that is more reusable and applicable for a wider range of use cases.",[2108,2109,2110],"blockquote",{},[11,2111,2112,2116,2117,2122],{},[2113,2114,2115],"strong",{},"What are generic types?"," A generic type is a placeholder that allows you to write classes or interfaces without directly specifying the type of its Fields Methods, and Parameters beforehand. This powerful feature of C# allows us to write more reusable code. Checkout ",[15,2118,2121],{"href":2119,"rel":2120},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fdotnet\u002Fstandard\u002Fgenerics\u002F",[19],"Introduction to Generics"," for more information on generic type.",[799,2124,850],{"id":849},[11,2126,2127,2128,2131,2132,2135],{},"First of lets import ",[35,2129,2130],{},"System.Collections.Generic"," and create a generic ",[35,2133,2134],{},"Pool\u003CT>"," class.",[341,2137,2141],{"className":2087,"code":2138,"filename":2139,"language":2088,"meta":2140,"style":54},"using System.Collections.Generic;\n\npublic class Pool\u003CT> {}\n","file.js","meta-info=val",[35,2142,2143,2164,2168],{"__ignoreMap":54},[349,2144,2145,2148,2151,2153,2156,2158,2161],{"class":351,"line":352},[349,2146,2147],{"class":407},"using",[349,2149,2150],{"class":355}," System",[349,2152,216],{"class":414},[349,2154,2155],{"class":355},"Collections",[349,2157,216],{"class":414},[349,2159,2160],{"class":355},"Generic",[349,2162,2163],{"class":414},";\n",[349,2165,2166],{"class":351,"line":55},[349,2167,480],{"emptyLinePlaceholder":63},[349,2169,2170,2173,2176,2179,2182,2185],{"class":351,"line":372},[349,2171,2172],{"class":407},"public",[349,2174,2175],{"class":407}," class",[349,2177,2178],{"class":355}," Pool",[349,2180,2181],{"class":414},"\u003C",[349,2183,2184],{"class":355},"T",[349,2186,2187],{"class":414},"> {}\n",[11,2189,2190,2191,2194,2195,2198,2199,2202],{},"We want to add three fields, ",[2113,2192,2193],{},"members"," which is a list of members of the pool, ",[2113,2196,2197],{},"unavailable"," to check if a member is already in use and ",[2113,2200,2201],{},"factory"," which will be responsible for creating new member instances.",[341,2204,2206],{"className":2087,"code":2205,"language":2088,"meta":54,"style":54},"public List\u003CT> members = new List\u003CT>();\npublic HashSet\u003CT> unavailable = new HashSet\u003CT>();\nIFactory factory;\n",[35,2207,2208,2239,2266],{"__ignoreMap":54},[349,2209,2210,2212,2215,2217,2219,2222,2224,2227,2230,2232,2234,2236],{"class":351,"line":352},[349,2211,2172],{"class":407},[349,2213,2214],{"class":355}," List",[349,2216,2181],{"class":414},[349,2218,2184],{"class":355},[349,2220,2221],{"class":414},"> ",[349,2223,2193],{"class":355},[349,2225,2226],{"class":407}," =",[349,2228,2229],{"class":407}," new",[349,2231,2214],{"class":355},[349,2233,2181],{"class":414},[349,2235,2184],{"class":355},[349,2237,2238],{"class":414},">();\n",[349,2240,2241,2243,2246,2248,2250,2252,2254,2256,2258,2260,2262,2264],{"class":351,"line":55},[349,2242,2172],{"class":407},[349,2244,2245],{"class":355}," HashSet",[349,2247,2181],{"class":414},[349,2249,2184],{"class":355},[349,2251,2221],{"class":414},[349,2253,2197],{"class":355},[349,2255,2226],{"class":407},[349,2257,2229],{"class":407},[349,2259,2245],{"class":355},[349,2261,2181],{"class":414},[349,2263,2184],{"class":355},[349,2265,2238],{"class":414},[349,2267,2268,2271,2274],{"class":351,"line":372},[349,2269,2270],{"class":355},"IFactory",[349,2272,2273],{"class":355}," factory",[349,2275,2163],{"class":414},[11,2277,2278,2279,2281],{},"Don’t mind ",[35,2280,2270],{}," for now, we will come back to that later",[11,2283,2284],{},"Next up are methods, we need one for creating new members with the factory and adding it to the list of members.",[341,2286,2288],{"className":2087,"code":2287,"language":2088,"meta":54,"style":54},"T Create() {\n    T member = factory.Create();\n    member.myPool = this;\n    members.Add(member);\n    return member;\n}\n",[35,2289,2290,2300,2319,2331,2342,2350],{"__ignoreMap":54},[349,2291,2292,2294,2297],{"class":351,"line":352},[349,2293,2184],{"class":355},[349,2295,2296],{"class":355}," Create",[349,2298,2299],{"class":414},"() {\n",[349,2301,2302,2305,2308,2310,2313,2316],{"class":351,"line":55},[349,2303,2304],{"class":355},"    T",[349,2306,2307],{"class":355}," member",[349,2309,2226],{"class":407},[349,2311,2312],{"class":414}," factory.",[349,2314,2315],{"class":355},"Create",[349,2317,2318],{"class":414},"();\n",[349,2320,2321,2324,2326,2329],{"class":351,"line":372},[349,2322,2323],{"class":414},"    member.myPool ",[349,2325,502],{"class":407},[349,2327,2328],{"class":380}," this",[349,2330,2163],{"class":414},[349,2332,2333,2336,2339],{"class":351,"line":488},[349,2334,2335],{"class":414},"    members.",[349,2337,2338],{"class":355},"Add",[349,2340,2341],{"class":414},"(member);\n",[349,2343,2344,2347],{"class":351,"line":493},[349,2345,2346],{"class":407},"    return",[349,2348,2349],{"class":414}," member;\n",[349,2351,2352],{"class":351,"line":508},[349,2353,1423],{"class":414},[11,2355,2356],{},"Another method for allocation that returns an available member and if there are none available we should create a new one with the factory. Before returning a member it should be tracked as unavailable with the unavailable hash set.",[341,2358,2360],{"className":2087,"code":2359,"language":2088,"meta":54,"style":54},"public T Allocate() {\n    for(int i = 0; i \u003C members.Count; i++) {\n        if(!unavailable.Contains(members[i])) {\n            unavailable.Add(members[i]);\n            return members[i];\n        }\n    }\n    T newMembers = Create();\n    unavailable.Add(newMembers);\n    return newMembers;\n}\n",[35,2361,2362,2374,2407,2426,2436,2444,2449,2454,2467,2477,2484],{"__ignoreMap":54},[349,2363,2364,2366,2369,2372],{"class":351,"line":352},[349,2365,2172],{"class":407},[349,2367,2368],{"class":355}," T",[349,2370,2371],{"class":355}," Allocate",[349,2373,2299],{"class":414},[349,2375,2376,2379,2382,2385,2388,2390,2393,2396,2398,2401,2404],{"class":351,"line":55},[349,2377,2378],{"class":407},"    for",[349,2380,2381],{"class":414},"(",[349,2383,2384],{"class":407},"int",[349,2386,2387],{"class":355}," i",[349,2389,2226],{"class":407},[349,2391,2392],{"class":380}," 0",[349,2394,2395],{"class":414},"; i ",[349,2397,2181],{"class":407},[349,2399,2400],{"class":414}," members.Count; i",[349,2402,2403],{"class":407},"++",[349,2405,2406],{"class":414},") {\n",[349,2408,2409,2412,2414,2417,2420,2423],{"class":351,"line":372},[349,2410,2411],{"class":407},"        if",[349,2413,2381],{"class":414},[349,2415,2416],{"class":407},"!",[349,2418,2419],{"class":414},"unavailable.",[349,2421,2422],{"class":355},"Contains",[349,2424,2425],{"class":414},"(members[i])) {\n",[349,2427,2428,2431,2433],{"class":351,"line":488},[349,2429,2430],{"class":414},"            unavailable.",[349,2432,2338],{"class":355},[349,2434,2435],{"class":414},"(members[i]);\n",[349,2437,2438,2441],{"class":351,"line":493},[349,2439,2440],{"class":407},"            return",[349,2442,2443],{"class":414}," members[i];\n",[349,2445,2446],{"class":351,"line":508},[349,2447,2448],{"class":414},"        }\n",[349,2450,2451],{"class":351,"line":513},[349,2452,2453],{"class":414},"    }\n",[349,2455,2456,2458,2461,2463,2465],{"class":351,"line":927},[349,2457,2304],{"class":355},[349,2459,2460],{"class":355}," newMembers",[349,2462,2226],{"class":407},[349,2464,2296],{"class":355},[349,2466,2318],{"class":414},[349,2468,2469,2472,2474],{"class":351,"line":933},[349,2470,2471],{"class":414},"    unavailable.",[349,2473,2338],{"class":355},[349,2475,2476],{"class":414},"(newMembers);\n",[349,2478,2479,2481],{"class":351,"line":939},[349,2480,2346],{"class":407},[349,2482,2483],{"class":414}," newMembers;\n",[349,2485,2486],{"class":351,"line":945},[349,2487,1423],{"class":414},[11,2489,2490],{},"And one last method for releasing that returns a member to its initial state and unmarks it as unavailable.",[341,2492,2494],{"className":2087,"code":2493,"language":2088,"meta":54,"style":54},"public void Release(T member) {\n    member.Reset();\n    unavailable.Remove(member);\n}\n",[35,2495,2496,2514,2524,2533],{"__ignoreMap":54},[349,2497,2498,2500,2503,2506,2508,2510,2512],{"class":351,"line":352},[349,2499,2172],{"class":407},[349,2501,2502],{"class":407}," void",[349,2504,2505],{"class":355}," Release",[349,2507,2381],{"class":414},[349,2509,2184],{"class":355},[349,2511,2307],{"class":355},[349,2513,2406],{"class":414},[349,2515,2516,2519,2522],{"class":351,"line":55},[349,2517,2518],{"class":414},"    member.",[349,2520,2521],{"class":355},"Reset",[349,2523,2318],{"class":414},[349,2525,2526,2528,2531],{"class":351,"line":372},[349,2527,2471],{"class":414},[349,2529,2530],{"class":355},"Remove",[349,2532,2341],{"class":414},[349,2534,2535],{"class":351,"line":488},[349,2536,1423],{"class":414},[11,2538,2539,2540,2542,2543,2545,2546,216],{},"Let’s get back to ",[35,2541,2270],{}," and create a ",[35,2544,2270],{}," interface. with a create method that returns a new instance of type ",[35,2547,2184],{},[341,2549,2551],{"className":2087,"code":2550,"language":2088,"meta":54,"style":54},"public interface IFactory\u003CT> {\n    T Create();\n}\n",[35,2552,2553,2570,2578],{"__ignoreMap":54},[349,2554,2555,2557,2560,2563,2565,2567],{"class":351,"line":352},[349,2556,2172],{"class":407},[349,2558,2559],{"class":407}," interface",[349,2561,2562],{"class":355}," IFactory",[349,2564,2181],{"class":414},[349,2566,2184],{"class":355},[349,2568,2569],{"class":414},"> {\n",[349,2571,2572,2574,2576],{"class":351,"line":55},[349,2573,2304],{"class":355},[349,2575,2296],{"class":355},[349,2577,2318],{"class":414},[349,2579,2580],{"class":351,"line":372},[349,2581,1423],{"class":414},[11,2583,2584,2585,2588,2589,2592],{},"That’s it, now we can create a ",[35,2586,2587],{},"Factory\u003CT>"," that implements this ",[35,2590,2591],{},"IFactory\u003CT>"," interface.",[341,2594,2596],{"className":2087,"code":2595,"language":2088,"meta":54,"style":54},"public class Factory\u003CT> : IFactory\u003CT> where T : new() {\n    public T Create() {\n    return new T();\n    }\n}\n",[35,2597,2598,2635,2646,2656,2660],{"__ignoreMap":54},[349,2599,2600,2602,2604,2607,2609,2611,2614,2616,2618,2620,2622,2625,2627,2630,2633],{"class":351,"line":352},[349,2601,2172],{"class":407},[349,2603,2175],{"class":407},[349,2605,2606],{"class":355}," Factory",[349,2608,2181],{"class":414},[349,2610,2184],{"class":355},[349,2612,2613],{"class":414},"> : ",[349,2615,2270],{"class":355},[349,2617,2181],{"class":414},[349,2619,2184],{"class":355},[349,2621,2221],{"class":414},[349,2623,2624],{"class":407},"where",[349,2626,2368],{"class":355},[349,2628,2629],{"class":414}," : ",[349,2631,2632],{"class":407},"new",[349,2634,2299],{"class":414},[349,2636,2637,2640,2642,2644],{"class":351,"line":55},[349,2638,2639],{"class":407},"    public",[349,2641,2368],{"class":355},[349,2643,2296],{"class":355},[349,2645,2299],{"class":414},[349,2647,2648,2650,2652,2654],{"class":351,"line":372},[349,2649,2346],{"class":407},[349,2651,2229],{"class":407},[349,2653,2368],{"class":355},[349,2655,2318],{"class":414},[349,2657,2658],{"class":351,"line":488},[349,2659,2453],{"class":414},[349,2661,2662],{"class":351,"line":493},[349,2663,1423],{"class":414},[11,2665,2666,2667,2670,2671,2674],{},"This is cool and all but you must be thinking this won’t work for a ",[35,2668,2669],{},"MonoBehaviour"," derived class and you’re right. So let’s create another factory called ",[35,2672,2673],{},"MonoBehaviourFactory\u003CT>"," for this use case.",[341,2676,2678],{"className":2087,"code":2677,"language":2088,"meta":54,"style":54},"using UnityEngine;\n\npublic class MonoBehaviourFactory\u003CT> : IFactory\u003CT> where T : MonoBehaviour {\n\n    GameObject prefab;\n    string name;\n    int index = 0;\n\n    public MonoBehaviourFactory() : this(\"MonoBehaviour\") { }\n\n    public MonoBehaviourFactory(string name) {\n    this.name = name;\n    }\n\n    public T Create() {\n        GameObject tempGameObject = GameObject.Instantiate(new GameObject()) as GameObject;\n\n        tempGameObject.name = name + index.ToString();\n    tempGameObject.AddComponent\u003CT>();\n    T objectOfType = tempGameObject.GetComponent\u003CT>();\n    index++;\n    return objectOfType;\n    }\n}\n",[35,2679,2680,2689,2693,2727,2731,2741,2751,2765,2769,2789,2793,2808,2821,2825,2829,2839,2871,2875,2896,2910,2931,2940,2947,2951],{"__ignoreMap":54},[349,2681,2682,2684,2687],{"class":351,"line":352},[349,2683,2147],{"class":407},[349,2685,2686],{"class":355}," UnityEngine",[349,2688,2163],{"class":414},[349,2690,2691],{"class":351,"line":55},[349,2692,480],{"emptyLinePlaceholder":63},[349,2694,2695,2697,2699,2702,2704,2706,2708,2710,2712,2714,2716,2718,2720,2722,2724],{"class":351,"line":372},[349,2696,2172],{"class":407},[349,2698,2175],{"class":407},[349,2700,2701],{"class":355}," MonoBehaviourFactory",[349,2703,2181],{"class":414},[349,2705,2184],{"class":355},[349,2707,2613],{"class":414},[349,2709,2270],{"class":355},[349,2711,2181],{"class":414},[349,2713,2184],{"class":355},[349,2715,2221],{"class":414},[349,2717,2624],{"class":407},[349,2719,2368],{"class":355},[349,2721,2629],{"class":414},[349,2723,2669],{"class":355},[349,2725,2726],{"class":414}," {\n",[349,2728,2729],{"class":351,"line":488},[349,2730,480],{"emptyLinePlaceholder":63},[349,2732,2733,2736,2739],{"class":351,"line":493},[349,2734,2735],{"class":355},"    GameObject",[349,2737,2738],{"class":355}," prefab",[349,2740,2163],{"class":414},[349,2742,2743,2746,2749],{"class":351,"line":508},[349,2744,2745],{"class":407},"    string",[349,2747,2748],{"class":355}," name",[349,2750,2163],{"class":414},[349,2752,2753,2756,2759,2761,2763],{"class":351,"line":513},[349,2754,2755],{"class":407},"    int",[349,2757,2758],{"class":355}," index",[349,2760,2226],{"class":407},[349,2762,2392],{"class":380},[349,2764,2163],{"class":414},[349,2766,2767],{"class":351,"line":927},[349,2768,480],{"emptyLinePlaceholder":63},[349,2770,2771,2773,2775,2778,2781,2783,2786],{"class":351,"line":933},[349,2772,2639],{"class":407},[349,2774,2701],{"class":355},[349,2776,2777],{"class":414},"() : ",[349,2779,2780],{"class":380},"this",[349,2782,2381],{"class":414},[349,2784,2785],{"class":358},"\"MonoBehaviour\"",[349,2787,2788],{"class":414},") { }\n",[349,2790,2791],{"class":351,"line":939},[349,2792,480],{"emptyLinePlaceholder":63},[349,2794,2795,2797,2799,2801,2804,2806],{"class":351,"line":945},[349,2796,2639],{"class":407},[349,2798,2701],{"class":355},[349,2800,2381],{"class":414},[349,2802,2803],{"class":407},"string",[349,2805,2748],{"class":355},[349,2807,2406],{"class":414},[349,2809,2810,2813,2816,2818],{"class":351,"line":951},[349,2811,2812],{"class":380},"    this",[349,2814,2815],{"class":414},".name ",[349,2817,502],{"class":407},[349,2819,2820],{"class":414}," name;\n",[349,2822,2823],{"class":351,"line":957},[349,2824,2453],{"class":414},[349,2826,2827],{"class":351,"line":963},[349,2828,480],{"emptyLinePlaceholder":63},[349,2830,2831,2833,2835,2837],{"class":351,"line":969},[349,2832,2639],{"class":407},[349,2834,2368],{"class":355},[349,2836,2296],{"class":355},[349,2838,2299],{"class":414},[349,2840,2841,2844,2847,2849,2852,2854,2856,2858,2861,2864,2867,2869],{"class":351,"line":974},[349,2842,2843],{"class":355},"        GameObject",[349,2845,2846],{"class":355}," tempGameObject",[349,2848,2226],{"class":407},[349,2850,2851],{"class":414}," GameObject.",[349,2853,2091],{"class":355},[349,2855,2381],{"class":414},[349,2857,2632],{"class":407},[349,2859,2860],{"class":355}," GameObject",[349,2862,2863],{"class":414},"()) ",[349,2865,2866],{"class":407},"as",[349,2868,2860],{"class":355},[349,2870,2163],{"class":414},[349,2872,2873],{"class":351,"line":980},[349,2874,480],{"emptyLinePlaceholder":63},[349,2876,2877,2880,2882,2885,2888,2891,2894],{"class":351,"line":986},[349,2878,2879],{"class":414},"        tempGameObject.name ",[349,2881,502],{"class":407},[349,2883,2884],{"class":414}," name ",[349,2886,2887],{"class":407},"+",[349,2889,2890],{"class":414}," index.",[349,2892,2893],{"class":355},"ToString",[349,2895,2318],{"class":414},[349,2897,2898,2901,2904,2906,2908],{"class":351,"line":992},[349,2899,2900],{"class":414},"    tempGameObject.",[349,2902,2903],{"class":355},"AddComponent",[349,2905,2181],{"class":414},[349,2907,2184],{"class":355},[349,2909,2238],{"class":414},[349,2911,2912,2914,2917,2919,2922,2925,2927,2929],{"class":351,"line":998},[349,2913,2304],{"class":355},[349,2915,2916],{"class":355}," objectOfType",[349,2918,2226],{"class":407},[349,2920,2921],{"class":414}," tempGameObject.",[349,2923,2924],{"class":355},"GetComponent",[349,2926,2181],{"class":414},[349,2928,2184],{"class":355},[349,2930,2238],{"class":414},[349,2932,2933,2936,2938],{"class":351,"line":1004},[349,2934,2935],{"class":414},"    index",[349,2937,2403],{"class":407},[349,2939,2163],{"class":414},[349,2941,2942,2944],{"class":351,"line":1010},[349,2943,2346],{"class":407},[349,2945,2946],{"class":414}," objectOfType;\n",[349,2948,2949],{"class":351,"line":1015},[349,2950,2453],{"class":414},[349,2952,2953],{"class":351,"line":1021},[349,2954,1423],{"class":414},[11,2956,2957,2958,2960,2961,2964,2965,2968],{},"This should get you pretty far but what if you need a pool of complex prefabs? Let’s make a copy of ",[35,2959,2673],{}," and rename it ",[35,2962,2963],{},"PrefabFactory\u003CT>",". The only change we’ll have to make is passing the prefab through the constructor and instantiate that instead of a new ",[35,2966,2967],{},"GameObject()"," like so.",[341,2970,2972],{"className":2087,"code":2971,"language":2088,"meta":54,"style":54},"using UnityEngine;\n\npublic class PrefabFactory\u003CT> : IFactory\u003CT> where T : MonoBehaviour {\n\n    GameObject prefab;\n    string name;\n    int index = 0;\n\n    public PrefabFactory(GameObject prefab) : this(prefab, prefab.name) { }\n\n    public PrefabFactory(GameObject prefab, string name) {\n        this.prefab = prefab;\n        this.name = name;\n    }\n\n    public T Create() {\n        GameObject tempGameObject = GameObject.Instantiate(prefab) as GameObject;\n        tempGameObject.name = name + index.ToString();\n        T objectOfType = tempGameObject.GetComponent\u003CT>();\n        index++;\n        return objectOfType;\n    }\n}\n",[35,2973,2974,2982,2986,3019,3023,3031,3039,3051,3055,3076,3080,3101,3114,3124,3128,3132,3142,3163,3179,3198,3207,3214,3218],{"__ignoreMap":54},[349,2975,2976,2978,2980],{"class":351,"line":352},[349,2977,2147],{"class":407},[349,2979,2686],{"class":355},[349,2981,2163],{"class":414},[349,2983,2984],{"class":351,"line":55},[349,2985,480],{"emptyLinePlaceholder":63},[349,2987,2988,2990,2992,2995,2997,2999,3001,3003,3005,3007,3009,3011,3013,3015,3017],{"class":351,"line":372},[349,2989,2172],{"class":407},[349,2991,2175],{"class":407},[349,2993,2994],{"class":355}," PrefabFactory",[349,2996,2181],{"class":414},[349,2998,2184],{"class":355},[349,3000,2613],{"class":414},[349,3002,2270],{"class":355},[349,3004,2181],{"class":414},[349,3006,2184],{"class":355},[349,3008,2221],{"class":414},[349,3010,2624],{"class":407},[349,3012,2368],{"class":355},[349,3014,2629],{"class":414},[349,3016,2669],{"class":355},[349,3018,2726],{"class":414},[349,3020,3021],{"class":351,"line":488},[349,3022,480],{"emptyLinePlaceholder":63},[349,3024,3025,3027,3029],{"class":351,"line":493},[349,3026,2735],{"class":355},[349,3028,2738],{"class":355},[349,3030,2163],{"class":414},[349,3032,3033,3035,3037],{"class":351,"line":508},[349,3034,2745],{"class":407},[349,3036,2748],{"class":355},[349,3038,2163],{"class":414},[349,3040,3041,3043,3045,3047,3049],{"class":351,"line":513},[349,3042,2755],{"class":407},[349,3044,2758],{"class":355},[349,3046,2226],{"class":407},[349,3048,2392],{"class":380},[349,3050,2163],{"class":414},[349,3052,3053],{"class":351,"line":927},[349,3054,480],{"emptyLinePlaceholder":63},[349,3056,3057,3059,3061,3063,3066,3068,3071,3073],{"class":351,"line":933},[349,3058,2639],{"class":407},[349,3060,2994],{"class":355},[349,3062,2381],{"class":414},[349,3064,3065],{"class":355},"GameObject",[349,3067,2738],{"class":355},[349,3069,3070],{"class":414},") : ",[349,3072,2780],{"class":380},[349,3074,3075],{"class":414},"(prefab, prefab.name) { }\n",[349,3077,3078],{"class":351,"line":939},[349,3079,480],{"emptyLinePlaceholder":63},[349,3081,3082,3084,3086,3088,3090,3092,3095,3097,3099],{"class":351,"line":945},[349,3083,2639],{"class":407},[349,3085,2994],{"class":355},[349,3087,2381],{"class":414},[349,3089,3065],{"class":355},[349,3091,2738],{"class":355},[349,3093,3094],{"class":414},", ",[349,3096,2803],{"class":407},[349,3098,2748],{"class":355},[349,3100,2406],{"class":414},[349,3102,3103,3106,3109,3111],{"class":351,"line":951},[349,3104,3105],{"class":380},"        this",[349,3107,3108],{"class":414},".prefab ",[349,3110,502],{"class":407},[349,3112,3113],{"class":414}," prefab;\n",[349,3115,3116,3118,3120,3122],{"class":351,"line":957},[349,3117,3105],{"class":380},[349,3119,2815],{"class":414},[349,3121,502],{"class":407},[349,3123,2820],{"class":414},[349,3125,3126],{"class":351,"line":963},[349,3127,2453],{"class":414},[349,3129,3130],{"class":351,"line":969},[349,3131,480],{"emptyLinePlaceholder":63},[349,3133,3134,3136,3138,3140],{"class":351,"line":974},[349,3135,2639],{"class":407},[349,3137,2368],{"class":355},[349,3139,2296],{"class":355},[349,3141,2299],{"class":414},[349,3143,3144,3146,3148,3150,3152,3154,3157,3159,3161],{"class":351,"line":980},[349,3145,2843],{"class":355},[349,3147,2846],{"class":355},[349,3149,2226],{"class":407},[349,3151,2851],{"class":414},[349,3153,2091],{"class":355},[349,3155,3156],{"class":414},"(prefab) ",[349,3158,2866],{"class":407},[349,3160,2860],{"class":355},[349,3162,2163],{"class":414},[349,3164,3165,3167,3169,3171,3173,3175,3177],{"class":351,"line":986},[349,3166,2879],{"class":414},[349,3168,502],{"class":407},[349,3170,2884],{"class":414},[349,3172,2887],{"class":407},[349,3174,2890],{"class":414},[349,3176,2893],{"class":355},[349,3178,2318],{"class":414},[349,3180,3181,3184,3186,3188,3190,3192,3194,3196],{"class":351,"line":992},[349,3182,3183],{"class":355},"        T",[349,3185,2916],{"class":355},[349,3187,2226],{"class":407},[349,3189,2921],{"class":414},[349,3191,2924],{"class":355},[349,3193,2181],{"class":414},[349,3195,2184],{"class":355},[349,3197,2238],{"class":414},[349,3199,3200,3203,3205],{"class":351,"line":998},[349,3201,3202],{"class":414},"        index",[349,3204,2403],{"class":407},[349,3206,2163],{"class":414},[349,3208,3209,3212],{"class":351,"line":1004},[349,3210,3211],{"class":407},"        return",[349,3213,2946],{"class":414},[349,3215,3216],{"class":351,"line":1010},[349,3217,2453],{"class":414},[349,3219,3220],{"class":351,"line":1015},[349,3221,1423],{"class":414},[11,3223,3224],{},"This should cover most use cases and if not it should not be hard to write a factory that fits your needs.",[11,3226,3227],{},"Okay we’re almost there we still need an interface for the pool members to enforce them to have a reset method that restores a pool member to its initial state when we release a member back to the pool.",[341,3229,3231],{"className":2087,"code":3230,"language":2088,"meta":54,"style":54},"public interface IResettable {\n    void Reset();\n}\n",[35,3232,3233,3244,3254],{"__ignoreMap":54},[349,3234,3235,3237,3239,3242],{"class":351,"line":352},[349,3236,2172],{"class":407},[349,3238,2559],{"class":407},[349,3240,3241],{"class":355}," IResettable",[349,3243,2726],{"class":414},[349,3245,3246,3249,3252],{"class":351,"line":55},[349,3247,3248],{"class":407},"    void",[349,3250,3251],{"class":355}," Reset",[349,3253,2318],{"class":414},[349,3255,3256],{"class":351,"line":372},[349,3257,1423],{"class":414},[11,3259,3260,3261,3263,3264,3266],{},"Now let’s make ",[35,3262,2184],{}," of ",[35,3265,2134],{}," implement IResettable like so.",[341,3268,3270],{"className":2087,"code":3269,"language":2088,"meta":54,"style":54},"public class Pool\u003CT> where T : IResettable {\n...\n",[35,3271,3272,3297],{"__ignoreMap":54},[349,3273,3274,3276,3278,3280,3282,3284,3286,3288,3290,3292,3295],{"class":351,"line":352},[349,3275,2172],{"class":407},[349,3277,2175],{"class":407},[349,3279,2178],{"class":355},[349,3281,2181],{"class":414},[349,3283,2184],{"class":355},[349,3285,2221],{"class":414},[349,3287,2624],{"class":407},[349,3289,2368],{"class":355},[349,3291,2629],{"class":414},[349,3293,3294],{"class":355},"IResettable",[349,3296,2726],{"class":414},[349,3298,3299],{"class":351,"line":55},[349,3300,485],{"class":414},[11,3302,3303],{},"That’s it, you now wrote your very own generic object pool.",[3305,3306,3308],"h3",{"id":3307},"example","Example",[11,3310,3311,3312,184,3314,3316],{},"Let’s look at an example on how you could use ",[35,3313,2134],{},[35,3315,2591],{}," for managing the spawning of enemies.",[11,3318,3319,3320,3322,3323,216],{},"To use pool we need to make a class that implements the interface ",[35,3321,3294],{}," that we want to have in the object pool in this case ",[35,3324,3325],{},"Enemy",[341,3327,3329],{"className":2087,"code":3328,"language":2088,"meta":54,"style":54},"using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class Enemy : MonoBehaviour, IResettable {\n\n    public event EventHandler Death;\n\n    void Start() {\n    }\n\n    void Update() {\n        if(Input.GetKeyDown(KeyCode.Space)) {\n            OnDeath();\n        }\n    }\n\n    public void Reset() {\n        gameObject.SetActive(false);\n    }\n\n    void OnDeath() {\n        Death?.Invoke(this, null);\n    }\n}\n",[35,3330,3331,3339,3351,3367,3375,3379,3398,3402,3417,3421,3430,3434,3438,3447,3460,3467,3471,3475,3479,3489,3505,3509,3513,3522,3546,3550],{"__ignoreMap":54},[349,3332,3333,3335,3337],{"class":351,"line":352},[349,3334,2147],{"class":407},[349,3336,2150],{"class":355},[349,3338,2163],{"class":414},[349,3340,3341,3343,3345,3347,3349],{"class":351,"line":55},[349,3342,2147],{"class":407},[349,3344,2150],{"class":355},[349,3346,216],{"class":414},[349,3348,2155],{"class":355},[349,3350,2163],{"class":414},[349,3352,3353,3355,3357,3359,3361,3363,3365],{"class":351,"line":372},[349,3354,2147],{"class":407},[349,3356,2150],{"class":355},[349,3358,216],{"class":414},[349,3360,2155],{"class":355},[349,3362,216],{"class":414},[349,3364,2160],{"class":355},[349,3366,2163],{"class":414},[349,3368,3369,3371,3373],{"class":351,"line":488},[349,3370,2147],{"class":407},[349,3372,2686],{"class":355},[349,3374,2163],{"class":414},[349,3376,3377],{"class":351,"line":493},[349,3378,480],{"emptyLinePlaceholder":63},[349,3380,3381,3383,3385,3388,3390,3392,3394,3396],{"class":351,"line":508},[349,3382,2172],{"class":407},[349,3384,2175],{"class":407},[349,3386,3387],{"class":355}," Enemy",[349,3389,2629],{"class":414},[349,3391,2669],{"class":355},[349,3393,3094],{"class":414},[349,3395,3294],{"class":355},[349,3397,2726],{"class":414},[349,3399,3400],{"class":351,"line":513},[349,3401,480],{"emptyLinePlaceholder":63},[349,3403,3404,3406,3409,3412,3415],{"class":351,"line":927},[349,3405,2639],{"class":407},[349,3407,3408],{"class":407}," event",[349,3410,3411],{"class":355}," EventHandler",[349,3413,3414],{"class":355}," Death",[349,3416,2163],{"class":414},[349,3418,3419],{"class":351,"line":933},[349,3420,480],{"emptyLinePlaceholder":63},[349,3422,3423,3425,3428],{"class":351,"line":939},[349,3424,3248],{"class":407},[349,3426,3427],{"class":355}," Start",[349,3429,2299],{"class":414},[349,3431,3432],{"class":351,"line":945},[349,3433,2453],{"class":414},[349,3435,3436],{"class":351,"line":951},[349,3437,480],{"emptyLinePlaceholder":63},[349,3439,3440,3442,3445],{"class":351,"line":957},[349,3441,3248],{"class":407},[349,3443,3444],{"class":355}," Update",[349,3446,2299],{"class":414},[349,3448,3449,3451,3454,3457],{"class":351,"line":963},[349,3450,2411],{"class":407},[349,3452,3453],{"class":414},"(Input.",[349,3455,3456],{"class":355},"GetKeyDown",[349,3458,3459],{"class":414},"(KeyCode.Space)) {\n",[349,3461,3462,3465],{"class":351,"line":969},[349,3463,3464],{"class":355},"            OnDeath",[349,3466,2318],{"class":414},[349,3468,3469],{"class":351,"line":974},[349,3470,2448],{"class":414},[349,3472,3473],{"class":351,"line":980},[349,3474,2453],{"class":414},[349,3476,3477],{"class":351,"line":986},[349,3478,480],{"emptyLinePlaceholder":63},[349,3480,3481,3483,3485,3487],{"class":351,"line":992},[349,3482,2639],{"class":407},[349,3484,2502],{"class":407},[349,3486,3251],{"class":355},[349,3488,2299],{"class":414},[349,3490,3491,3494,3497,3499,3502],{"class":351,"line":998},[349,3492,3493],{"class":414},"        gameObject.",[349,3495,3496],{"class":355},"SetActive",[349,3498,2381],{"class":414},[349,3500,3501],{"class":380},"false",[349,3503,3504],{"class":414},");\n",[349,3506,3507],{"class":351,"line":1004},[349,3508,2453],{"class":414},[349,3510,3511],{"class":351,"line":1010},[349,3512,480],{"emptyLinePlaceholder":63},[349,3514,3515,3517,3520],{"class":351,"line":1015},[349,3516,3248],{"class":407},[349,3518,3519],{"class":355}," OnDeath",[349,3521,2299],{"class":414},[349,3523,3524,3527,3530,3532,3535,3537,3539,3541,3544],{"class":351,"line":1021},[349,3525,3526],{"class":414},"        Death",[349,3528,3529],{"class":407},"?",[349,3531,216],{"class":414},[349,3533,3534],{"class":355},"Invoke",[349,3536,2381],{"class":414},[349,3538,2780],{"class":380},[349,3540,3094],{"class":414},[349,3542,3543],{"class":380},"null",[349,3545,3504],{"class":414},[349,3547,3548],{"class":351,"line":1027},[349,3549,2453],{"class":414},[349,3551,3552],{"class":351,"line":1033},[349,3553,1423],{"class":414},[11,3555,3556,3557,3559],{},"And we need a class that manages the ",[35,3558,2134],{}," and its members.",[341,3561,3563],{"className":2087,"code":3562,"language":2088,"meta":54,"style":54},"using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class EnemyManager : MonoBehaviour {\n    public GameObject prefab;\n    Pool\u003CEnemy> pool;\n\n    void Start() {\n        pool = new Pool\u003CEnemy>(new PrefabFactory\u003CEnemy>(prefab), 5);\n    }\n\n    void Update() {\n        if(Input.GetKeyDown(KeyCode.S)) {\n            Spawn();\n        }\n    }\n\n    void Spawn() {\n        Enemy enemy = pool.Allocate();\n\n        EventHandler handler = null;\n        handler = (sender, e) => {\n            pool.Release(enemy);\n            enemy.Death -= handler;\n        };\n\n        enemy.Death += handler;\n        enemy.gameObject.SetActive(true);\n    }\n}\n",[35,3564,3565,3573,3585,3601,3609,3613,3628,3638,3654,3658,3666,3700,3704,3708,3716,3727,3734,3738,3742,3746,3755,3773,3777,3792,3818,3829,3840,3845,3849,3859,3873,3877],{"__ignoreMap":54},[349,3566,3567,3569,3571],{"class":351,"line":352},[349,3568,2147],{"class":407},[349,3570,2150],{"class":355},[349,3572,2163],{"class":414},[349,3574,3575,3577,3579,3581,3583],{"class":351,"line":55},[349,3576,2147],{"class":407},[349,3578,2150],{"class":355},[349,3580,216],{"class":414},[349,3582,2155],{"class":355},[349,3584,2163],{"class":414},[349,3586,3587,3589,3591,3593,3595,3597,3599],{"class":351,"line":372},[349,3588,2147],{"class":407},[349,3590,2150],{"class":355},[349,3592,216],{"class":414},[349,3594,2155],{"class":355},[349,3596,216],{"class":414},[349,3598,2160],{"class":355},[349,3600,2163],{"class":414},[349,3602,3603,3605,3607],{"class":351,"line":488},[349,3604,2147],{"class":407},[349,3606,2686],{"class":355},[349,3608,2163],{"class":414},[349,3610,3611],{"class":351,"line":493},[349,3612,480],{"emptyLinePlaceholder":63},[349,3614,3615,3617,3619,3622,3624,3626],{"class":351,"line":508},[349,3616,2172],{"class":407},[349,3618,2175],{"class":407},[349,3620,3621],{"class":355}," EnemyManager",[349,3623,2629],{"class":414},[349,3625,2669],{"class":355},[349,3627,2726],{"class":414},[349,3629,3630,3632,3634,3636],{"class":351,"line":513},[349,3631,2639],{"class":407},[349,3633,2860],{"class":355},[349,3635,2738],{"class":355},[349,3637,2163],{"class":414},[349,3639,3640,3643,3645,3647,3649,3652],{"class":351,"line":927},[349,3641,3642],{"class":355},"    Pool",[349,3644,2181],{"class":414},[349,3646,3325],{"class":355},[349,3648,2221],{"class":414},[349,3650,3651],{"class":355},"pool",[349,3653,2163],{"class":414},[349,3655,3656],{"class":351,"line":933},[349,3657,480],{"emptyLinePlaceholder":63},[349,3659,3660,3662,3664],{"class":351,"line":939},[349,3661,3248],{"class":407},[349,3663,3427],{"class":355},[349,3665,2299],{"class":414},[349,3667,3668,3671,3673,3675,3677,3679,3681,3684,3686,3688,3690,3692,3695,3698],{"class":351,"line":945},[349,3669,3670],{"class":414},"        pool ",[349,3672,502],{"class":407},[349,3674,2229],{"class":407},[349,3676,2178],{"class":355},[349,3678,2181],{"class":414},[349,3680,3325],{"class":355},[349,3682,3683],{"class":414},">(",[349,3685,2632],{"class":407},[349,3687,2994],{"class":355},[349,3689,2181],{"class":414},[349,3691,3325],{"class":355},[349,3693,3694],{"class":414},">(prefab), ",[349,3696,3697],{"class":380},"5",[349,3699,3504],{"class":414},[349,3701,3702],{"class":351,"line":951},[349,3703,2453],{"class":414},[349,3705,3706],{"class":351,"line":957},[349,3707,480],{"emptyLinePlaceholder":63},[349,3709,3710,3712,3714],{"class":351,"line":963},[349,3711,3248],{"class":407},[349,3713,3444],{"class":355},[349,3715,2299],{"class":414},[349,3717,3718,3720,3722,3724],{"class":351,"line":969},[349,3719,2411],{"class":407},[349,3721,3453],{"class":414},[349,3723,3456],{"class":355},[349,3725,3726],{"class":414},"(KeyCode.S)) {\n",[349,3728,3729,3732],{"class":351,"line":974},[349,3730,3731],{"class":355},"            Spawn",[349,3733,2318],{"class":414},[349,3735,3736],{"class":351,"line":980},[349,3737,2448],{"class":414},[349,3739,3740],{"class":351,"line":986},[349,3741,2453],{"class":414},[349,3743,3744],{"class":351,"line":992},[349,3745,480],{"emptyLinePlaceholder":63},[349,3747,3748,3750,3753],{"class":351,"line":998},[349,3749,3248],{"class":407},[349,3751,3752],{"class":355}," Spawn",[349,3754,2299],{"class":414},[349,3756,3757,3760,3763,3765,3768,3771],{"class":351,"line":1004},[349,3758,3759],{"class":355},"        Enemy",[349,3761,3762],{"class":355}," enemy",[349,3764,2226],{"class":407},[349,3766,3767],{"class":414}," pool.",[349,3769,3770],{"class":355},"Allocate",[349,3772,2318],{"class":414},[349,3774,3775],{"class":351,"line":1010},[349,3776,480],{"emptyLinePlaceholder":63},[349,3778,3779,3782,3785,3787,3790],{"class":351,"line":1015},[349,3780,3781],{"class":355},"        EventHandler",[349,3783,3784],{"class":355}," handler",[349,3786,2226],{"class":407},[349,3788,3789],{"class":380}," null",[349,3791,2163],{"class":414},[349,3793,3794,3797,3799,3802,3805,3807,3810,3813,3816],{"class":351,"line":1021},[349,3795,3796],{"class":414},"        handler ",[349,3798,502],{"class":407},[349,3800,3801],{"class":414}," (",[349,3803,3804],{"class":355},"sender",[349,3806,3094],{"class":414},[349,3808,3809],{"class":355},"e",[349,3811,3812],{"class":414},") ",[349,3814,3815],{"class":407},"=>",[349,3817,2726],{"class":414},[349,3819,3820,3823,3826],{"class":351,"line":1027},[349,3821,3822],{"class":414},"            pool.",[349,3824,3825],{"class":355},"Release",[349,3827,3828],{"class":414},"(enemy);\n",[349,3830,3831,3834,3837],{"class":351,"line":1033},[349,3832,3833],{"class":414},"            enemy.Death ",[349,3835,3836],{"class":407},"-=",[349,3838,3839],{"class":414}," handler;\n",[349,3841,3842],{"class":351,"line":1038},[349,3843,3844],{"class":414},"        };\n",[349,3846,3847],{"class":351,"line":1044},[349,3848,480],{"emptyLinePlaceholder":63},[349,3850,3851,3854,3857],{"class":351,"line":1050},[349,3852,3853],{"class":414},"        enemy.Death ",[349,3855,3856],{"class":407},"+=",[349,3858,3839],{"class":414},[349,3860,3861,3864,3866,3868,3871],{"class":351,"line":1056},[349,3862,3863],{"class":414},"        enemy.gameObject.",[349,3865,3496],{"class":355},[349,3867,2381],{"class":414},[349,3869,3870],{"class":380},"true",[349,3872,3504],{"class":414},[349,3874,3875],{"class":351,"line":1061},[349,3876,2453],{"class":414},[349,3878,3879],{"class":351,"line":1490},[349,3880,1423],{"class":414},[799,3882,1969],{"id":721},[11,3884,3885,3886,216],{},"Thanks for taking the time to work through this tutorial. All the code we have written can be found on GitHub as a Unity3D package for the package manager at ",[15,3887,3890],{"href":3888,"rel":3889},"https:\u002F\u002Fgithub.com\u002FLiamEderzeel\u002FPool",[19],"LiamEderzeel\u002FPool",[11,3892,3893],{},"I hope you found this tutorial useful and helped you grasp a better understanding of object pools and writing generic code. I’d love to know how it helped you in developing your game.",[11,3895,3896],{},"Feel free to share a link to showcase your work in the comments. Questions, thoughts or improvements are always welcome too.",[11,3898,3899],{},"#Design Pattern #Memory Management #Object Pool #Unity3D",[764,3901,3902],{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":54,"searchDepth":55,"depth":55,"links":3904},[3905],{"id":3307,"depth":372,"text":3308},"2019-03-31","\u002Fimages\u002Fisomatrix8.gif",{"slug":3909},"a-generic-object-pool-for-unity3d","\u002Farticles\u002Fa-generic-object-pool-for-unity3d",{"title":2068,"description":2077},"This is a tutorial for writing a generic object pool for game development in Unity3D.","articles\u002Fa-generic-object-pool-for-unity3d",[3915],"Unity3D","jD9OcVE3dwhsWLLyfLKFgvXhHWylUjUdh1DFjwrwvEM",1793104388966]