205 Matching Annotations
  1. Apr 2021
    1. class AuthConstraint def initialize(&block) @block = block || ->(_) { true } end def matches?(req) user = current_user(req) user.present? && @block.call(user) end def current_user(req) User.find_by_id(session[:user_id]) end end This is a flexible approach to defining route access based on any desired variable (roles, auth, etc...)

      Good solution, and might be needed if you want to base routes on roles, etc. — but this one is even easier if all you need is for it to be conditional based on signed in or not (because devise provides authenticated helper):


  2. Mar 2021
    1. A proposal to specify the path for bury with classes as values of a hash arg: {}.bury(users: Array, 0 => Hash, name: Hash, something: 'Value') # {user: [{name: {something: 'Value'}]} So all absent nodes could be created via klass.new

      Didn't understand it at first, but now I think it's a pretty clever/decent solution.

      Just a bit more verbose than one might like...

      At first I had reservations about the fact that this requires you to pass a hash ... or rather, once you start using a hash as your "list", you can't just "switch back" to an array (a "problem" I've noticed in RSpec, where you have some tags that are symbols, and some that are hashes: you have to list the symbols first: describe 'thing', :happy_path, driver: :chrome):

      {}.bury(users: Array, 0, 'Value')

      But I think that's okay in practice. Just use a hash for all "elements" in your list:

      {}.bury(users: Array, 0 => 'Value')
    2. A one-liner alternative for hash-only cases can be implemented using Enumerable#reduce: root = {} [:a, :b, :c].reduce(root){@1[@2]||={}}[:d] = 'E' # root => {:a=>{:b=>{:c=>{:d=>"E"}}}}
    3. I think the issues/problems specified in the comments are not present with a Hash-only implementation. :) I would be supportive of re-considering this feature just for use with a Hash, where I believe 80% of the real-life use cases would (and do) exist. I have encountered this need before in the wild, but not with Arrays.
    1. Prof. Devi Sridhar. (2020, March 25). We will be stuck in an endless cycle of lockdown/release for next 18 months, if we do not start mass testing, tracing, & isolating those who are carriers of the virus while pursuing rapid research for antiviral treatment or vaccine. This is the message the public needs to hear. [Tweet]. @devisridhar. https://twitter.com/devisridhar/status/1242743618986745861

    1. xdg-open should do the same thing - actually, it will call gnome-open, or kde-open, or whatever, depending on your desktop environment. Thus it's more portable.
    2. The advantage is that you can use gnome-open for almost all file-types, URIs and directories. It's one command to learn, instead of trying to remember about obscure commands like sensible-browser
    1. Refactoring is a means of addressing the problem of software rot. It is described as the process of rewriting existing code to improve its structure without affecting its external behaviour.
  3. en.wikipedia.org en.wikipedia.org
    1. PyPy uses a technique known as meta-tracing, which transforms an interpreter into a tracing just-in-time compiler.
    1. We’re not really using placeholder in our demo, but a value of a single space works:
    2. :placeholder-shown is super useful for us here! It’s basically the secret selector for testing if an input currently has a value or not.
    1. var md = require('markdown-it')('commonmark');

      first sighting: require(...)(...)

      How would that work with import? Not as fluidly but...

      import markdownIt from 'markdown-it'
      let md = markdownIt('commonmark')
  4. Feb 2021
    1. Adding ends to an activity is a beautiful way to communicate more than two outcomes to the outer world without having to use a state field in the ctx. It also allows wiring those outcomes to different tracks in the container activity.
    1. Instead of having this confusing maze of lambdas, regexes, and strings, we could, in theory, introduce a single entry point of configuration for Sprockets to use, and in that file declare all assets we wanted to compile. Well, that’s exactly what the manifest.js file is.
    2. One way to alleviate this configuration fatigue is by making configuration consistent and composable. That’s what Sprocket’s new “manifest.js” seeks to do.
    1. Not all cases can be covered and easily restored. And sometimes when we will reuse this function for different use-cases we will find out that it requires different restore logic.
    2. But why do we return 0? Why not 1? Why not None? And while None in most cases is as bad (or even worse) than the exceptions, turns out we should heavily rely on business logic and use-cases of this function.
    3. So, the sad conclusion is: all problems must be resolved individually depending on a specific usage context. There’s no silver bullet to resolve all ZeroDivisionErrors once and for all. And again, I am not even covering complex IO flows with retry policies and expotential timeouts.
    1. Monads provide an elegant way of handling errors, exceptions and chaining functions so that the code is much more understandable and has all the error handling, without all the ifs and elses.
    1. I wanted to keep reviewing restaurants, but I didn’t want to go back into their dining rooms both because of the risk and because I was afraid readers would take it as an all-clear signal. When the governor halted indoor dining again in December, my selfish reaction was relief. Then I briefly got depressed. How would restaurants survive? And how would I keep writing about them?One answer had already started to appear on sidewalks and streets in the form of small greenhouses, huts, tents and yurts. Inside these personal dining rooms, you can (and should) sit just with people from your own household. If the restaurant thoroughly airs the space out between seatings, any germs you breathe in should be the same ones that are bouncing around your home. Many restaurants instruct their servers to stay outside the structures as much as possible, though some don’t.

      Syntax of question and answer reveals itself again. His doubts and negativity are addressed within the first highlighted paragraph with a question coming to Pete's mind. He realized his influence as a critic and decided to take the right step to prevent anything bad from occurring. Despite his sacrifice, the next paragraph he discusses the clever solutions restaurants had come up with which solved his problem for the most part. This description underlines yet more change that brought upon good things, which is the main idea he is relating to the food scene. He creates a comparison between an at home setting along with the solutions restaurants have come up with to further emphasize his point of safety amidst COVID.

    1. It requires an account to update, but the other inputs are optional. If they're missing, it'll ignore those attributes. If they're present, it'll update them.
    2. For this one we'll define a helper method to handle raising the correct errors. We have to do this because calling .run! would raise an ActiveInteraction::InvalidInteractionError instead of an ActiveRecord::RecordNotFound. That means Rails would render a 500 instead of a 404.

      True, but why couldn't it handle this for us?

    1. while ActiveForm currently fits 99% of my use cases, I do sometimes make modifications based on the product requirements
    2. I will continue to use form objects and push changes into the repo when I feel they are universally relevant and valuable.

      new tag?:

      • code that is universally relevant/valuable
      • non - _-specific logic
    3. I typically save everything I can first, and then call the side-effects afterwards. If the side-effects fail I can handle them elsewhere and retry when necessary.
    1. This can be useful in cases like multistep registration. Previously in # rails we used to stick all of the validations in the class and then we're # stuck validating them all everytime
    1. Most importantly, let us support all of those who are using sport as a force to advance equality and opportunity;

      A viable way to solve the gender inequality as a whole.

    2. Not only are successful sportswomen showing girls that they can excel on the field; many are using their status to start important conversations about gender equality and to advocate for women’s rights more widely.

      Being a role model that shows the world the problem of gender inequality would be a viable solution.

    3. We also need more male athletes to step up with us, and model a culture that reflects equality, respect for diversity and non-violence, within and beyond sport.

      Solution that may work.

    4. Even when laws and policies are in place, deep-seated attitudes about gender roles can hold back substantive change

      Some solution may not work even though it seems like it will. This means that we can't solve this on a government level, but on a individual's thought.

    5. In November 2018, Fenerbahçe Sports Club, one of the oldest and most popular multi-sports clubs in Turkey, joined forces with HeForShe in an ’Equal together’ initiative involving its male football players, and seen by its global fan base of 25 million. They aim to achieve gender equality transformation through sport, with women- and children-friendly stadium practices, and a zero-tolerance approach to all sorts of discrimination against women and girls

      A solution for combating gender inequality in sports. We can create a new program that allows equal rights and wages for all genders.

    1. Universal Links allow you to register a series of domains that are allowed to interact with an installed application. If the application is not installed, the universal link is opened with Safari, allowing you to inform the user of the existence of an application or whatever is necessary.
  5. Jan 2021
    1. If components gain the slot attribute, then it would be possible to implement the proposed behavior of <svelte:fragment /> by creating a component that has a default slot with out any wrappers. However, I think it's still a good idea to add <svelte:fragment /> so everyone who encounters this common use case doesn't have to come up with their own slightly different solutions.
    1. Moving DOM elements around made me anxious and I wanted to preserve natural tab order without resorting to setting tabindex, so I also made a flexbox version that never moves DOM elements around. I think it's the superior solution, at least for the layouts I was going for. https://github.com/wickning1/svelte-components/blob/master/src/FlexCardLayout.svelte
    1. A Svelte component that monitors an element enters or leaves the viewport/parent element. Performant and efficient thanks to using Intersection Observer under the hood. Can be used in multiple projects including lazy loading images, infinite scrolling, playing/pausing the video when in the viewport, tracking user behaviour firing link pre-fetching and animations and many many more.
    1. Popper for Svelte with actions, no wrapper components or component bindings required! Other Popper libraries for Svelte (including the official @popperjs/svelte library) use a wrapper component that takes the required DOM elements as props. Not only does this require multiple bind:this, you also have to pollute your script tag with multiple DOM references. We can do better with Svelte actions!
  6. Dec 2020
    1. This is an opportunity to fix a bug: if you're on a page that redirects to a login page if there's no user object, or otherwise preloads data specific to that user, then logging out won't automatically update the page — you could easily end up with a page like HOME ABOUT LOG IN ----------------------------------------------------------------------------------------- Secret, user-specific data that shouldn't be visible alongside a 'log in' button:
    1. Instead of waiting for a magic fairy to appear and eliminate your problem so that you can enjoy life again, you might want to start adding those little positive events back onto your agenda despite the problem still being present

      This solution based therapy focuses on trying to get people active and engaged with life even when depressed.

      It is important to help patients experience those little positive events. These events can help people get back on track.

    2. If you need to imagine in concrete detail how you would notice that a problem disappeared, you are challenged to leave vague descriptions like “I’ll be happy”, “I’ll be less annoyed” behind.Vagueness in the end is a cognitive avoidance mechanism. It is easy to ruminate on general emotions and thoughts but very hard to imagine concrete outcomes and changes. We would rather not face precise thoughts, emotions or memories because they can be painful. Better to stay at a safe but vague distance.

      This is all about solution based therapy. We need concrete ways of fixing our problems.

      Vagueness is a cognitive avoidance strategy. It is a way to avoid digging deep.

      It is safer for our feelings to stay vague, but that is not where we need to improve.

  7. Nov 2020
    1. So, how does an SPA work? JavaScript loads in the browser and loads data from an API. Most of the rendering is done on the client Side. But search engine bots have a hard time indexing the page because it doesn't have much without JS.
    1. This scenario demonstrates one drawback of CSS: With all the style rules that need to be applied to multiple elements on multiple pages, things can get pretty redundant. And redundancy can eat up your time and cause friction whenever you need to change a color, font, or any other style aspect across your site.
  8. Oct 2020
    1. We could broadcast a warning if we find the variable to be set in the environment, but that is more likely than not to annoy people who intentionally set it.

      New tag?: warnings that may annoy people who intentionally do something. (Need a way to selectively silence certain warnings?)

    1. for (var member in myObject) delete myObject[member]; ...would seem to be pretty effective in cleaning the object in one line of code

      But checking hasOwnProperty is probably better/safer idea:

      for (var prop in obj) { if (obj.hasOwnProperty(prop)) { delete obj[prop]; } }
    1. I don't want Svelte to go out of its way to try to catch all these edge cases. It would require lots of fragile heuristics in the compiler. I want a solid compiler I can trust, not something magic but often out of service. I want it the simplest possible.
    1. In the many projects I have maintained so far, sooner or later I always run into the same issue: circular module dependencies. Although there are many strategies and best practices on how to avoid circular dependencies. There is very little on how to fix them in a consistent and predictable way.
    2. This is how I solve circular dependency issues nowadays.
    3. Examples of this include: requiring base classes or reading from imported variables that have not been initialized yet.
    4. as soon as you have a (indirect) circular dependency, you might be interacting with a half loaded module in your code.
    1. Perhaps we should detect URLSearchParams objects differently (using duck typing detection instead of instanceof window.URLSearchParams, for example) but the solution isn't adding a specific polyfill to Axios (as it'd increase the bundle size and still won't work with other polyfills).
    1. You can see that behaviour in this example. Select a range of text and hit the tab key. Because the <textarea> value changes, the current selection is cleared and the cursor jumps, annoyingly, to the end.
    1. Just like elements can have children... <div> <p>I'm a child of the div</p> </div>...so can components. Before a component can accept children, though, it needs to know where to put them. We do this with the <slot> element.
    1. The primary motivation behind virtual-dom is to allow us to write code independent of previous state. So when our application state changes we will generate a new VTree. The diff function creates a set of DOM patches that, based on the difference between the previous VTree and the current VTree, will update the previous DOM tree to match the new VTree.

      annotation meta: may need new tag: for: "code independent of previous state."

      annotation meta: may need new tag: for: diffs other than source/text code diffs (in this case diffs between virtual DOM trees)

    2. Manual DOM manipulation is messy and keeping track of the previous DOM state is hard. A solution to this problem is to write your code as if you were recreating the entire DOM whenever state changes. Of course, if you actually recreated the entire DOM every time your application state changed, your app would be very slow and your input fields would lose focus.
    1. As we've briefly seen already, you can listen to any event on an element with the on: directive:
  9. mdxjs.com mdxjs.com
    1. Before MDX, some of the benefits of writing Markdown were lost when integrating with JSX. Implementations were often template string-based which required lots of escaping and cumbersome syntax.
    1. But this is starting to become rather verbose at what could be a much simpler and more elegant solution if only there were another template helper that could do variable assignment.
  10. Sep 2020
    1. I think Svelte's approach where it replaces component instances with the component markup is vastly superior to Angular and the other frameworks. It gives the developer more control over what the DOM structure looks like at runtime—which means better performance and fewer CSS headaches, and also allows the developer to create very powerful recursive components.
    1. Nic Fildes in London and Javier Espinoza in Brussels April 8 2020 Jump to comments section Print this page Be the first to know about every new Coronavirus story Get instant email alerts When the World Health Organization launched a 2007 initiative to eliminate malaria on Zanzibar, it turned to an unusual source to track the spread of the disease between the island and mainland Africa: mobile phones sold by Tanzania’s telecoms groups including Vodafone, the UK mobile operator.Working together with researchers at Southampton university, Vodafone began compiling sets of location data from mobile phones in the areas where cases of the disease had been recorded. Mapping how populations move between locations has proved invaluable in tracking and responding to epidemics. The Zanzibar project has been replicated by academics across the continent to monitor other deadly diseases, including Ebola in west Africa.“Diseases don’t respect national borders,” says Andy Tatem, an epidemiologist at Southampton who has worked with Vodafone in Africa. “Understanding how diseases and pathogens flow through populations using mobile phone data is vital.”
      the best way to track the spread of the pandemic is to use heatmaps built on data of multiple phones which, if overlaid with medical data, can predict how the virus will spread and determine whether government measures are working.
    1. Please focus on explaining the motivation so that if this RFC is not accepted, the motivation could be used to develop alternative solutions. In other words, enumerate the constraints you are trying to solve without coupling them too closely to the solution you have in mind.
    2. A huge part of the value on an RFC is defining the problem clearly, collecting use cases, showing how others have solved a problem, etc.
    3. An RFC can provide tremendous value without the design described in it being accepted.
    1. Hi Arthurp,We are not able to reproduce the issue at our end.Could you please try the following steps:-Open Task Manager and kill the process "Adobe Collaboration Synchronizer"-Delete the folder "Synchronizer" located at: C:\Users\arviyada\AppData\LocalLow\Adobe\Acrobat\DC\Acrobat\ Please let us know it helps. Regards,Arvind

      Suggested solution to problem with Adobe Document Cloud (ADC) synchronising comments with shared reviews from Adobe Acrobat.

  11. Aug 2020
  12. Jul 2020
    1. How to Build a Marketplace App for Barbers like Uber for Haircuts?

      Increase in the usage of uber-like services in segments like salons, personal grooming, haircuts, etc. has enhanced growth opportunities for haircut startups and entrepreneurs.

      More and more companies are planning to develop and launch apps like Uber for haircuts.

      If you also feel that it is a great idea for a sustainable business, read on to explore how you can shape this idea into a profitable business model.