Skip to content

Instantly share code, notes, and snippets.

View ilhamgusti's full-sized avatar
👀
whoopss

ilhamgusti ilhamgusti

👀
whoopss
View GitHub Profile
server {
listen 80;
listen [::]:80;
# Log files for Debugging
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;
# Webroot Directory for Laravel project
root /var/www/example.com/public;
@jochasinga
jochasinga / app.js
Last active May 8, 2021 20:16
Node/Socket.io server code for syncing data from Firebase
var Firebase = require("firebase");
var express = require("express");
// Create HTTP Server
var app = express();
var server = require("http").createServer(app);
// Attach Socket.io server
var io = require("socket.io")(server);
// Indicate port 3000 as host
var port = process.env.PORT || 3000;
@ilhamgusti
ilhamgusti / useForm.js
Created January 7, 2022 15:43
hooks for handle form input
import { useState } from "react";
function getInputOnChange(setValue) {
return (val) => {
if (!val) {
setValue(val);
} else if (typeof val === "function") {
setValue(val);
} else if (typeof val === "object" && "nativeEvent" in val) {
const { currentTarget } = val;
@ilhamgusti
ilhamgusti / mutableSet.js
Created April 28, 2022 08:11
writing mutable object safely
/**
*
* @param o Object to mutate
* @param ks array of keys, or string of keys
* @param v value to assign
* @param sep custom separator if keys is string. ex: ks:"INIxxADALAHxxKEY", sep is: "xx"
*/
function mutableSet(o, ks, v, sep = '.') {
ks.split && (ks=ks.split(sep));
let i=0, l=ks.length, t=o, x, k;
@ilhamgusti
ilhamgusti / hotkey-utilities.js
Created August 6, 2022 00:27
utility to handle hotkeys
export function parseHotkey(hotkey) {
const keys = hotkey
.toLowerCase()
.split('+')
.map((part) => part.trim());
const modifiers = {
alt: keys.includes('alt'),
ctrl: keys.includes('ctrl'),
@kyleshevlin
kyleshevlin / memoizedHandlers.js
Created January 22, 2021 00:26
Using React.useMemo to create a `handlers` object
// One of my new favorite React Hook patternms is to create handler
// functions for a custom hook using `React.useMemo` instead of
// `React.useCallback`, like so:
function useBool(initialState = false) {
const [state, setState] = React.useState(initialState)
// Instead of individual React.useCallbacks gathered into an object
// Let's memoize the whole object. Then, we can destructure the
// methods we need in our consuming component.
@tmslnz
tmslnz / dnsmasq.md
Last active March 20, 2023 07:07
Setting up dnsmasq on OS X

Install dnsmasq

Via brew or other method

Set up DNS resolver order

In order to work on every connection and on any TLD, dnsmasq needs to be the first DNS resolver receving the query.

And since dnsmasq is a local process, all DNS queries need to go to 127.0.0.1

On macOS, /etc/resolv.conf is automaticaly created, depending on a variety of things (network settings, etc), so it cannot be edited.

@gilbitron
gilbitron / CaddyController.php
Created June 16, 2021 10:55
Enabling HTTPS (SSL) for Laravel Sail using Caddy
<?php
# app/Http/Controllers/CaddyController.php
namespace App\Http\Controllers;
use App\Store;
use Illuminate\Http\Request;
class CaddyController extends Controller
{
@dtomasi
dtomasi / default
Last active December 8, 2023 04:20
Brew Nginx PHP7
server {
listen 80;
server_name localhost;
root /Users/YOUR_USERNAME/Sites;
access_log /Library/Logs/default.access.log main;
location / {
include /usr/local/etc/nginx/conf.d/php-fpm;
}
@zapthedingbat
zapthedingbat / logeverything.js
Created August 19, 2014 12:22
Log every function call to the console
(function() {
var call = Function.prototype.call;
Function.prototype.call = function() {
console.log(this, arguments);
return call.apply(this, arguments);
};
}());