Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Pavel Lang langpavel

🏠
Working from home
Block or report user

Report or block langpavel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@langpavel
langpavel / GraphQLTimestamp.js
Last active Jul 11, 2019
GraphQLTimestamp.js
View GraphQLTimestamp.js
import { Kind } from 'graphql/language';
import { GraphQLScalarType } from 'graphql';
function serializeDate(value) {
if (value instanceof Date) {
return value.getTime();
} else if (typeof value === 'number') {
return Math.trunc(value);
} else if (typeof value === 'string') {
return Date.parse(value);
@langpavel
langpavel / uaccent.sql
Last active Jun 7, 2019
PostgreSQL URL slug usable for indices
View uaccent.sql
/**
* original unaccent function isn't usable for indices
*/
CREATE OR REPLACE FUNCTION uaccent(text) RETURNS text AS
$uaccent$
SELECT unaccent('unaccent',$1::text);
$uaccent$ LANGUAGE sql IMMUTABLE;
@langpavel
langpavel / create-comparator.ts
Created May 29, 2019
TypeScript comparator factory for Array.sort()
View create-comparator.ts
// Usage:
const candidates: any[] = [];
// ...
candidates.sort(createComparator(
(x) => x.ambiguous,
(_, y) => y.refCount, // DESC
(x) => x.name.length,
(x) => x.name,
));
@langpavel
langpavel / generate-urls.d.ts
Created Apr 10, 2019
universal-router generated type definitions
View generate-urls.d.ts
import { Params } from './types';
import UniversalRouter from './universal-router';
export default function generateUrls(router: UniversalRouter<any, any>, options?: any): (routeName: string, params: Params) => string;
//# sourceMappingURL=generate-urls.d.ts.map
@langpavel
langpavel / graphql-loader-ts.js
Created Apr 8, 2019
graphql-loader-ts (really not finished)
View graphql-loader-ts.js
/* eslint-disable max-len, consistent-return, no-continue, no-restricted-syntax, func-names, no-throw-literal, global-require */
// really heavily borrowed from 'graphql-tag/loader'
const fs = require('fs');
const gql = require('graphql-tag/src');
const { addTypenameToDocument } = require('apollo-utilities');
// Takes `lines` (the source GraphQL query string)
// and `doc` (the parsed GraphQL document) and tacks on
// the imported definitions.
@langpavel
langpavel / mergeExtensionsIntoAST.js
Last active Nov 8, 2018
GraphQL: Merge Extensions Into AST
View mergeExtensionsIntoAST.js
const invariant = require('invariant');
const { Kind } = require('graphql');
const byKindGetInfo = {
// SchemaDefinition
[Kind.SCHEMA_DEFINITION]: def => ({
isExtension: false,
type: 'schema',
typeName: 'schema',
}),
View EMOJI.md

💯 🔢 👍 👎 🥇 🥈 🥉 🎱 🅰️ 🆎

@langpavel
langpavel / CsvTransformStream.js
Created Oct 26, 2017
Node Streams: HashThroughStream, ObjectStreamToJSON and CsvTransformStream
View CsvTransformStream.js
import { Transform } from 'stream';
export default class CsvTransformStream extends Transform {
constructor(options) {
super({
decodeStrings: false,
readableObjectMode: true,
});
this.rowFlushed = true;
this.currentColumn = [];
@langpavel
langpavel / keybase.md
Last active Sep 24, 2016
Keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am langpavel on github.
  • I am langpavel (https://keybase.io/langpavel) on keybase.
  • I have a public key ASD90-YIy2SfkHcnDOIr-maeEAW83YKtCSpWkBoHp3lyGgo

To claim this, I am signing this object:

@langpavel
langpavel / template1.sql
Created Feb 11, 2016
PostgreSQL česká template1 šablona
View template1.sql
/* PostgreSQL česká template1 */
UPDATE pg_database SET datistemplate = false WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 template=template0 encoding='UTF-8' LC_COLLATE='cs_CZ.UTF-8' LC_CTYPE='cs_CZ.UTF-8';
COMMENT ON DATABASE template1 IS 'Výchozí česká databáze';
UPDATE pg_database SET
datacl = (SELECT datacl FROM pg_database WHERE datname = 'template0'),
datistemplate = true
WHERE datname = 'template1';
You can’t perform that action at this time.