Skip to content

Instantly share code, notes, and snippets.

View dalcib's full-sized avatar

Dalci de Jesus Bagolin dalcib

View GitHub Profile
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&')
.replace(/>/g,'>')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
@dalcib
dalcib / ngGrid.js
Created May 7, 2012 20:18
Angular Grid
//////////////////////////////////////
/// Grid Directive to Angular 1.0.0rc7
//////////////////////////////////////
// To use:
// <script>
// var app = angular.module('myapp', ['ngGrid']);
// var Ctrl = function($scope) { $scope.todo = [...] }
// </script>
// <div ng-app="myapp">
@dalcib
dalcib / ng-schema.js
Created July 25, 2012 03:38
AngularJS directive to convert JSON-Scheme in a form
/* https://github.com/nikos/cmskern/blob/master/playapp/public/javascripts/widgets.js*/
/**
* Widget for displaying a complete form as specified by the given schema.
*/
angular.widget('my:form', function(element) {
this.descend(true); // compiler will process children elements
this.directives(true); // compiler will process directives
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
//github.com/infinitered/ignite
<Drawer
ref='drawer'
content={this.renderDrawerContent()}
styles={drawerStyles}
openDrawerOffset={100}
type='overlay'
tapToClose
panOpenMask={0.05}
@dalcib
dalcib / jsonSchemaInterface.ts
Created July 11, 2016 18:31 — forked from enriched/jsonSchemaInterface.ts
TypeScript interface for Json-Schema V4
/**
* MIT License
*
* Copyright (c) 2016 Richard Adams (https://github.com/enriched)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@dalcib
dalcib / index.d.ts
Created June 22, 2017 13:10 — forked from pierre-H/index.d.ts
Expo TypeScript Definitions
declare module 'Expo' {
import { EventSubscription } from 'fbemitter';
import { Component } from 'react';
import { ViewStyle, ViewProperties, ColorPropType } from 'react-native';
/**
* Expo Accelerometer
*/
export namespace Accelerometer {
// TODO: good export type of x, y and z
@dalcib
dalcib / ajvValidator.js
Created January 24, 2018 04:36
AJV validator to use with react-final-form
import Ajv from 'ajv/dist/ajv.min';
import AddIf from 'ajv-keywords/keywords/if';
const makeValidator = (schema) => {
const ajv = new Ajv({ allErrors: true, coerceTypes: true });
// Add If-then-else from ajv-keywords package
AddIf(ajv);
// Add custom keyword
@dalcib
dalcib / gather.ts
Last active October 15, 2019 11:05 — forked from eenblam/gather-final.js
Naive JS implementation of tidyr's gather function. Intended for use with JSON-styled tabular data... like you'd get from d3.dsv
function withFields<S>(record: S, fields: (keyof S)[]) {
// Returns record with only properties specified in fields
return fields.reduce((acc: Partial<S>, key) => {
acc[key] = record[key]
return acc
}, {})
}
function splitRecord<S extends object>(record: S, ...fields: Array<keyof S>) {
let withGivenFields = withFields(record, fields)
@dalcib
dalcib / Counter.js
Created October 14, 2019 11:02 — forked from tannerlinsley/Counter.js
Global React State with Context and Immer
import { useCount, useIncrement, useDecrement } from './store.Count'
export default function Counter () {
const count = useCount()
const increment = useIncrement()
const decrement = useDecrement()
return (
<div>
<div>Count: {count}</div>