Show HN: Our daily learning site, TIL, is five years old

0
0
Show HN: Our daily learning site, TIL, is five years old

I’m in the meanwhile engaged on an app that forwards logging round to numerous places on the Linux server. It’s fairly difficult for me to find out the place any motion I bear the browser is being logged. I would love these logs!

A superior methodology to find out the place the logging is going down is to slim it the entire formulation right down to 1 itemizing (comment, /var/log/) then ls that itemizing, ordering by most at present up to date. The devices on the stay of the report had been at present up to date, and thus doubtlessly comprise valuable loggings!

$ ls -lt

I’m throwing on the -l flag for extra element. If there are lot of logs, filter it down with head:

$ ls -lt | head

Thanks for the muse, Kori!

https://github.com/rails/rails/blob/4dcc5435e9569e084f6f90fcea6e7c37d7bd2b4d/activesupport/lib/active_support/sorting out/time_helpers.rb#L145

In and of itself, not a immense deal. Nonetheless, for people who combine it with the methodology that inviting epic quotes occasions:

https://github.com/rails/rails/blob/4dcc5435e9569e084f6f90fcea6e7c37d7bd2b4d/activesupport/lib/active_support/sorting out/time_helpers.rb#L145

It ought to all the time result in some extraordinarily refined bugs to your checks that make use of queries of their assertions. Lengthy chronicle speedy, in case your question will depend on a time comparability, that it is possible you will nicely presumably moreover merely not return one thing. 😐

Proper this is a confederate to my earlier submit about inline HTML types. If you find yourself taking to beget to place your photographs inline to your HTML, GNU coreutils affords the unsuitable64 program.

Proper right here’s me working it in Vim jabber mode, sending the output applicable to my up to date line:

:.! unsuitable64 -w Zero public/photographs/bg.gif

The -w 0 disables line wrapping, which I don’t want for inline photographs. Prefix this string with "information:picture/;unsuitable64," and also you’re right to go.

I cherish my distinctive pages (404, 500, 503) to rely as miniature as conceivable on the webserver to render inside the browser. A superior instrument to reinforce proper this is CSS Inclined for Chrome.

CSS Inclined gives a panel to DevTools that opinions which CSS courses from exterior stylesheets are being former to your net web page. That you just simply might wish to nicely presumably presumably then paste these types inside a style designate and retract away stylesheet references to your HTML. I iterate on this by opening the HTML file in my browser outdoor of my enterprise repo; when the full types are loading, I’ve eliminated the stylesheet dependency.

image

Phil Capel posted a til at present that talked in regards to the make use of of the _ persona as a remember boundary by taking out it from the iskeyword report with:

:se iskeyword-=_

So now w navigates to the next underscore in long_id_for_var and that it is possible you will nicely presumably copy lengthy with yiw when your cursor is on lengthy.

My addendum to proper this is that navigating with W will nonetheless lumber to the next area separated remember, B will lumber the origin of the sooner area separated remember, and in case your cursor is on lengthy, yiW will copy long_if_for_var.

All individuals at Hashrocket has some acknowledge for making an try to go looking out the remember below the cursor.

One other people created a mapping, nonetheless as I try and maintain to native vim performance as grand as conceivable I copied the up to date remember with yiw after which typed:

:Rg 0

The place 0 writes no matter is in register Zero to the jabber.

As a exchange, the jabber mapping writes the remember in the meanwhile below the cursor to the jabber, so I’ll true skip the yiw.

:Rg 

Will look the remember below the cursor.

Understand :befriend c_CTRL-R_CTRL-A for extra information.

Postgres can routinely generate constraint names should you omit the remember constraint:

alter desk customers
  add worldwide key (location_id) references places;

alter desk customers
  add new (e mail);

I repeatedly beget hazard remembering how you can derive the title of the up to date itemizing. So new pneumonics is the methodology to go.

The predominant amigo is a shell variable:

echo $PWD
# returns '/home/chris/tils'

There may very well be additionally a pwd jabber that returns the the identical ingredient.

The 2nd amigo is basename which affords you the up to date itemizing title with out its route:

basename $PWD
# returns 'tils'

The third amigo is dirname which affords you the trail with out the up to date itemizing title:

dirname $PWD
# returns '/home/chris'

So now I’ll blueprint issues cherish

