17 private links
npm install -g
won't finish installs on WSL Ubuntu. What I did to fix this issue:
- turned of any application running on port 3000
- cleaned npm cache
- some said I should remove package.json.lock, but what about Yarn?
I find as I am building my redux app, one piece of functionality at a time, I keep needing to add {actionTypes, actions, reducer} tuples for each use case. I have been keeping these in separate files and even separate folders, however 95% of the time, it's only one reducer/actions pair that ever needs their associated actions.
To me, it makes more sense for these pieces to be bundled together in an isolated module that is self contained, and can even be packaged easily into a library.
npm install legally -g # Make it work everywhere
legally # Check licenses of current directory
legally express # Check an npm library's licenses
use Inline::Perl5;
use DBI:from<Perl5>;
my $dbh = DBI.connect('dbi:Pg:database=test');
my $products = $dbh.selectall_arrayref(
'select * from products', {Slice => {}}
);
Module for executing Perl 5 code and accessing Perl 5 modules from Perl 6.
Supports Perl 5 modules including XS modules. Allows passing integers, strings, arrays, hashes, code references, file handles and objects between Perl 5 and Perl 6. Also supports calling methods on Perl 5 objects from Perl 6 and calling methods on Perl 6 objects from Perl 5 and subclass Perl 5 classes in Perl 6.
> mi6 new Foo::Bar # create Foo-Bar distribution
> cd Foo-Bar
> mi6 build # build the distribution and re-generate README.md/META6.json
> mi6 test # run tests
> mi6 release # release!
!!! EXPERIMENTAL !!!
> mi6 dist # make distribution tarball
> mi6 upload # upload distribution tarball to CPAN
Where should I look for perl 6 libraries?
When I've chosen one, how can I add it to my perl 6 project?
Use zef to install it on your local system.
Read the modules doc page for directions on use
ing a module in your project.
If I find it [somewhere], how can I add it to my perl 6 project?
If zef can see it (and zef will usually be able to see a module if its repo is listed at modules.perl6.org) then zef should be able to install it. If not, contact the author or ask about it on #perl6.
As an answer to point 2) and 3) , you can take a look at 6pm
. It's idea is to be NPM for Perl6. It works over Zef
.
$ 6pm init
# Install dependencies to ./perl6_modules and add it to META6.json
$ 6pm install Test::Meta --save
# Run a file using the local dependencies
$ 6pm exec-file test.p6
# Make your code always use 6pm by making it "use SixPM;"
$ perl6 test.p6
See the full documentation for more information.
How much library code do you really need — 50K? 100K? 150K? More? How much of that do you really use?
Sure, we all love our favorite monolithic frameworks, and sometimes we even use them fully. But how often do we reach for the ride-on John Deere tractor with air conditioning and six-speaker sound system, when a judiciously applied pocketknife would do the trick better, faster, slicker?
Micro-frameworks are definitely the pocketknives of the JavaScript library world: short, sweet, to the point. And at 5k and under, micro-frameworks are very very portable. A micro-framework does one thing and one thing only — and does it well. No cruft, no featuritis, no feature creep, no excess anywhere.
Microjs.com helps you discover the most compact-but-powerful microframeworks, and makes it easy for you to pick one that’ll work for you.
The built-in js-mode in Emacs does not provide many features for working with js framework beside js editing and syntax highlighting. The tips in this post will help you transform your Emacs into a powerful Javascript IDE.
Using Simple Examples
In any substantial project, it is necessary to separate your code in different files. Node.js implements the CommonJS API standard to load modules from other files. Using exports can be a source of much confusion in Node.js. Let us explore how exports works.
Alternatively, if you are creating the theme yourself and/or can modify it, you can create an action yourself using WordPress' do_action
function. This is also how they create their other hooks. So basically in your theme, you would go where you want to, right after the <body>
tag, and do something like:
do_action('after_body');
You can also pass arguments to the action callback, see the linked documentation for information.
Then afterwards, you would simply use the add_action
function to hook onto it.
add_action('after_body', 'my_callback');
Hope that helps. Sorry if I misunderstood.
A standardized, organized, object-oriented foundation
for building high-quality WordPress Plugins.
Callbacks are just the name of a convention for using JavaScript functions. There isn't a special thing called a 'callback' in the JavaScript language, it's just a convention. Instead of immediately returning some result like most functions, functions that use callbacks take some time to produce a result. The word 'asynchronous', aka 'async' just means 'takes some time' or 'happens in the future, not right now'. Usually callbacks are only used when doing I/O, e.g. downloading things, reading files, talking to databases, etc.
Summary
- Don't nest functions. Give them names and place them at the top level of your program
- Use function hoisting to your advantage to move functions 'below the fold'
- Handle every single error in every one of your callbacks. Use a linter like standard to help you with this.
- Create reusable functions and place them in a module to reduce the cognitive load required to understand your code. Splitting your code into small pieces like this also helps you handle errors, write tests, forces you to create a stable and documented public API for your code, and helps with refactoring.
The most important aspect of avoiding callback hell is moving functions out of the way so that the programs flow can be more easily understood without newcomers having to wade through all the detail of the functions to get to the meat of what the program is trying to do.
You can start by moving the functions to the bottom of the file, then graduate to moving them into another file that you load in using a relative require like require('./photo-helpers.js') and then finally move them into a standalone module like require('image-resize').
Here are some rules of thumb when creating a module:
- Start by moving repeatedly used code into a function
- When your function (or a group of functions related to the same theme) get big enough, move them into another file and expose them using module.exports. You can load this using a relative require
- If you have some code that can be used across multiple projects give it it's own readme, tests and package.json and publish it to github and npm. There are too many awesome benefits to this specific approach to list here!
- A good module is small and focuses on one problem
- Individual files in a module should not be longer than around 150 lines of JavaScript
- A module shouldn't have more than one level of nested folders full of JavaScript files. If it does, it is probably doing too many things
- Ask more experienced coders you know to show you examples of good modules until you have a good idea of what they look like. If it takes more than a few minutes to understand what is happening, it probably isn't a very good module.
More reading
Try reading my longer introduction to callbacks, or try out some of the nodeschool tutorials.
Also check out the browserify-handbook for examples of writing modular code.
What about promises/generators/ES6 etc?
Before looking at more advanced solutions, remember that callbacks are a fundamental part of JavaScript (since they are just functions) and you should learn how to read and write them before moving on to more advanced language features, since they all depend on an understanding of callbacks. If you can't yet write maintainable callback code, keep working at it!
If you really want your async code to read top-to-bottom, there are some fancy things you can try. Note that these may introduce performance and/or cross platform runtime compatibility issues, so make sure to do your research.
Promises are a way to write async code that still appears as though it is executing in a top-down way, and handles more types of errors due to encouraged use of try/catch style error handling.
Generators let you 'pause' individual functions without pausing the state of the whole program, which at the cost of slightly more complex to understand code lets your async code appear to execute in a top-down fashion. Check out watt for an example of this approach.
Async functions are a proposed ES7 feature that will further wrap generators and promises in a higher level syntax. Check them out if that sounds interesting to you.
Personally I use callbacks for 90% of the async code I write and when things get complicated I bring in something like run-parallel or run-series. I don't think callbacks vs promises vs whatever else really make a difference for me, the biggest impact comes from keeping code simple, not nested and split up into small modules.
Regardless of the method you choose, always handle every error and keep your code simple.
Remember, only you can prevent callback hell and forest fires
You can find the source for this on github.
Browserify lets you require('modules') in the browser by bundling up all of your dependencies.
- 172 languages and 77 styles
- automatic language detection
- multi-language code highlighting
- available for node.js
- works with any markup
- compatible with any js framework
#Uploading Your First Module to CPAN brian d foy The Perl Review YAPC::EU 2011
- You upload through PAUSE, The Perl Authors Upload Server. This is a stepping stone to CPAN.
- Indexing.
-- PAUSE indexes and creates data files for the CPAN clients
-- Only the latest distributions get into it.
-- People have permissions for namespaces - Get a PAUSE Account
- Choose a [module name](https://pause.perl.org/pause/query? ACTION=pause_namingmodules)
- Permissions.
-- You can upload a namespace someone else already uses.
-- But PAUSE will ignore it.
-- A good name goes a long way. - Create the distro
-- There are modules that can help you
--- Module::Starter
--- Distribution::Cooker
--- h2xs (comes with Perl)
--- many others - 25,000 Examples
-- Look at other distributions to get examples
-- See how other people do it
-- Ask them questions - Github
- Upload
- Upload early & often
-- You don’t have to be perfect, or even good
-- Other people can help as soon as possible
-- CPAN Testers can send you feedback - CPAN Search
- Lots more
-- PAUSE lets you add co-maintainers
-- You can take over existing modules
-- You can help with other people’s modules - Publicize your module
-- Don’t be shy
-- Write something on blogs.perl.org
-- Tweet it, plus it, facebook it
-- Give a lightning talk - Getting help
-- For help with PAUSE issues, write tomodules@perl.org
-- One of the PAUSE volunteer admins can help you
-- For general module questions, you might trymodule-authors@perl.org
-- For CPAN Search issues, trycpansearch@perl.org
PeerJS simplifies WebRTC peer-to-peer data, video, and audio calls.
PeerJS wraps the browser's WebRTC implementation to provide a complete, configurable, and easy-to-use peer-to-peer connection API. Equipped with nothing but an ID, a peer can create a P2P data or media stream connection to a remote peer.
WebTorrent is the first torrent client that works in the browser. It's easy to get started!
Want to see what's inside a variable in a complete, colored and human-friendly way?
use Data::Printer; # or just "use DDP" for short
p @array; # no need to pass references
Code above might output something like this (with colors!):
[
[0] "a",
[1] "b",
[2] undef,
[3] "c",
]
You can also inspect objects:
my $obj = SomeClass->new;
p($obj);
Which might give you something like:
\ SomeClass {
Parents Moose::Object
Linear @ISA SomeClass, Moose::Object
public methods (3) : bar, foo, meta
private methods (0)
internals: {
_something => 42,
}
}