Skip to content

Instantly share code, notes, and snippets.

View luisenriquecorona's full-sized avatar
😎
I may be slow to respond.

TextKi JS luisenriquecorona

😎
I may be slow to respond.
View GitHub Profile
// in a browser
var RegExp = "Hello!";
console.log(window.RegExp); // "Hello!"
var ncz = "Hi!";
console.log(window.ncz); // "Hi!"
// in a browser
let RegExp = "Hello!";
console.log(RegExp); // "Hello!"
@luisenriquecorona
luisenriquecorona / GenericEncoder.java
Created July 19, 2019 01:11
The GenericEncoder Class Now Uses EncoderFactory
class GenericEncoder
{
private $encoderFactory;
public function __construct(
EncoderFactory $encoderFactory
){
$this->encoderFactory = $encoderFactory;
}
public function encodeToFormat($data, string $format): string
{
import React from 'react';
import { Formik, Form, Field, FieldArray } from 'formik';
import styled from 'styled-components';
const languageState = [true];
export default () => {
const handleSubmit = values => {
console.log(values.languages);
};
import React, { Component } from 'react'
import FeedbackMessage from './FeedbackMessage'
class App extends Component {
render() {
return (
<div className="App">
<FeedbackMessage name="@SoyLuisCorona Follome" app="My App React" />
</div>
);
@luisenriquecorona
luisenriquecorona / permanote.js
Created July 6, 2019 01:51
With that overview of PermaNote’s event-driven logic, here is
// Some variables we need throughout
var editor, statusline, savebutton, idletimer;
// The first time the application loads
window.onload = function() {
// Initialize local storage if this is the first time
if (localStorage.note == null) localStorage.note = "";
if (localStorage.lastModified == null) localStorage.lastModified = 0;
if (localStorage.lastSaved == null) localStorage.lastSaved = 0;
// Find the elements that are the editor UI. Initialize global variables.
editor = document.getElementById("editor");
@luisenriquecorona
luisenriquecorona / UserDataStorage.js
Created July 6, 2019 01:07
Implements the getItem(), setItem(), and removeItem() methods of the Storage API on top of IE’s userData. (It does not implement key() or clear(), because userData does not define a way to iterate through all stored items.)
function UserDataStorage(maxage) {
// Create a document element and install the special userData
// behavior on it so it gets save() and load() methods.
var memory = document.createElement("div"); // Create an element
memory.style.display = "none"; // Never display it
memory.style.behavior = "url('#default#userData')"; // Attach magic behavior
document.body.appendChild(memory); // Add to the document
// If maxage is specified, expire the userData in maxage seconds
if (maxage) {
var now = new Date().getTime(); // The current time
@luisenriquecorona
luisenriquecorona / CookieStorage.js
Created July 6, 2019 00:54
Storage with Cookies demonstrates how to implement the methods of the Storage API on top of cookies. Pass the desired max-age and path attributes to the CookieStorage() con- structor, and then use the resulting object as you would use localStorage or session Storage. Note, though, that the example does not implement the storage event and it does…
/*
* CookieStorage.js
* This class implements the Storage API that localStorage and sessionStorage
* do, but implements it on top of HTTP Cookies.
*/
function CookieStorage(maxage, path) { // Arguments specify lifetime and scope
// Get an object that holds all cookies
var cookies = (function() { // The getCookies() function shown earlier
var cookies = {}; // The object we will return
var all = document.cookie; // Get all cookies in one big string
@luisenriquecorona
luisenriquecorona / localStorage.js
Created July 5, 2019 01:12
Storage lifetime and scope are explained in more detail below. First, however, let’s look at some examples. The following code uses localStorage, but it would also work with sessionStorage:
var name = localStorage.username; // Query a stored value.
name = localStorage["username"]; // Array notation equivalent
if (!name) {
name = prompt("What is your name?"); // Ask the user a question.
localStorage.username = name; // Store the user's response.
}
// Iterate through all stored name/value pairs
for(var name in localStorage) { // Iterate all stored names
var value = localStorage[name]; // Look up the value of each one
}
@luisenriquecorona
luisenriquecorona / Startup.cs
Last active July 4, 2019 23:43
ASP.NET Core Startup Class The configuration of the execution pipeline of an ASP.NET Core application is done via the Configure method of the Startup class. At its simplest this method needs a parameter of type IApplicationBuilder to receive an instance of the application builder, which is used to assemble together all middleware components. sho…
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
puplic void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
@luisenriquecorona
luisenriquecorona / GenerocEncoder.java
Created June 15, 2019 20:58
We have put some effort into implementing a nice abstract factory for encoders, but the GenericEncoder class still has this ugly switch statement for preparing the data before it is encoded.
class GenericEncoder
{
private function prepareData($data, string $format)
{
switch ($format) {
case 'json':
$data = $this->forceArray($data);
$data = $this->fixKeys($data);
// fall through
case 'xml':