alias tnew=tmux up to date -s $(basename $PWD)

as a result of I repeatedly, repeatedly, title my tmux session after the title of the up to date itemizing.

Parcel talked about a superior piece of philosophy of their v2 README.

As a exchange of pulling all that configuration into Parcel, we fabricate make use of of their possess configuration techniques.

This reveals up inside the variation in how output directories are handled in v1 and v2.

In v1, dist is the default output itemizing and might overridden with the -d flag for the originate jabber, cherish this:

npx parcel originate index.js
// writes to dist/index.js
npx parcel originate index.js -d builds
// writes to builds/index.js

In v2, parcel reads the predominant key out of your gear.json file and makes make use of of that to configure the output route and file.

With the configuration:

// gear.json
{
...
"predominant": "v2_builds/index.js"
...
}

parcel outputs to the specified residing.

npx parcel originate index.js
// writes to v2_builds/index.js

I found this present day that that it is possible you will nicely presumably destructure javascript object keys a number of occasions:

const obj = {a: 1};

const {a: c, a: d} = obj;

c === d
// evaluates to applicable

Proper this is great for people who take to beget to destructure explicit keys for comfort nonetheless nonetheless should function on the entire article, cherish this:

const {bigObj, bigObj: {isError}} = deepObj;

I found at present from Josh Branchaud’s Vim Un-Alphabet screencast sequence about purchasing your befriend information with :helpgrep.

This works with the befriend information to your plugins too. Lets embrace:

:helpgrep Creator:  Tim Pope

Will look the string “Creator: Tim Pope” and might merely return entries for all plugins that Tim Pope authored that you simply beget gotten set in.

Today whereas doing a little sleuthing, I found in regards to the host jabber. host “is an easy utility for performing DNS lookups.” It helped me join a sequence of domains to their respective AWS EC2 servers, and never using a seek the advice of with to the area registrar.

Instance:

$ host jakeworth.com
jakeworth.com has maintain 184.168.131.241
jakeworth.com mail is handled by 10 mailstore1.secureserver.safe.
jakeworth.com mail is handled by Zero smtp.secureserver.safe.

Additional information: man host

A terribly big attribute of parcel is scorching module reloading, or reasonably, for people who fabricate a trade to a file that trade is manifested inside the browser the place you beget gotten your app open.

My parcel enterprise turned as quickly as setup on a distant server that I had ssh’d into port forwarding the default parcel port, 1234, nonetheless inside the console of Firefox I bought this error:

Firefox can’t place a connection to the server at ws://localhost: 41393/. hmr-runtime.js: 29: 11

Seems I important to lock my hmr port to a put port after which port ahead that hmr port over ssh.

Lock the hmr port for people who initiating the parcel server cherish this:

parcel index.html --hmr-port=55555

And be advantageous you’re port forwarding that port over ssh:

ssh [email protected] -L 1234:localhost: 1234 -L 55555:localhost: 55555

Now your app will place a web-based socker connection to the parcel server!

Whereas making an try to derive scorching module reloading working with parcel this present day I seen that when shortly parcel’s server didn’t register when a file turned as quickly as saved.

It seems that evidently vim has some unprecedented behaviour round writing information that stops node’s filesystem watcher from getting occasions that the file modified.

That you just simply might wish to nicely presumably presumably uncover about that unprecedented behaviour right here

You’re going to moreover derive round this behaviour with:

:area backupcopy=advantageous

in holding with vim befriend backupcopy this might nicely:

fabricate a replica of the file and overwrite the brand new one

triggering the fs occasion.

I’ve been experimenting with noconfig webpack (mannequin 4.43) at present and have become as quickly as homosexual to remember tree shaking is on by default.

If I little doubt beget a module maths.js:

export const add = (a, b) => a + b;

export const subtract = (a, b) => a - b;

And in my index.js file I import excellent add:

import { add } from './maths'

Then after I chase webpack in manufacturing mode with -p, retract to visible present unit the sooner exports with --visual present unit-former-exports and retract to visible present unit the geared up exports with --visual present unit-equipped-exports then I derive an output for the maths module that signifies tree shaking is taking residing:

$ npx webpack -p --visual present unit-former-exports --visual present unit-equipped-exports
    | ./src/maths.js 78 bytes [built]
    |     [exports: add, subtract]
    |     [only some exports used: add]

