Skip to content

Instantly share code, notes, and snippets.

import * as React from "react";
import { useRef, useCallback, useInsertionEffect } from "react";
let _dispatcher = null;
function getCurrentDispatcher() {
return React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
.ReactCurrentDispatcher.current;
}
[
{"code": 47, "groups": ["corp", "fin"], "description": "Accounting"},
{
"code": 94,
"groups": ["man", "tech", "tran"],
"description": "Airlines/Aviation"
},
{
"code": 120,
"groups": ["leg", "org"],
@raibima
raibima / scrape.rs
Last active September 25, 2021 14:31
A Rust program to get the list of Traveloka's marketing job vacancies, compile and send the result via email.
use failure::Fallible;
use headless_chrome::Browser;
use lettre::Transport;
use lettre::{smtp::authentication::Credentials, SmtpClient};
use lettre_email::EmailBuilder;
use serde::{Deserialize, Serialize};
use std::env;
use std::time::{SystemTime, UNIX_EPOCH};
fn main() -> Fallible<()> {

Need to implement two interfaces:

  • function subscribeChatRoom(orderId, onMessage)
  • function sendMessage(orderId, message)

Message Schema

Message:

  • id (string)
  • created_at (timestamp)
  • message: (string)
@raibima
raibima / App.jsx
Created July 23, 2020 10:47
Vanilla JS Animation
import React, { useRef } from 'react';
/** @type Record<string, React.CSSProperties> */
const styles = {
root: {
width: '100vw',
height: '100vh',
display: 'flex',
alignItems: 'center',
paddingLeft: '5rem',
module.exports = function (babel) {
const { types: t } = babel;
let counter = 0;
const specialProps = {
padding: 1,
borderRadius: 1
};
let styles = null;
@raibima
raibima / generator-example.jsx
Created January 21, 2020 08:58
Generator Example 1
import { range, map } from './utils.js';
let iter = range(0, 1000); // almost-zero memory & computation overhead!
let list = (
<ul>
{map(iter, n => <li key={n}>{n}</li>)
</ul>
);
function createService<F extends (...args: any[]) => Promise<any>>(fn: F) {
type Result = PromiseType<ReturnType<typeof fn>>;
type Entry = Result | Promise<void> | Error;
// const cache = new LRU<string, Entry>({maxSize: 5});
const cache = new Map();
return {
call(...args: Parameters<typeof fn>): Result {
const key = JSON.stringify(args);
const hit = cache.get(key);
if (!hit) {
/**
* Function component with Hooks
* @see: https://reactjs.org/docs/hooks-intro.html
*/
import { useRouter } from "next/router";
function FunctionComponentPage() {
const router = useRouter();
return <h1>{`ID: ${router.query.id}`}</h1>;
}
const { useEffect, useState } = React;
export default function IndexPage(props) {
const [currentHash, setCurrentHash] = useState(window.location.hash);
useEffect(() => {
function handleHashChange(e) {
setCurrentHash(window.location.hash);
}
window.addEventListener('hashchange', handleHashChange);