Skip to content

Instantly share code, notes, and snippets.

View crisu83's full-sized avatar
🎩
Coding

Christoffer Niska crisu83

🎩
Coding
View GitHub Profile
@crisu83
crisu83 / pull-schema.ts
Last active December 8, 2020 09:28
Scripts for pulling and pushing schema to and from DGraph.
import {writeFileSync} from 'fs';
import fetch from 'isomorphic-unfetch';
const [, , schemaPath] = process.argv;
const dgraphUrl = process.env.DGRAPH_URL;
const dgraphToken = process.env.DGRAPH_TOKEN;
if (!dgraphUrl) {
throw new Error('You need to specify `DGRAPH_URL` in your environment.');
@crisu83
crisu83 / utils.tsx
Last active December 4, 2020 15:31
Utility components built on top of Styled System.
// Utility components on top of styled-system.
// Inspired by [Rebass](https://rebassjs.org/) and adopted to our needs.
// See: https://react-typescript-cheatsheet.netlify.app/docs/advanced/patterns_by_usecase
import {Theme} from '@/styles/theme';
import css, {SystemStyleObject} from '@styled-system/css';
import shouldForwardProp from '@styled-system/should-forward-prop';
import {
ComponentPropsWithRef,
ComponentPropsWithoutRef,
@crisu83
crisu83 / loader-example.tsx
Last active December 4, 2020 15:30
React loader implementation
import React from 'react';
export default function LoaderExample() {
comst {data, loading, error} = useMyQuery(); // Implementation specific
const {Loader, data: myData} = useLoader({
data,
errorMessage: error?.message,
isLoading: loading,
});
return (
@crisu83
crisu83 / dip_bot.js
Created May 5, 2014 11:03
Small script that will help you play "Drowning in Problems" by Notch http://game.notch.net/drowning/#
/*
Open up the developer console in your browser, paste the script below, press enter and enjoy!
*/
var anchors, i;
setInterval(function() {
anchors = document.getElementsByTagName('a');
for (i = 0; i < anchors.length; i++) {
anchors[i].click();
}
@crisu83
crisu83 / ErrorProvider.jsx
Last active December 2, 2019 11:34
Testing with Apollo Client
import { ApolloProvider } from '@apollo/react-hooks';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import { ApolloLink, Observable } from 'apollo-link';
import React from 'react';
const ErrorProvider = ({ errors, children }) => {
const errorLink = new ApolloLink(
() =>
new Observable(observer => {
@crisu83
crisu83 / init
Last active April 1, 2019 14:27
Releasing your library written in TypeScript on NPM code snippets
$ yarn
$ yarn add -D typescript rollup rollup-plugin-typescript2
@crisu83
crisu83 / react.code-snippets
Created January 22, 2019 13:54
My VS Code React snippets
{
"reactClassComponent": {
"prefix": "rcc",
"body": "import * as React from 'react'\n\nclass ${TM_FILENAME_BASE} extends React.Component {\n\trender() {\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t$0\n\t\t\t</div>\n\t\t)\n\t}\n}\n\nexport default ${TM_FILENAME_BASE}\n",
"description": "Creates a React component class"
},
"reactPureComponent": {
"prefix": "rpc",
"body": "import * as React from 'react'\n\nclass ${TM_FILENAME_BASE} extends React.PureComponent {\n\trender() {\n\t\treturn (\n\t\t\t<div>\n\t\t\t\t$0\n\t\t</div>\n\t\t)\n\t}\n}\n\nexport default ${TM_FILENAME_BASE}\n",
"description": "Creates a React pure component class"
@crisu83
crisu83 / settings.json
Created January 22, 2019 12:20
My VS Code settings
{
"diffEditor.renderSideBySide": false,
"editor.fontFamily": "Operator Mono Lig",
"editor.fontLigatures": true,
"editor.fontSize": 14,
"editor.formatOnSave": true,
@crisu83
crisu83 / moment-locale-fi.js
Last active August 24, 2018 13:20
Finnish translation for Moment.js
//! moment.js locale configuration
//! locale : finnish (fi)
//! author : Tarmo Aidantausta : https://github.com/bleadof
//! author : Christoffer Niska : https://github.com/crisu83
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../moment')) :
typeof define === 'function' && define.amd ? define(['moment'], factory) :
factory(global.moment)
}(this, function (moment) { 'use strict';
@crisu83
crisu83 / AbstractPageBuilder.php
Last active April 18, 2018 21:09
WIP Relay concept for our GraphQL implementation
<?php
namespace ALehdet\AspaApi\GraphQL\Relay;
use Digia\GraphQL\Relay\PageInfo;
use Digia\GraphQL\Relay\PageInfoBuilderInterface;
abstract class AbstractPageBuilder implements PageInfoBuilderInterface
{
/**