The output [only some exports used: add] implies that subtract has not been included inside the ultimate output.

The lodash gear wants so that you’d probably wish to improve all browsers, it makes make use of of es5 modules. The lodash-es gear makes make use of of es6 modules, pondering it to be tree shaked by default in webpack v4.

This import declaration:

import {be a half of} from 'lodash';

brings inside the whole lodash file, all 70Okay.

This import declaration:

import {be a half of} from 'lodash-es';

brings in precisely the be a half of module, which is never as so much as 1K.

With each lodash builds that it is possible you will nicely presumably true import the function right now:

import be a half of from 'lodash/be a half of';

However when the make use of of a number of lodash capabilities in a file that it is possible you will nicely presumably moreover merely take the sooner import declarations to derive it the entire formulation right down to 1 line:

import {chunk, be a half of, sortBy} from 'lodash-es';

If you beget gotten these declarations proper through your app, take be aware aliasing lodash to lodash-es to your webpack config as a transient restore.

Let’s comment you’re having reminiscence points to your Ruby app and you’re taking to beget to derive a really feel for the methodology many objects are instantied. That you just simply might wish to nicely presumably presumably make use of ObjectSpace!

require 'objspace'
ObjectSpace.each_object(Object).rely
# in my unprecedented rails app: 394683

The total lot inside purpose one among Object (for basically essentially the most piece), so that you beget gotten about 394683 objects in reminiscence! That’s tons! That you just simply might wish to nicely presumably presumably slim this down should you’re taking to true String.

ObjectSpace.each_object(String).rely
# in my unprecedented rails app: 295261

However let’s confirm one thing extra attention-grabbing, cherish TZInfo::CountryTimezone:

ObjectSpace.each_object(TZInfo::CountryTimezone).rely
# in my unprecedented rails app: 348

Clever!

tldr; Beware, each ActiveSupport’s try and Ruby’s true navigation operator &. will repeatedly return nil when engaged on a nil.

Lets embrace, I’d beget anticipated both to return a response cherish so:

> nil.try(:to_s) => ""
> nil&.to_s => ""

Nonetheless proper this is not the case:

> nil.try(:to_s) => nil
> nil&.to_s => nil

That you just simply might wish to nicely presumably presumably make use of du, to epic on the dimension of directories or information, nonetheless when my file is smaller than the block dimension I don’t watch the output I demand.

With a miniature file, this should be the dimension of the sequence of characters.

$ echo 'Every Precise Boy Deserves Fudge' > staff.txt
$ cat staff.txt | wc -c
30

However after I make use of du to peruse file, I don’t watch 30.

$ du -h staff.txt
4.0K    staff.txt

du measures in block sizes as a result of usually if any piece of a block is former, then for the wants of the working system the full block is former.

That you just simply might wish to nicely presumably presumably repeat du to care excellent in regards to the dimension of the file with --obvious-dimension which is right apparent as a result of between the origin and stay of the file the OS can’t repeat which bytes are in make use of or normally will not be in make use of.

$ du --obvious-dimension staff.txt
1       staff.txt

When reporting apparent dimension it rounds as so much as kilobytes, or --block-dimension=1k

To derive the precise dimension of the file, that it is possible you will nicely presumably make use of -b which is the the identical as --obvious-dimension --block-dimension=1

$ du -b staff.txt
30      staff.txt

UUID’s (universally new identifiers) are if truth be told at hand. I make use of them for all types of issues, cherish key props in a React blueprint, and I take to beget them with out points accessible when writing code.

Today I wrote two Vim mappings to reinforce this workflow. I’ll shell out to Ruby and make use of SecureRandom:

" Insert a UUID with Ruby
nnoremap ruid :be taught !ruby -e "require 'securerandom'; p SecureRandom.uuid"

Or, should you’re happier inside the JavaScript ecosystem, proper right here’s a the identical jabber the make use of of Node and the uuid library. I did not beget to place in uuid, it turned as quickly as already readily available to me.

" Insert a UUID with JS
nnoremap juid :be taught !node -e "var uuid = require('uuid'); console.log(uuid.v4())"

jq is a extraordinarily environment friendly jabber-line instrument to offer wait on to parse, analyze and script json output.

My up to date instruct in jq is to flip this:

