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 / initPage.js
Created June 15, 2019 20:20
Add a call to pirateManager.subscribeToPush in the peggy_parrot script on the check to see if notifications have been enabled
document.addEventListener('DOMContentLoaded', initPage, false);
function initPage() {
if (!('Notification' in window)) {
// this browser does not support notifications
} else if (Notification.permission === 'denied') {
// the user denied notification permission!
else if (Notification.permission === 'granted') {
pirateManager.subscribeToPush();
} ...
function enableNotifications() {
@luisenriquecorona
luisenriquecorona / JQueryFn.js
Created June 7, 2019 00:39
It is almost trivially easy to write your own jQuery extensions. The trick is to know that jQuery.fn is the prototype object for all jQuery objects. If you add a function to this object, that function becomes a jQuery method
jQuery.fn.println = function() {
// Join all the arguments into a space-separated string
var msg = Array.prototype.join.call(arguments, " ");
// Loop through each element in the jQuery object
this.each(function() {
// For each one, append the string as plain text, then append a <br/>.
jQuery(this).append(document.createTextNode(msg)).append("<br/>");
});
// Return the unmodified jQuery object for method chaining
return this;
@luisenriquecorona
luisenriquecorona / ParsingHTTPResponse.js
Created June 7, 2019 00:14
Checks the “Content-Type” header of the response and handles “application/json” responses specially. Another response type that you might want to “decode” specially is “application/javascript” or “text/javascript”.
// Issue an HTTP GET request for the contents of the specified URL.
// When the response arrives, pass it to the callback function as a
// parsed XML Document object, a JSON-parsed object, or a string.
function get(url, callback) {
var request = new XMLHttpRequest(); // Create new request
request.open("GET", url); // Specify URL to fetch
request.onreadystatechange = function() { // Define event listener
// If the request is compete and was successful
if (request.readyState === 4 && request.status === 200) {
// Get the type of the response
@luisenriquecorona
luisenriquecorona / getText.js
Created June 6, 2019 00:47
defines a getText() function that demonstrates how to listen for ready- statechange events. The event handler first ensures that the request is complete.
// Issue an HTTP GET request for the contents of the specified URL.
// When the response arrives successfully, verify that it is plain text
// and if so, pass it to the specified callback function
function getText(url, callback) {
var request = new XMLHttpRequest(); // Create new request
request.open("GET", url); // Specify URL to fetch
request.onreadystatechange = function() { // Define event listener
// If the request is compete and was successful
if (request.readyState === 4 && request.status === 200) {
var type = request.getResponseHeader("Content-Type");
@luisenriquecorona
luisenriquecorona / postMessage.js
Created June 5, 2019 22:56
uses each of the XMLHttpRequest. It POSTs a string of text to a server and ignores any response the server sends.
function postMessage(msg) {
var request = new XMLHttpRequest(); // New request
request.open("POST", "/log.php"); // POST to a server-side script
// Send the message, in plain-text, as the request body
request.setRequestHeader("Content-Type", // Request body will be plain text
"text/plain;charset=UTF-8");
request.send(msg); // Send msg as the request body
// The request is done. We ignore any response or any error.
}
@luisenriquecorona
luisenriquecorona / XMLHttpRequest.js
Created June 4, 2019 21:23
Intercepting network requests HTTPrequest using the XMLHTTPRequest object
var request;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
request = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
request = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {}
@luisenriquecorona
luisenriquecorona / Angular.js
Created May 22, 2019 21:21
Angular And NodeJS
'use strict';
var request = require('request');
var dbSession = require('../../src/backend/dbSession.js');
var resetDatabase = require('../resetDatabase.js');
var async = require('async');
describe('The API', function () {
it('should respond to a GET request at /api/keywords/', function (done) {
var expected = {
"_items": [
{'id': 1, 'value': 'Aubergine', 'categoryID': 1},
@luisenriquecorona
luisenriquecorona / JSX.js
Created May 16, 2019 23:18
Let's start by creating a simple repetition, without worrying about the keys yet. For this we are going to need a component that has a property or state with an array value. In the render () method we will do the repetition in that array, creating a list element for each item of the array.
import React, { Component } from 'react';
class RepeatComponent extends Component {
constructor(props) {
super(props);
this.state = {
lenguajes: ['Javascript', 'JSX', 'Typescript', 'NodeJS']
}
}
render() {
@luisenriquecorona
luisenriquecorona / ReactJS.js
Created May 16, 2019 22:10
Each property is indicated as if it were an HTML attribute, to which we indicate its value. This would be a code where the FeedbackMessage component is used, indicating the values ​​of its properties.
import React, { Component } from 'react'
import FeedbackMessage from './FeedbackMessage'
class App extends Component {
render() {
return (
<div className="App">
<FeedbackMessage name="SoyLuisCorona" app="My App React" />
</div>
@luisenriquecorona
luisenriquecorona / createClass.html
Created May 16, 2019 19:02
A component that we created using createClass () does not produce any output. We will have to use the component so that we can actually see it working on the page. This part requires the other piece of React we need to operate: React-DOM.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test React from a blank page</title>
</head>
<body>
<div id="anchorage"></div>