Skip to content

Instantly share code, notes, and snippets.

View vitorbal's full-sized avatar

Vitor Balocco vitorbal

View GitHub Profile
@vitorbal
vitorbal / routeChangeSaga.js
Created February 7, 2017 12:09
A Saga that allows you to describe route changes using the `meta.redirect` property of your action objects. FSA-compliant.
// A saga that looks for a route change request in every action. Example usage:
// export const selectConversation = ({ id }) => ({
// type: SELECT_CONVERSATION,
// payload: {
// conversationId: id,
// },
// meta: {
// redirect: {
// url: `inbox/${id}`, // <-- the saga will redirect to this url
// replace: true, // <-- if the route should be replaced or pushed on top of the history stack
@vitorbal
vitorbal / PropTypes best practices.md
Created January 19, 2017 10:51
Best practices for writing PropTypes for React Components (Work in Progress)

Best Practices for React PropTypes

  • Avoid using PropTypes.string for a prop that sets a type/variation, use PropTypes.oneOf(CONSTANT) instead:
// BAD:
Button.propTypes = {
    size: React.PropTypes.string
};

// Good:
@vitorbal
vitorbal / README.md
Last active February 9, 2022 18:02
jscodeshift transform to add metadata to all ESLint rules

jscodeshift transform to add metadata to all ESLint rules

This transform was created to programmatically add metadata to all ESLint rules (#5417).

here's a live example for the no-trailing-spaces rule.

Please note:

  • The rule mappings were initially created by scraping eslint.org/docs/rules using jsdom.
  • The scraping assumes all fixable rules are of fixable type whitespace. This is not true for 4 rules, which were fixed manually afterwards:
    • semi
  • no-extra-semi

JavaScript

  • Explain event delegation
  • Explain how this works in JavaScript
  • Explain how prototypal inheritance works
  • How do you go about testing your JavaScript?
  • AMD vs. CommonJS?
  • Which JavaScript libraries have you used?
  • Have you ever looked at the source code of the libraries/frameworks you use?
  • What are undefined and undeclared variables?
  • What is a closure, and how/why would you use one?
@vitorbal
vitorbal / simplemoduleexport.js
Last active December 14, 2015 01:28 — forked from bryanberger/simplemoduleexport.js
Exporting pattern for scripts that supports both AMD and Node module patterns. Exports to `window` as a fallback.
(function( factory ) {
// if require js is available use it to define jquery and require it.
if ( typeof define === 'function' && define.amd ) {
define( ['jquery'], factory );
} else if ( typeof module !== 'undefined' && module.exports ) {
var jQuery = require('jquery');
module.exports = factory( $ );
} else {
window.YourModule = factory( $ );
}
@vitorbal
vitorbal / _.md
Created February 13, 2013 20:48
Pie Chart
@vitorbal
vitorbal / _.md
Created February 7, 2013 09:46
rank bar chart
@vitorbal
vitorbal / gistembed.js
Created June 28, 2012 22:19
Use writeCapture to embed gists to Tumblr
$(document).ready(function() {
var prefix = "https://gist.github.com/";
$('a[href^="' + prefix + '"]').each(function(i) {
var $anchor = $(this),
$el = $("<p></p>");
$anchor.replaceWith($el);
writeCapture.html($el, '<script src="'+$anchor.text()+'.js"></scr' + 'ipt>');
$anchor.remove();
});
});
@vitorbal
vitorbal / tumblrscripts.html
Created June 28, 2012 22:10
Embed gists to Tumblr just by pasting the gist link directly
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/eojssfq/QG5m6cm3z/embedgist.js"></script>
@vitorbal
vitorbal / gist:846012
Created February 27, 2011 08:16
How to use parts of the url path as variables for a handler in Google App Engine
class RenderMovieShowTimes(webapp.RequestHandler):
def get(self, cityid, movieid):
# cityid and movieid will contain the passed variables
# do something with them
application = webapp.WSGIApplication([ '/([^/]+)/([^/]+)' ])
def main():
run_wsgi_app(application)