Skip to content

Instantly share code, notes, and snippets.

View bwyx's full-sized avatar
😡

bayu bwyx

😡
View GitHub Profile
// temporary solution since there is no typescript definition for qiscus,
// TODO: publish this type definition to npm
declare module 'qiscus-sdk-core' {
interface InitOptions {
AppId: string
options?: {
baseUrl?: string
[key: string]: unknown
}
{
"forecast": [1, 2, 3, 4, 5],
"history": [10, 23, 4, 14, 5]
}
@bwyx
bwyx / qiscus-sdk-core.d.ts
Created May 18, 2024 09:20
qiscus-sdk-core@^2 uncompleted type definitions
// qiscus-sdk-core@^2 uncompleted type definitions
declare module 'qiscus-sdk-core' {
interface InitOptions {
AppId: string
options?: {
baseUrl?: string
[key: string]: unknown
}
}
import crypto from 'crypto'
import cryptoRandomString from 'crypto-random-string'
const key = 'secret'
const createSignature = (text) => {
const hmac = crypto.createHmac('sha256', key)
hmac.update(text)
return hmac.digest('base64')
}
#include <stdio.h>
#include <X11/Xlib.h>
int main(void) {
Display *dpy = XOpenDisplay(":0");
XKeyboardState x;
XGetKeyboardControl(dpy, &x);
XCloseDisplay(dpy);
printf("led_mask=%lx\n", x.led_mask);
printf("NumLock is %s\n", (x.led_mask & 2) ? "On" : "Off");
@bwyx
bwyx / nginx_assets.md
Created October 23, 2021 17:41 — forked from vishaltelangre/nginx_assets.md
Serving Static Assets via Nginx

Concept

  • People talk about two servers: a web server (e.g. Nginx, Apache, etc.) and a app server (e.g. Language specific servers like Unicorn, Node.js, Tomcat, Http-Kit, etc.). There are exceptions where app servers not required at all (as web server itself provides preprocessors for handling), but let's not talk about now.
  • Web servers are really fast and supports lot of standard and commonly used MIME-type requests. Concept of serving a file is -- forming and sending a response of bytes of data and labeling it with requested MIME-type by a client (e.g. web browser).
  • Every response format (in layman's language, a file) is recognized by it's MIME-type, for e.g. a PNG image file has "image/png" MIME-type. JavaScript file has "text/javascript". HTML responses (or files) has "text/html". Plain text files have "text/plain".
  • Modern Browsers supports a lot of standard MIME-types. Images, videos, text files (XML, HTML, SVG, JS), and they better know how to visualize it. Browser also knows unrec

Keybase proof

I hereby claim:

  • I am bwyx on github.
  • I am bwyx (https://keybase.io/bwyx) on keybase.
  • I have a public key ASAk4uqNLElrvOMSohp38UpwbpmL8CyxYx9et5LsT9n7fgo

To claim this, I am signing this object:

@bwyx
bwyx / CA.md
Last active August 25, 2021 03:03
self signed ssl linux

Source

With only 5 openssl commands, you can accomplish this. (Please don't change your browser security settings.)

With the following code, you can

  1. become your own CA
  2. then sign your SSL certificate as a CA.
  3. Then import the CA certificate (not the SSL certificate, which goes onto your server) into Chrome/Chromium. (Yes, this works even on Linux.)
# Summary: Recommended confusable mapping for IDN
# File: confusablesSummary.txt
# Version: 2.1-draft
# Generated: 2010-04-13, 01:33:25 GMT
# Checkin: $Revision: 1.29 $
#
# For documentation and usage, see http://www.unicode.org/reports/tr39/
#
#   ᠎ 
 
                          
@bwyx
bwyx / pick.ts
Created May 14, 2021 17:25
'pick' utility in typescript
const pick = <T, K extends keyof T>(object: T, keys: K[]): Pick<T, K> => {
return Object.assign(
{},
...keys.map(key => {
if (object && Object.prototype.hasOwnProperty.call(object, key)) {
return { [key]: object[key] };
}
})
);
};