Skip to content

Instantly share code, notes, and snippets.

View corlaez's full-sized avatar
🏠
WFH since January 2020

Armando Cordova corlaez

🏠
WFH since January 2020
View GitHub Profile
@corlaez
corlaez / CopyToClipboard
Created October 9, 2016 20:02
Copy to clipboard
public void copyToClipboard() {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(label, text);
clipboard.setPrimaryClip(clip);
}
@corlaez
corlaez / Invitation.js
Last active December 6, 2017 23:52
Invitation Email to use on RunKit
const React = require('react')
const ReactDOMServer = require('react-dom/server')
global.React = React
const t7 = require('t7')
let jsx;
t7.module((t7instance) => {
jsx = t7instance
jsx.setOutput(t7.Outputs.React);
})
const reactHtmlEmail = require("react-html-email");
@corlaez
corlaez / Ycombinator.js
Last active March 27, 2018 20:01
My Y combinator implementation, am I missing something?
// My point is that we could have a simpler Y combinator
// I think the lambda would be λf.λx. f f x
// not sure about that. I have only read about this today, so let me know
// what I am missing.
// My Y combinator (am i violating some lambda rule?)
const Y2 = f => x => f(f)(x)
// This proposal implementation requires spetial input functions
// Y combinator's lambda calculus formula:
// Y = λf.(λx.f(x x))(λx.f(x x))
// Single line Y combinator implementation:
// const Y = f => (x => f(v => x(x)(v))) (x => f(v => x(x)(v)))
// My prefered (2 line) Y implementation (more readable IMO)
const λfx__f_xx_ = f => x => f( y => x(x)(y) ); // helper
const Y = f => λfx__f_xx_(f) ( λfx__f_xx_(f) ); // The Y combinator
// factorial generator for Y (where fact is truly recursive):
const Y_factg = fact => n => n === 0 ? 1 : n * fact(n - 1)
// A factorial function generated with Y:
// Continuation Passing Style (CPS)
console.log('CPS factorial')
const CPS_fact = (n, callback = log) => {
console.log('CPS_fact push stack when n = '+ n)
if(n === 0) {
//console.log(`then we call callback$${n}(1)`)
callback(1)// executed when n is 0
} else {
//console.log(`when n = ${n} then callback$${n - 1} = e => callback$${n}(e * ${n})`)
CPS_fact(n - 1, r => {
@corlaez
corlaez / cerebral-runkit.js
Created May 16, 2018 22:04
Cerebral on npm.runkit.com
var {Module, Controller, Provider} = require("cerebral")
var {state, signal} = require("cerebral/tags")
var {increment} = require("cerebral/operators")
var React = require("react")
var PropTypes = require("prop-types")
var {Container, connect} = require("@cerebral/react")
var { renderToString } = require('react-dom/server')
const controller = Controller(Module({
state: {
@corlaez
corlaez / empty-event.proto
Created June 11, 2018 16:31
How does an empty message looks like in protobuffers
syntax = "proto3";
package com.corlaez;
message EmptyEvent {
}
@corlaez
corlaez / Main.java
Last active October 5, 2018 19:14
Understanding WeakMap with not interned Strings
import java.util.WeakHashMap;
import java.lang.ref.WeakReference;
class Main {
public static void main(String[] args) {
WeakHashMap map = new WeakHashMap<String, Integer>();
char[] arr = {'x'};
String x = new String(arr);
String x2 = new String(arr);
@corlaez
corlaez / README.md
Last active December 19, 2019 15:17
Flatten an Array!