Skip to content

Instantly share code, notes, and snippets.

View pavinduLakshan's full-sized avatar
🎯
Focusing

Pavindu Lakshan pavinduLakshan

🎯
Focusing
View GitHub Profile
public class MulticastClient{
public final static int MULTICAST_PORT = 50001;
public final static String MULTICAST_GROUP = "127.0.0.1";
public static void main(String[] args){
try {
MulticastSocket clientSocket = new MulticastSocket(MULTICAST_PORT);
clientSocket.joinGroup(InetAddress.getByName(MULTICAST_GROUP));
byte[] dataBuffer = new byte[];
DatagramPacket inputPacket = new DatagramPacket();
public class MulticastServer {
public final static int MULTICAST_PORT = 50001;
public final static String MULTICAST_GROUP = "127.0.0.1";
public static void main(String[] args){
try {
DatagramSocket serverSocket = new DatagramSocket();
byte[] dataBuffer = new byte[1024];
DatagramPacket outputPacket = new DatagramPacket(
import React, { useState, useEffect } from 'react';
import { generatePath } from "react-router";
const GeneratePathExample = () => {
const [isPosts, setIsPosts] = useState(false);
let url = generatePath("/user/:id/:entity(posts|comments)", {
id: 1,
entity: isPosts ? "posts" : "comments"
})
import React from "react";
import ReactDOMServer from "react-dom/server";
import { StaticRouter } from "react-router";
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
// This context object contains the results of the render
const context = {};
import React from 'react';
import { shallow, mount } from 'enzyme';
import Routes from './Routes';
import Home from './Home';
import { MemoryRouter } from 'react-router'
describe('routes using memory router', () => {
it('should show Home component for / route', () => {
const component = mount(
<MemoryRouter initialEntries="{['/']}">
import React, {useState} from 'react';
import {Prompt} from 'react-router-dom';
const PromptExample = () => {
const [isCompleted,setCompleted] = useState(false);
return (
<>
<Prompt
when={!isCompleted}
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
public class SocketClient {
public static void main(String[] args){
try {
Socket clientSocket = new Socket ("localhost",50001);
InputStream is = clientSocket.getInputStream();
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class SocketServer {
public static final int SERVER_PORT = 50001;
public static void main (String[] args){
import * as React from 'react';
import { Text } from 'react-native';
import { useIsFocused } from '@react-navigation/native';
function Profile() {
// This hook returns `true` if the screen is focused, `false` otherwise
const isFocused = useIsFocused();
return <Text>{isFocused ? 'focused' : 'unfocused'}</Text>;
}
import { useFocusEffect } from '@react-navigation/native';
function Profile() {
useFocusEffect(
React.useCallback(() => {
// Do something when the screen is focused
return () => {
// Do something when the screen is unfocused
// Useful for cleanup functions