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 / httpGetAsync.js
Last active May 15, 2019 20:09
httpGetAsync Function Definition
let https = require('https');
function httpGetAsync(url,callback) {
return https.get(url,
function(response) {
var body = ";
response.on('data', function(d) {
body += d; });
response.on('end', function() {
let parsed = JSON.parse(body)
callback(parsed)
@luisenriquecorona
luisenriquecorona / setTimeout.js
Last active May 15, 2019 17:56
Simple Asynchronous Functions
let getDataOne = (cb) => {
setTimeout(function(){
//calling the callback
cb('dummy data one')
}, 1000);
}
let getDataTwo = (cb) => {
setTimeout(function(){
//calling the callback
cb('dummy data two')
@luisenriquecorona
luisenriquecorona / generatorSequence.js
Created May 15, 2019 17:46
Code for Understanding done Property
//get generator instance variable
let generatorSequenceResult =
generatorSequence();
console.log('done value for the first time',
generatorSequenceResult.next())
console.log('done value for the second time',
@luisenriquecorona
luisenriquecorona / getComments.js
Created May 15, 2019 16:17
We need to get its permalink value to get the list of comments. We can write a separate method for getting a list of comments for the given URL. We call this method getComments. The implementation of getComments is simple
let getComments = (link) => {
let response
try {
response = JSON.parse(request('GET',"https://www.
reddit.com/" + link).getBody('utf8'))
} catch(err) {
response = { message: "Something went wrong" ,
errorCode: err['statusCode'] }
}
return response
@luisenriquecorona
luisenriquecorona / JButtonClickedCounter.java
Created May 14, 2019 20:51
Let’s look at one more example of adding an Action listener to JButton. This time, we add two buttons to a JFrame: a Close button and another to display the number of times it is clicked. Every time the second button is clicked, its text is updated to show the number of times it has been clicked. You need to use an instance variable to maintain …
// JButtonClickedCounter.java
package com.jdojo.swing.intro;
import javax.swing.JFrame;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import java.awt.event.ActionListener;
public class JButtonClickedCounter extends JFrame {
int counter;
JButton counterButton = new JButton("Clicked #0");
@luisenriquecorona
luisenriquecorona / Message.js
Last active May 15, 2019 01:30
innerhtml Functions
function GetContent (){
var elem = document.getElementById ("my div");
var message = "";
if (elem.outerHTML !== undefined) {
message +="outerHTML:" + elem.outerHTML
@luisenriquecorona
luisenriquecorona / Keymap.js
Created May 14, 2019 00:48
Defines a Keymap class that maps keystroke identifiers such as “PageUp”, “Alt_Z”, and “ctrl+alt+shift+F5” to JavaScript functions that are invoked in response to those keystrokes. Pass key bindings to the Keymap() constructor in the form of a JavaScript object in which property names are keystroke identifiers and property values are handler func…
/*
* Keymap.js: bind key events to handler functions.
*
* This module defines a Keymap class. An instance of this class represents a
* mapping of key identifiers (defined below) to handler functions. A Keymap
* can be installed on an HTML element to handle keydown events. When such an
* event occurs, the Keymap uses its mapping to invoke the appropriate handler.
*
* When you create a Keymap, you can pass a JavaScript object that represents
* the initial set of bindings for the Keymap. The property names of this object
@luisenriquecorona
luisenriquecorona / Node MongoClient.js
Created May 13, 2019 20:33
Let’s have a look at how actual filters that match only some of our documents look like. We are going to rewrite our script because we need some more documents to play with
'use strict';
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect( 'mongodb://127.0.0.1:27017/accounting', function (err, connection) {
var collection = connection.collection('customers');
var doFind = function (callback) { collection.find().toArray(function (err, documents) {
console.dir(documents);
@luisenriquecorona
luisenriquecorona / Recipe01_02.vb
Created May 13, 2019 19:22
The Recipe01_02 class shown in the following code listing is a simple Windows Forms application that demonstrates the techniques just listed. When run, it prompts a user to enter a name and then displays a message box welcoming the user to Visual Basic 2005 Recipes.
Imports System
Imports System.Windows.Forms
Namespace
Apress.VisualBasicRecipes.Chapter01
Public Class Recipe01_02 Inherits Form
' Private members to hold references to the form's controls.
@luisenriquecorona
luisenriquecorona / ConsoleUtils.vb
Last active May 13, 2019 18:46
Visual BASIC 2005
Imports System
Namespace
Apress.VisualBasicRecipes.Chapter01
Public Class ConsoleUtils
' This method will display a prompt and read a response from the console.
Public Shared Function ReadString(ByVal message As String) As String