Skip to content

Instantly share code, notes, and snippets.

View jamesplease's full-sized avatar
🍕
yum

James Please jamesplease

🍕
yum
  • USA
View GitHub Profile
@jamesplease
jamesplease / icu.txt
Last active August 31, 2016 17:45
ICU Message Example
# this version is easier to read
Displaying {count} { count, plural,
one {character}
other {characters}
}.
# new lines don't have meaning so this also works
Displaying {count} { count, plural, one {character} other {characters} }.
// need to fill these out
const RTL = ['ar', 'whatevs'];
const reverseComma = ['ar'];
function generateList(arr, languageCode) {
const rtl = RTL.indexOf(languageCode) >= 0;
const comma = reverseComma.indexOf(languageCode) >= 0 ? '،' : ',';
if (rtl) {
return arr.reverse().join(` ${comma}`);
@jamesplease
jamesplease / i18n.md
Last active September 7, 2016 16:48
i18n

A Short Guide to i18n Support

Internationalization (i18n) support in webapps is important, but I'm learning that it's not simple to do. Here are some quick guidelines if you're new to it.

The ICU Message Format

The most basic thing you can do to support i18n is to use a format that supports "pluralization." For instance, if a string in English is "There are {count} dogs", you'll want it to read something like:

function startpg {
pg_ctl -D /usr/local/var/postgres start
}
function stoppg {
pg_ctl -D /usr/local/var/postgres stop -s -m fast
}
import simpleResource from 'redux-simple-resource';
const books = simpleResource('book', {
// Maybe not necessary
pluralForm: 'books',
actions: {
// Pass `false` to turn it off. Default is `true`
create: false,
// Pass an object to configure the xhr request.
{
name: 'person',
plural_form: 'people',
attributes: { first_name: 'VARCHAR(30)', last_name: 'VARCHAR(30)' },
pagination: { default_page_size: 5, default_page_number: 1 },
built_in_meta: { created_at: false, updated_at: true }
}
@jamesplease
jamesplease / new.js
Last active February 19, 2017 06:58
"New" was generated from a SQL table. "original" is the Model used to generate the table.
{ name: 'transaction',
plural_form: 'transactions',
attributes:
{ description: { type: 'VARCHAR(30)', nullable: true },
value: { type: 'NUMERIC(9,2)', nullable: false },
date: { type: 'DATE', nullable: true } },
meta: { copyright: { type: 'VARCHAR(30)', nullable: true } },
relationships: {},
actions:
{ create: true,
@jamesplease
jamesplease / many-to-many.sql
Last active February 22, 2017 01:07
Guest relationship support queries for api-pls
-- Select one
WITH toppings_of_pizzas AS (
SELECT
pizza_id,
array_agg(topping_id) AS topping_ids
FROM pizza_topping
WHERE pizza_id=1
GROUP BY pizza_id
)
withIt "related_pizza_ids" AS (
SELECT
"topping_id",
array_agg("pizza_id") AS "pizza_id"
FROM "pizza_topping"
GROUP BY "topping_id"
)
render() {
return (
<Resource name="book" loading={LoadingComponent} error={ErrorComponent}>
{(resource, resourceMeta) => {
return (<div>hello {resource.name}</div>);
}}
</Resource>
);
}