{
  "modules": [
  {
    "name": "x",
    "size": 10
  },
  {
    "name": "y",
    "size": 20
  }
  ]
}

into this:

{x: 10}
{y: 20}

Proper this is conceivable the make use of of object development:

jq '.modules[] | {(.title): .dimension}'

You pipe the stay consequence of the preliminary attribute as an array syntax .modules[] to an object {}. To make use of an attribute as a key you set parens proper through the attribute (.title) and jabber that the related worth should be a specific attribute .dimension.

Learn extra inside the jq docs

That you just simply might wish to nicely presumably presumably screenshot excellent the touchbar by the make use of of the keyboard shortcut Cmd ^

Camouflage: I’ve examined this on a 15” MBP, no conception on how this might nicely work on totally completely different macs

In my vendetta towards the besides expression in ruby, I obtained proper right here proper through a make use of case the place I desired to affect code excellent if an merchandise turned as quickly as lacking from an array.

I may nicely moreover with out points blueprint:

besides ['a', 'b', 'c'].embrace?('d')
  # blueprint a ingredient
stay

However I desired to interchange the besides with an if, which led me to marvel if there turned as quickly as an exclude? methodology for arrays in ruby.

Seems, ActiveSupport prolonged the Enumerable class to introduce precisely what I turned as quickly as purchasing for!

if ['a', 'b', 'c'].exclude?('d')
  # blueprint a ingredient
stay

Hooray!

If you find yourself taking to beget to attach with a laptop to your community nonetheless don’t know the ipaddress, that it is possible you will nicely presumably make use of nmap to offer wait on to.

nmap -sn 192.168.1.0/24

The above jabber will conduct a “Ping Scan” on all addresses that initiating with 192.168.1.

192.168.1.0/24 is a subnet conceal. It takes 24 bits to stipulate the predominant Three sections of an ip4 maintain, in comment that’s what the /24 is all about. Be taught extra about subnet masks right here.

ct_ will trade as so much because the underscore and lumber away or not it is.

cf_ will trade as so much because the underscore and eat it as neatly.

Alternatively, that it is possible you will nicely presumably make use of area iskeyword-=_ which is able to fabricate the “_” persona a advantageous remember boundary. This might nicely presumably be preferable should you, cherish me, are inclined to make make use of of ciw extra recurrently than true cw.

EDIT: Ensuing from iskeyword is how the syntax highlighting is managed, you’ll doubtlessly leer that for methods/capabilities that comprise key phrases the highlighting is new after taking half in with this. I found that I cherish nnoremap e :area iskeyword-=_diw:area iskeyword+=_i as a strategy to allow me to extra with out points edit the phrases I want with out messing with the highlighting.

IO inspects limits your information by default in 50, so 50 Blueprint keys and values, or 50 Checklist devices, and lots others. Every so recurrently you beget gotten an even bigger information, in order that it is possible you will nicely presumably play with this amount by environment an risk to the IO.peek/2 function, or that it is possible you will nicely presumably area it to :infinity. Use :infinity with moderation pointless to comment:

big_map = 1..100 |> Enum.blueprint(&{ &1, "payment #{&1}"}) |> Enum.into(%{})
IO.peek(big_map)
IO.peek(big_map, restrict: 100)
IO.peek(big_map, restrict: :infinity)

When that it is possible you will nicely presumably moreover be the make use of of Vimium, the Hacker’s Browser, I little doubt beget a superior professional tip by job of Hashrocket alumnus Josh Branchaud. Hit yy on an webpage to repeat the up to date URL into your paste buffer.

This miniature alert inside the decrease applicable of my Firefox tells me it labored:

yanked

A trademark of switching between Ruby and JavaScript: I mistype the respective array inclusion function tons. In JavaScript, it’s entails, and in Ruby, it’s embrace (with a query designate). Every language does not care what I meant.

The methodology I take be aware which function to make make use of of: in Ruby, I comment: “does this array embrace this merchandise?”. Then after I’m writing JavaScript, I take be aware I’m not writing Ruby. This system is… missing.

Chris Erin’s pneumonic is best: “JavaScript has an ‘s’ in it, so it entails. Ruby does not, so it’s embrace.”

I cooked up this Heroku/subshell jabber this present day, and I cherish it:

$ psql $(heroku config:derive DATABASE_URL)

