Skip to content

Instantly share code, notes, and snippets.

View quanfoo's full-sized avatar

Quan Nguyen quanfoo

  • Ho Chi Minh City, Vietnam
View GitHub Profile
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
import http.client
import json
import time
conn = http.client.HTTPSConnection('uinames.com', 443)
def request():
conn.request('GET', '/api/')
res = conn.getresponse()
const https = require('https');
const url = 'https://uinames.com/api/';
function request(url) {
return new Promise((resolve, reject) => {
let data = '';
https
.get(url, (res) => {
res.on('data', (chunk) => data += chunk);
@quanfoo
quanfoo / concurrent_requests.go
Last active May 4, 2020 09:20
concurrent_requests.go
package main
import (
"encoding/json"
"fmt"
"net/http"
"sync"
"time"
)
function buildGrid(nodeNum, nodeDists) {
const grid = [];
for (let i = 0; i < nodeNum; i++) {
const row = [];
for (let j = 0; j < nodeNum; j++) {
if (j <= i + nodeDists[i] && j >= i - nodeDists[i]) {
row[j] = i + nodeDists[i] <= nodeNum - 1 ? i + nodeDists[i] : nodeNum - 1;
} else {
row[j] = -1;
}
function randomObject(level) {
const obj = {};
for (let i = 97; i <= 110; i++) {
const dice = Math.random();
const key = String.fromCharCode(i);
if (dice < 0.33) {
obj[key] = i;
} else if (dice < 0.66) {
obj[key] = () => {};
} else {
class Vertex:
def __init__(self, name, email, adj = []):
self.name = name
self.email = email
self.adj = adj
self.marked = False
def add_adj(self, v):
if v not in self.adj:
self.adj.append(v)
import java.util.*;
public class MyClass {
public static void main(String[] args) {
User user = new User("Michael");
Robot robot = new Robot("Lisa");
ArrayList<Scorable> players = new ArrayList<Scorable>();
players.add(user);
players.add(robot);
function Square({ value, style, onClick }) {
return (
<button className="square" onClick={onClick} style={{background: style}}>
{value}
</button>
);
}
function Board({ squares, winner, onClick }) {
function renderSquare(i) {