Skip to content

Instantly share code, notes, and snippets.

View jerray's full-sized avatar
🤯

Jerray jerray

🤯
View GitHub Profile
@jerray
jerray / README.md
Last active April 22, 2023 04:47
Use the @ alias to refer to your project root in Expo (React Native)

Use the @ alias to refer to your project root in Expo (React Native)

I spent some time and finally figured out the solution.

Note the difference between the paths in the tsconfig.json file and the alias in the babel.config.js file. The module resolver automatically adds a slash after the @ character, then uses it to generate a regular expression /^@(\/.*|)$/ to match the import path.

So if we add a slash after @ in the alias (@/), the module resolver can't match (using /^@\/(\/.*|)$/) the import path.

For example, if we have the following directory structure:

@jerray
jerray / template.handlebars
Created September 20, 2019 04:30
Work Weixin Notifier Markdown Template
# {{#equal inputs.Status "success"}}🔵{{/equal}}{{#equal inputs.Status "failure"}}🔴{{/equal}} {{ github.Repository }}
{{#if build.Tag}}[Tag {{ build.Tag }}]({{ build.Link }}){{else}}[Commit {{ build.Commit }}]({{ build.Link }}) on branch **{{ build.Branch }}**{{/if}} build {{ inputs.Status }}.
Click [here]({{ build.Link }}/checks) to check the detailed information.
@jerray
jerray / dingtalk.handlebars
Last active November 20, 2019 05:51
Drone WebHook Templates
{
"msgtype": "markdown",
"markdown": {
"title": "{{ repo.owner }}/{{ repo.name }} build {{#success build.status}}succeeded{{else}}failed{{/success}}.",
"text": "### {{#success build.status}} 🔵 {{else}} 🔴 {{/success}}{{ repo.owner }}/{{ repo.name }}\n\n{{#if build.tag}}[tag {{ build.tag }}](https://github.com/{{ repo.owner }}/{{ repo.name }}/tree/{{ build.tag }}){{else}}[commit {{regexReplace "([\w\d]{8}).*" build.commit "$1" }}](https://github.com/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}) on branch **{{build.branch}}**{{/if}} build {{#success build.status}}succeeded{{else}}failed{{/success}}.\n\nClick [here]({{ build.link }}) to check the detailed information."
}
}
function docker-cli
set vm $argv[1]
if test -s $vm
set vm "default"
end
set host (docker-machine url $vm)
if test -z $host
docker-machine ls
return 1
@jerray
jerray / luhn.js
Created January 30, 2016 08:07 — forked from ShirtlessKirk/luhn.js
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
@jerray
jerray / javascript_resources.md
Last active August 29, 2015 14:21 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@jerray
jerray / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

function modify(modifiers) {
return through2.obj(function(file, encoding, done) {
var stream = this;
function applyModifiers(content) {
(typeof modifiers === 'function' ? [modifiers] : modifiers).forEach(function(modifier) {
content = modifier(content, file);
});
@jerray
jerray / singleton.js
Created September 26, 2014 07:52
JavaScript Singleton
var Singleton = function() {
if (Singleton.prototype._instance) {
return Singleton.prototype._instance;
}
Singleton.prototype._instance = this;
};
var a = new Singleton;
var b = new Singleton;