Skip to content

Instantly share code, notes, and snippets.

View rolangom's full-sized avatar
💭
John 3:16

Rolando Gómez Tabar rolangom

💭
John 3:16
View GitHub Profile
@rolangom
rolangom / index.js
Created June 2, 2017 05:46
RNGridListView: React Native Selectable Grid in a ListView
import React, { Component } from 'react';
import { Text, View, StyleSheet, VirtualizedList, Dimensions, TouchableOpacity } from 'react-native';
import { Constants } from 'expo';
const arrItems = 'Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M,1,2,3,4,5,6,7,8,9,0'.split(',').map(it => ({key: it}));
const Item = ({item, width, selectedItems, setItem}) => {
const isActive = selectedItems.indexOf(item.key) > -1;
return (
<TouchableOpacity
@rolangom
rolangom / index.js
Last active July 30, 2018 22:04
JS Promise and Applicative Functor
Promise.prototype.ap = function(p) {
const self = this;
return p.then(v => self.then(f => f(v)));
}
const add =
a => b => a + b;
console.log(add(1)(2)); // 3
@rolangom
rolangom / index.js
Last active September 15, 2018 02:13
Compose with Promises, using pointfree programming #javascript #functional #programming #pointfree
let composeP = (...fns) => p =>
fns
.reduceRight(
(acc, it) =>
Array.isArray(it)
? acc.then(it[0], it[1]) // ).catch(
: acc.then(it),
p
);
@rolangom
rolangom / index.js
Last active December 30, 2019 15:22
Export HTML table to Excel
/**
* Taken from a few web snippets
*/
function tableToExcel(table, name = '', filename = "export.xls") {
const uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
if (!table.nodeType)
@rolangom
rolangom / centralFetcher.js
Last active September 3, 2020 13:10
Centralized fetcher function that caches the response.
const _sessionStore = {};
const sessionStore = {
getItem: (id) => _sessionStore[id] || null,
setItem: (id, value) => _sessionStore[id] = value,
clear: () => _sessionStore = {},
}
/**
*
@rolangom
rolangom / wevents.py
Last active October 15, 2020 12:52
Create Windows events using Python 3
"""
Create windows events
"""
import os
def create_event(srcname: str, type: str, id: int, description: str):
command = f'eventcreate /t {type} /id {id} /l application /so {srcname} /d "{description}"'
os.system(f'cmd /c "{command}"')
def post_info_event(srcname: str, id: int, description: str):
@rolangom
rolangom / round.js
Last active July 27, 2021 00:05
functions javascript round numbers
function round(n, e) {
const f = e === 0 ? 1 : Math.pow(10, e);
return Math.round(n * f) / f;
}
// test examples
/*
> round(123.123, 2)
< 123.12
@rolangom
rolangom / download_bars.py
Created August 8, 2021 23:27 — forked from wrighter/download_bars.py
A command line utility to download historical data from Interactive Brokers
#!/usr/bin/env python
import os
import sys
import argparse
import logging
from datetime import datetime, timedelta
from typing import List, Optional
from collections import defaultdict
@rolangom
rolangom / vgsales.ipynb
Created October 20, 2021 21:20
video game sales analysis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rolangom
rolangom / GTFlowEngine.tsx
Last active November 11, 2021 21:15
GTFlowEngine
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import createStore from "./GTState";
const DUMMY_FUNC = (...args: any[]) => {};
const RESIZER_SIZE = 10;
const PORT_RADIUS = 6;
const PADDING_RIGHT = 50;
const PORT_LABEL_FONT_SIZE = 7;
const portCircleWidth = 2;
const RESIZER_BORDER_WIDTH = 1;