This could join me to the predominant PostgreSQL database for my Heroku utility inside the psql shopper. Now I’m prepared to question!

NOTE: why not $ heroku pg:psql? I’m not advantageous. I ponder Heroku turned as quickly as reporting standing points this present day, and I desired to bypass any infrastructure I may nicely moreover.

I’m managing two Firefoxes on my laptop laptop: one for work and one for after work. A attribute that helps this neatly is Firefox profiles. Test with them in Firefox by typing about:profiles into the browser bar.

These work cherish Chrome Other people— separate classes, histories, bookmarks, and lots others. I little doubt beget styled the two browsers fairly otherwise so I’ll fast repeat them apart.

I former to make make use of of Incognito/Private Residence home windows for this setup, nonetheless these aren’t big for long-operating browser classes, as a result of for people who pack up or wreck the browser, one thing you’ve carried out in that browser is lengthy gone. Profiles give me the isolation I would love with some persistence, too.

I’ve been the make use of of Rails for virtually a decade, and net I nonetheless don’t know even terminate to all it has to offer. Today, I turned as quickly as purchasing through an open supply app, and stumbled proper through this code:

besides feed.posts.exists?(@submit.identification)
  feed.posts << @put up
finish

I’d by no means seen or used exists? on a set earlier than, so I appeared it up. And naturally, there it's, proper within the Rails Guides Association Basics - methods added by has many!

Digging in a bit, what arguments can exists? take? Right here’s the reference.

Turns on the market a lot of options!. Integer, string, array, hash, false, or no args.

Effectively that’s kinda neat! So what does the no args do?

Imgur

It appears to behave just like any?, and return true if there are any members of the gathering, false if it’s empty.

TLDR: Learn the Rails Guides. A decade in, you’ll most likely nonetheless study one thing!

Right this moment I realized how you can convert a HTTPoison Request right into a curl command, helpful for logs. This is perhaps helpful to another person, so I'm sharing:

