Alex Chang

35 code snips · on codesnips 5 months

Front-end developer with 10+ years building modern web applications. Expert in responsive design, performance optimization, and accessibility. Passionate about creating...

css
/* 1. Mobile-first approach */
/* Base styles for mobile */
.container {
  width: 100%;
  padding: 1rem;
}

Responsive design patterns with CSS media queries

css responsive-design media-queries
by Alex Chang 1 tab
typescript
// 1. Basic types
let username: string = 'Alex';
let age: number = 30;
let isActive: boolean = true;
let items: string[] = ['item1', 'item2'];
let numbers: Array<number> = [1, 2, 3];

TypeScript fundamentals for type-safe front-end code

typescript javascript types
by Alex Chang 2 tabs
javascript
// 1. Create SVG elements
const svgNS = 'http://www.w3.org/2000/svg';

function createSVGElement(type, attributes = {}) {
  const element = document.createElementNS(svgNS, type);
  Object.entries(attributes).forEach(([key, value]) => {

SVG manipulation with JavaScript

svg javascript graphics
by Alex Chang 1 tab
javascript
// Get canvas and context
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');

// 1. Basic shapes
// Rectangle (filled)

Canvas API for graphics and animations

canvas javascript graphics
by Alex Chang 1 tab
javascript
// 1. Basic WebSocket connection
const socket = new WebSocket('wss://example.com/ws');

// Connection opened
socket.addEventListener('open', (event) => {
  console.log('Connected to WebSocket server');

WebSockets for real-time bidirectional communication

websockets real-time javascript
by Alex Chang 1 tab
javascript
// 1. localStorage basics
// Store data
localStorage.setItem('username', 'alex');
localStorage.setItem('theme', 'dark');

// Retrieve data

LocalStorage, SessionStorage, and IndexedDB

javascript localstorage indexeddb
by Alex Chang 1 tab
javascript
// 1. DANGEROUS: Never use innerHTML with user input
const userInput = '<img src=x onerror="alert('XSS')">';

// WRONG - vulnerable to XSS
document.getElementById('output').innerHTML = userInput;

Front-end security - XSS and CSRF prevention

security xss csrf
by Alex Chang 1 tab
javascript
// 1. Basic Custom Element
class MyButton extends HTMLElement {
  constructor() {
    super();

    // Attach shadow DOM

Web Components and Shadow DOM encapsulation

web-components shadow-dom custom-elements
by Alex Chang 1 tab
javascript
// service-worker.js

const CACHE_NAME = 'my-pwa-cache-v1';
const urlsToCache = [
  '/',
  '/index.html',

Progressive Web Apps - service workers and offline support

pwa service-workers offline-first
by Alex Chang 3 tabs
javascript
import React, { lazy, Suspense, useState, useEffect } from 'react';

// 1. Component lazy loading
const HeavyComponent = lazy(() => import('./HeavyComponent'));
const AdminPanel = lazy(() => import('./AdminPanel'));
const Dashboard = lazy(() => import('./Dashboard'));

Performance optimization - lazy loading and code splitting

performance optimization lazy-loading
by Alex Chang 2 tabs
javascript
import React, { createContext, useContext, useReducer, useState } from 'react';

// 1. Basic Context
const UserContext = createContext(null);

function UserProvider({ children }) {

State management with Context API and Redux patterns

react redux state-management
by Alex Chang 2 tabs
javascript
import React, { useState, useEffect, useCallback, useMemo, useRef, useContext } from 'react';

// 1. useState - managing component state
function Counter() {
  const [count, setCount] = useState(0);
  const [name, setName] = useState('');

React hooks - useState, useEffect, and custom hooks

react javascript hooks
by Alex Chang 1 tab