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
@luisenriquecorona
luisenriquecorona / InputFilter.js
Created May 13, 2019 00:13
Is an unobtrusive module of JavaScript code that allows exactly this sort of filtering. It looks for <input type=text> elements that have an additional (nonstandard) attribute named data-allowed-chars. The module registers handlers for textinput, textInput, and keypress events on any such text field to restrict input to characters that appear i…
/**
* InputFilter.js: unobtrusive filtering of keystrokes for <input> elements
*
* This module finds all <input type="text"> elements in the document that
* have an "data-allowed-chars" attribute. It registers keypress, textInput, and
* textinput event handlers for any such element to restrict the user's input
* so that only characters that appear in the value of the attribute may be
* entered. If the <input> element also has an attribute named "data-messageid",
* the value of that attribute is taken to be the id of another document
* element. If the user types a character that is not allowed, the message
@luisenriquecorona
luisenriquecorona / DnD-API.js
Created May 12, 2019 23:49
Demonstrates how to make <ul> elements into drop targets and how to make the <li> elements within them into drag sources. The example is a piece of un- obtrusive JavaScript that looks for <ul> elements with a class attribute that includes “dnd” and registers DnD event handlers on any such lists it finds. The event handlers make the list itself i…
/*
* The DnD API is quite complicated, and browsers are not fully interoperable.
* This example gets the basics right, but each browser is a little different
* and each one seems to have its own unique bugs. This code does not attempt
* browser-specific workarounds.
*/
whenReady(function() { // Run this function when the document is ready
// Find all <ul class='dnd'> elements and call the dnd() function on them
var lists = document.getElementsByTagName("ul");
var regexp = /\bdnd\b/;
@luisenriquecorona
luisenriquecorona / isMacWebKit.js
Created May 12, 2019 23:20
In order to work correctly in all common browsers, Example must perform some browser testing. The example anticipates the DOM Level 3 Events specifi- cation and includes code to use the wheel event when browsers implement it.6 It also includes some future-proofing to stop using the DOMMouseScroll event when Firefox starts firing wheel or mousewh…
// Enclose the content element in a frame or viewport of the specified width
// and height (minimum 50x50). The optional contentX and contentY arguments
// specify the initial offset of the content relative to the frame. (If
// specified, they must be <= 0.) The frame has mousewheel event handlers that
// allow the user to pan the element, and to shrink or enlarge the frame.
function enclose(content, framewidth, frameheight, contentX, contentY) {
// These arguments aren't just the initial values: they maintain the
// current state and are used and modified by the mousewheel handler.
framewidth = Math.max(framewidth, 50);
frameheight = Math.max(frameheight, 50);
@luisenriquecorona
luisenriquecorona / functional_tests.py
Created May 11, 2019 22:19
And we could also use a try/finally to clean up the old Firefox window. But these sorts of problems are quite common in testing, and there are some ready-made solutions for us in the standard library’s unittest module
from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
@luisenriquecorona
luisenriquecorona / index.js
Created May 11, 2019 18:52
Let’s now go full circle and create a simple web application that allows to insert data into our table and also reads and displays the data that was entered. We need to start a web server with two routes (one for displaying data, one for taking user input), and we need to pass user input to the database and database results to the webpage. Here …
'use strict';
var mysql = require('mysql'),
http = require('http'),
url = require('url'),
querystring = require('querystring');
// Start a web server on port 8888. Requests go to function handleRequest
@luisenriquecorona
luisenriquecorona / create.js
Last active May 11, 2019 17:52
Next, we will query some real data from existing tables. For this, we first need to create a database, add a table to it, and insert some rows. Let’s do this through a Node.js application.
'use strict';
var mysql = require('mysql');
var connection = mysql.createConnection({ host: 'localhost',
user: 'root',
password: 'root'
});
connection.query('CREATE DATABASE node', function(err) { if (err) {
console.log('Could not create database "node".');
}
});
@luisenriquecorona
luisenriquecorona / Config EIGRPv6 Router 1,2,3.txt
Created May 10, 2019 18:13
Shows the network topology for the configuration that follows, which shows how to configure EIGRP using commands covered in this chapter.
***Network Topology for EIGRP Configuration***
R1 Router
R1>enable
Enters privileged mode.
R1#config t
Moves to global configuration mode.
@luisenriquecorona
luisenriquecorona / Config EIGRP Router 1 & 2.txt
Last active May 10, 2019 06:41
Shows the network topology for the configuration that follows, which shows how to configure EIGRP over MPLS where the MPLS PE devices are taking part in the EIGRP process.
***In this example, it is assumed that
the MPLS network is configured with the MPLS PE
devices participating in the EIGRP process and virtual route forwarding.
Only the client-side EIGRP configuration is shown here.***
R1 Router
R1(config)#interface fastethernet0/0
Enters interface configuration mode
@luisenriquecorona
luisenriquecorona / EIGRP over Frame Relay: Dynamic Mappings.txt
Last active November 18, 2022 21:40
Shows the network topology for the configuration that follows, which shows how to configure EIGRP over Frame Relay using dynamic mappings.
***Network Topology for EIGRP over Frame Relay Using Dynamic Mappings***
R1(config)#interface serial0/0/0
Enters interface configuration mode
R1(config-if)#ip address 192.168.1.101 255.255.255.0
Assigns the IP address and mask
R1(config-if)#encapsulation frame-relay
Enables Frame Relay on this interface
@luisenriquecorona
luisenriquecorona / AwesomeServer.cs
Created May 9, 2019 22:06
The server we will build is called AwesomeServer, an HTTP server that receives specific requests via files that are dropped in a folder on disk (instead of a network port) and then forwards them as proper HTTP requests to the rest of the request pipeline of the application. After the application processes the request, the returning response will…
public class AwesomeServer : IServer
{
public AwesomeServer(IOptions<AwesomeServerOptions> options)
{
Features.Set<IHttpRequestFeature>(new HttpRequestFeature());
Features.Set<IHttpResponseFeature>(new HttpResponseFeature());
var serverAddressesFeature = new ServerAddressesFeature();
serverAddressesFeature.Addresses.Add(options.Value.FolderPath);
Features.Set<IServerAddressesFeature>(serverAddressesFeature);
}