Skip to content

Instantly share code, notes, and snippets.

@josephj
josephj / array_merge_recursive_distinct.php
Last active September 10, 2023 07:52
Useful PHP script when you want to merge multiple arrays like Y.merge().
<?php
/**
* Copy from http://www.php.net/manual/en/function.array-merge-recursive.php#92195
*
* array_merge_recursive does indeed merge arrays, but it converts values with duplicate
* keys to arrays rather than overwriting the value in the first array with the duplicate
* value in the second array, as array_merge does. I.e., with array_merge_recursive,
* this happens (documented behavior):
*
* array_merge_recursive(array('key' => 'org value'), array('key' => 'new value'));
@josephj
josephj / fsck-git-log.sh
Created July 27, 2012 03:37
檔案在 git pull 後被刪除、可以用 git fsck 救回來
# 這個時候檔案都已經做完,想要放到 Github 上
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git init .
Initialized empty Git repository in /var/www/josephj/frontend/lab/2012/qt-webkit/.git/
# Github 的 Repo 也已經開好了 (已經產生好 README.md)
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git remote add origin git@github.com:miiicasa/tv-apps-html.git
# 先試著從 Github 上抓東西下來
josephj@cockatoo /var/www/josephj/frontend/lab/2012/qt-webkit $ % git pull
remote: Counting objects: 3, done.
@josephj
josephj / index.html
Last active July 7, 2020 00:15
Electron show the images by their EXIF thumbnails
<!DOCTYPE html>
<html>
<head>
<title>Thumbnails</title>
</head>
<body>
<div>
<h2>Original</h2>
<img width="100" height="72" id="original" />
</div>
@josephj
josephj / index.html
Last active March 24, 2020 04:48
Electron Keyboard Prototype
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
<style>html, body {background: black; color: #fff}
button {padding: 10px; border-radius: 6px; border: none;}
</style>
</head>
@josephj
josephj / index.html
Created March 24, 2020 03:56
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
<style>html, body {background: black; color: #fff}
button {padding: 10px; border-radius: 6px; border: none;}
</style>
</head>
@josephj
josephj / index.html
Created February 7, 2020 01:01
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>File Listing</title>
</head>
<body>
<h1>File Listing</h1>
<section>
<input
@josephj
josephj / index.html
Created February 7, 2020 00:32
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>File Listing</title>
</head>
<body>
<h1>File Listing</h1>
<section>
<input
@josephj
josephj / index.html
Created February 7, 2020 00:23
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>File Listing</title>
</head>
<body>
<h1>File Listing</h1>
<section>
<input
@josephj
josephj / yui3-io-xdr-native-cookie.html
Created December 26, 2011 15:35
Get cross-domain cookie by using YUI3 io (native mode).
@josephj
josephj / express-try-catch.js
Last active August 23, 2018 08:19
Error Handling in Express.js
const express = require("express");
const app = express();
const fs = require("fs");
app.get("/", (req, res) => res.send("Hello World!"));
// Express will catch the errors in synchrous code #1
app.get("/error", (req, res) => {
throw new Error("Trigger error #1"); // try-catch is not necessary
});