defmodule MyHTTP do
  def curl(%HTTPoison.Request{} = req) do
    headers = req.headers |> Enum.blueprint(fn {ok, v} -> "-H "#{ok}: #{v}"" stay) |> Enum.be a half of(" ")
    physique = req.physique && req.physique != "" && "-d '#{req.physique}'" || nil
    params = URI.encode_query(req.params || [])
    url = [req.url, params] |> Enum.filter(& &1 != "") |> Enum.be a half of("?")

    [
      "curl -v -X",
      to_string(req.method),
      headers,
      body,
      url,
      ";"
    ]
    |> Enum.filter(& &1)
    |> Enum.blueprint(&String.clear/1)
    |> Enum.filter(& &1 != "")
    |> Enum.be a half of(" ")
  stay
stay

And proper right here’s an instance of utilization:

MyHTTP.curl(%HTTPoison.Quiz{
  url: "https://til.hashrocket.com",
  params: [q: "elixir"]
})

"curl -v -X derive https://til.hashrocket.com?q=elixir ;"

Planning to make make use of of Zoom for one thing totally completely different than a gathering, cherish a studying or musical efficiency, that would nicely beget the revenue of room noise and a softer audio expertise? If that's the case, be taught on!

Zoom has a whole lot of default audio aspects in residing to manufacture what you're selling calls sound big. We don’t want these aspects in residing in a efficiency environment. Jettison them by enabling ‘standard sound’ below developed audio settings:

image

All you beget gotten to blueprint from proper right here is flip to your excellent (superb and/or area) microphone risk. For me, that’s my visible present unit audio.

h/t Suzanne Erin

One factor I’ve found pairing with Chris Erin is to checkout code you don’t want in patches. Proper right here’s the jabber:

$ git checkout --patch

Love the git add --patch jabber many builders know, this places you an interactive workflow the place that it is possible you will nicely presumably inform how you can maintain every chunk, or patch, of your adjustments. It really works reverse of git add --patch, in that y potential confirm out the patch (abandon the adjustments), and n potential maintain the adjustments.

Proper this is an enormous drift to go through earlier than making an try to commit code; make use of it to position away with debugger statements, pseudocode, undesirable autoformatter adjustments, and lots others.

I if truth be told love the Darkish Reader Browser plugin (h/t Chris Erin). It turns most internet sites right into a dejected mode that's if truth be told simple on my eyes. Nonetheless, some internet sites true don’t uncover about applicable in darkish mode. Luckily, the plugin may nicely presumably be toggled on and off with ALT + SHIFT + D on Firefox and Chrome. I make use of it just some occasions a day on internet sites I come throughout on the internet.

Bonus: Proper right here’s an instance of this plugin in motion, that's amazingly meta.

image

Darkish Reader

There are lot of tutorials about Git. One that's constructed applicable into Git is the ‘on a regular basis befriend’. Print this befriend with:

$ git befriend on a regular basis

The output is a sequence of have to-know instructions for plenty of roles in a technical group: particular person developer (standalone), particular person developer (participant), integrators, and admins.

Raise a lane and lumber! 🏁

Git has one attribute that I net irksome; you beget to be inside the itemizing with the Git repository to chase instructions towards it.

…Or blueprint you?

Git affords the -C flag for this self-discipline. Observe it with a itemizing title, and Git will affect your jabber as if it turned as quickly as chase from .

$ git -C ~/tilex standing
On department grasp
Your department is up to date with 'origin/grasp'.

Adjustments not staged for commit:
  (make use of "git add ..." to replace what is going on to be dedicated)
  (make use of "git checkout -- ..." to discard adjustments in working itemizing)

    modified:   lib/tilex_web/templates/construction/app.html.eex

no adjustments added to commit (make use of "git add" and/or "git commit -a")

Tonight I found how you can battle the dragon in #Minecraft.

Great to beget:

  • armor with safety
  • bow with vitality
  • sword with sharpening
  • stength/well being/regen potions
  • pumpkin head
  • snowballs

Should beget:

  • golden apple, tempo potion,
  • pickaxe, bow, arrows, sword & protect, armor
  • stack of grime/cobblestone, buckets of water, ladders

I proceeded to The Spoil. I picked a battle with a dragon and its pesky posse of ender males (pumpkin head helps). I found to:

  • dodge the purple dragon breath
  • dodge or block dragon dives with the sheild
  • assassinate crystals

    • with bow or snowballs for shorter towers
    • for taller towers, dump water at tower unsuitable, climb with ladder, then break crystal and tumble into water
  • with a sword strike dragon’s toes when it sits on the pillar of bedrock
  • make use of looted ender pearls to teleport dodge

In The Spoil, I died.

I’ve been the make use of of VSCode for some time, and if truth be told love the shortcut CMD+Shift+D: should you beget gotten one thing chosen, this might nicely moreover merely net and retract the next match.

Imgur

Today I unintentionally pressed CMD+Shift+L, and serendipitously discovered that it “Selects All Occurrences of Procure Match.” Now I'll retract away these pesky quotations marks on this Ruby hash ! As written, the hash keys shall be turned into symbols anyway, so the quote marks are noise.

Imgur

Hat tip 🎩to Licecap for straightforward recording of gifs on any platform.

Need a report?

list_default = Hash.up to date([])

That’s fairly darn simple.

Edit: Due to @kaokun on twitter for catching this and correcting me.
This could return the similar array at any time when (having flashbacks to the predominant time I former mutable key phrase args in python). To derive a specific array, you will have should lumber a block with the habits:

list_default = Hash.up to date hash, key

Merely as a result of your language hides pointers and references doesn’t point out that it is possible you will nicely presumably ignore them I inform.

If you’re cherish me, that it is possible you will nicely presumably moreover merely beget perception that the remember for ^ turned as quickly as spelled “carrot” because of its pointy kind.

Seems, it's spelled “caret”. This picture turned as quickly as former as a designate in improving proofs, for instance the place one thing should be inserted. So, the title comes from the Latin verb “caret” that means “there may be missing”.

Supply: https://www.etymonline.com/be aware/caret

I’ve been doing an experiment at present that requires studying and purchasing a whole lot logs in Tmux. One factor that makes this more durable is that we get hold of a deep historic earlier there. Every so recurrently I’ll ‘net’ a query I’ve been purchasing for 😀, excellent to understand it's hours or days extinct ️😐.

Tmux obvious-historical earlier has been our acknowledge. Working this jabber on an already cleared Tmux pane clears your historic earlier for that pane; that it is possible you will nicely presumably’t scroll up or search the sooner output.

We’re doing this ample that I set this alias in our terminal dotfiles.

alias tc='apparent; tmux obvious-historical earlier; apparent'

tmux obvious-historical earlier is the CLI mannequin of the Tmux meta jabber :tmux obvious-historical earlier.

I These days important to spherical down a time in apparent increments. Proper this is not one thing I’ve ever been requested to blueprint beforehand so it turned as quickly as a attention-grabbing instruct to find out. The ensuing formulation is simple:

TIME_MIN - (TIME_MIN % INCREMENT)

This might provide the earlier incremental minute. ex: Given a 5 minute increment @ 3: 12, the stay consequence may nicely presumably be 10.

time = Time.now
new_min = time.min - (time.min % 5)

I happen to be fixing this in a enterprise with ActiveSupport so there turned as quickly as entry to Time#exchange so I carried out this up with:

time.trade(min: new_min)

When including an occasion listener to a goal in javascript, the make use of of the EventTarget.addEventListener function permits you in an effort so as to add a listener with out clobbering any others that may very well be registered to that coronary heart of consideration on. Proper this is if truth be told great and all, nonetheless should you beget gotten a script that would nicely maybe moreover merely or may nicely moreover merely not be reloaded a number of occasions that it is possible you will nicely presumably stay up with this function getting known as fairly fairly.
If you’re cherish me and you utilize anonymous capabilities cherish they’re going out of style, then you definately definately can stay up attaching a number of handlers, as a result of they aren’t acknowledged as a result of the the identical function, eg

const div = epic.createElement('div');
div.addEventListener('click on on', occasion => (rating('mutate/ingredient'));

This might nicely moreover stay up working the rating the the identical sequence of occasions that the script is loaded. If as a substitute you blueprint:

function mutateMyThings(occasion) { rating('mutate/ingredient') };
div.addEventListener('click on on', mutateMyThings);

You then don’t beget to alarm about it, since including a named function will routinely excellent add it as quickly as.

Function composition is on the full great, and having a neat methodology to blueprint it's extreme. Ruby 2.6 launched a terribly orderly methodology of dealing with it with procs:

add_self = ->x { x + x }
mult_self = ->x { x x }
add_and_mult = add_self << mult_self
add_and_mult[3] # 18

In order for you the applying to be reversed:

add_self = ->x { x + x }
mult_self = ->x { x x }
add_and_mult = add_self >> mult_self
add_and_mult[3] # 36

This might nicely presumably be made into a strategy of elevate pipelines for single argument procs by declaring them in an Array and the make use of of #inject with an identification proc:

calculations = [
->x { x / 3 },
->x { x + 5 },
->x { x 2 }
]
pipeline = calculations.inject(->x {x}) blueprint |constructed, func|
originate << func
finish
pipeline[3] # 8

This may be tremendous cool for issues like ActiveRecord objects the place you wish to chain sure operations with out essentially making them specific strategies by way of scopes or comparable.

removebg is absolutely cool! Add a picture, and the location gives you again the identical picture, with background eliminated, as a tranparent PNG.

If you find yourself making an attempt to debug one thing it's normally useful to see the stacktrace of what known as a perform.

If you happen to’re inside a strive expression, and inside the catch or rescue block, that’s simple - use the __STACKTRACE__ Special Form.

strive do
    # NOPE
rescue
  ArgumentError ->
    IO.places("Stacktrace #{peek(__STACKTRACE__)}")
decide
  payment ->
    IO.places("Stacktrace #{peek(__STACKTRACE__)}")
else
  # NOPE
after
  # NOPE
stay

For all totally completely different instances the incantation inside purpose extra refined (and should you don’t ponder that it is possible you will nicely presumably bring it to mind, probably area up a snippet):

self()
|> Route of.information(:current_stacktrace)
|> IO.peek(signal: "---------> stacktrace")

CoC is the fanciest Language Server Protocol shopper for (neo)vim. It even implements Code Lens annotations, cherish reference counts in Javascript:

code lens reference counts

Okay orderly. However by default, digital textual jabber in neovim is inside the standard highlight crew. That suggests it seems to be like true cherish code, and I’m already careworn ample. After grand supply diving, I found that the highlight crew former by CoC for proper this is CocCodeLens, and former cherish so:

:hiya CocCodeLens guifg=White

code lens reference counts with better color

My code is grand extra readable.

LEAVE A REPLY

Please enter your comment!
Please enter your name here