Skip to content

Instantly share code, notes, and snippets.

@shiny
shiny / 多维数组.php
Last active April 28, 2019 06:36
多维数组.php
<?php
$a = [ 'Date','Media','Geo' ];
$b = [ 'Num' ];
$subject = [ 'Date'=>'2019-04-26','Media'=>'AAA','Geo'=>'CN','Num'=>105 ];
// 多维数组的最后一项
$value = array_intersect_key($subject, array_fill_keys($b, 1));
// 生成多维数组
$res = createMultiArray($a, $value, $subject);
var_dump([
@ruanyf
ruanyf / mtr.css
Created March 16, 2019 11:23
mtr.css: Hong Kong MTR station colors http://metrocolor.live/index.html
:root {
--heng-fa-chuen: #b51921;
--tai-koo: #b2103e;
--kowloon-bay: #c41832;
--tseung-kwan-o: #ef342a;
--wui-kai-sha: #a84d18;
--po-lam: #f68f26;
--sai-wan-ho: #faca07;
--disneyland-resort: #07594a;
--skek-kip-mei: #4ba946;
@ohmika
ohmika / iOS Shortcut Download JavaScript.txt
Created February 18, 2019 22:32
Use the bookmarklet or JavaScript in order to download the shortcut file from an icloud.com link
javascript:%22use%20strict%22;%0Alet%20iCloudUrl%20%3D%20location.href;%0Alet%20apiUrl%20%3D%20iCloudUrl.replace(/%5C/shortcuts/g,%20%22/shortcuts/api/records%22);%0Alet%20iCloudApi%20%3D%20new%20XMLHttpRequest();%0AiCloudApi.open(%22GET%22,%20apiUrl);%0AiCloudApi.responseType%20%3D%20%22text%22;%0AiCloudApi.send();%0A%0AiCloudApi.onload%20%3D%20function()%20%7B%0A%20%20let%20apiResult%20%3D%20JSON.parse(iCloudApi.response);%0A%0A%20%20function%20saveData(url)%20%7B%0A%20%20%20%20let%20a%20%3D%20document.createElement(%22a%22);%0A%20%20%20%20document.body.appendChild(a);%0A%20%20%20%20a.style%20%3D%20%22display:%20none%22;%0A%0A%20%20%20%20a.href%20%3D%20url;%0A%20%20%20%20a.download;%0A%20%20%20%20a.click();%0A%20%20%20%20window.URL.revokeObjectURL(url);%0A%20%20%7D%0A%20%20let%20downloadURL%20%3D%20apiResult.fields.shortcut.value.downloadURL;%0A%20%20let%20shortcutName%20%3D%20apiResult.fields.name.value;%0A%20%20let%20finalURL%20%3D%20downloadURL.replace(%22$%7Bf%7D%22,%20shortcutName%20+%20%22.shortcut%22
@mjgarton
mjgarton / plumber.go
Last active October 14, 2023 15:22
"plumber" message munging application
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"log"
"os"
@LauLaman
LauLaman / Mojave-nfs.md
Last active May 28, 2021 18:01
Vagrant nfs mount Mac OS X Mojave
  1. Mac OS X system settings > Security & Privacy > privacy tab

  2. Select Full Disk Access and click plus icon.

  3. Add terminal in the list ( in my case iTerm)

  4. Restart iTerm

  5. Run command in iterm: $ cd /private/etc && sudo touch ./exports

  6. Start virtual machine trough vargrant: Profit

@kcrawford
kcrawford / gist:00994c6246472d73e6a8893cb84d3e9c
Last active April 20, 2024 20:23 — forked from chbeer/gist:3666e4b7b2e71eb47b15eaae63d4192f
Calling AppleScript from Swift App, passing a parameter. Basic
import Carbon
//guard let url = Bundle.main.url(forResource: "SendFinderMessage", withExtension: "scpt") else {
// exit(0)
//}
//guard let script = NSAppleScript(contentsOf: url, error: &errors) else {
// exit(0)
//}
@AshikNesin
AshikNesin / base64-form-data.js
Last active February 22, 2025 17:30
Base64 image to multipart/form-data
const base64 = 'data:image/png;base64,....' // Place your base64 url here.
fetch(base64)
.then(res => res.blob())
.then(blob => {
const fd = new FormData();
const file = new File([blob], "filename.jpeg");
fd.append('image', file)
// Let's upload the file
// Don't set contentType manually → https://github.com/github/fetch/issues/505#issuecomment-293064470
@iannbing
iannbing / ._reactFormatting
Last active November 15, 2022 17:04
A gist for initial eslint and prettier setup for React projects
We couldn’t find that file to show.
@IsaacXen
IsaacXen / TextField.swift
Last active March 16, 2023 12:36
NSTextField subclass with focus and blur callback.
import Cocoa
protocol TextFieldDelegate: class {
func textFieldDidBecomeFirstResponder(_ textField: TextField)
func textFieldDidResignFirstResponder(_ textField: TextField)
}
class TextField: NSTextField {
weak var firstResponderDelegate: TextFieldDelegate?
@banks
banks / ecdh.go
Last active April 23, 2020 02:12
// ecdh implements a simple way to perform Diffie-Hellman Key Exchange using
// Curve25519 on the command line.
//
// NOTE: this is a toy for fun. Don't use it.
//
// See https://godoc.org/golang.org/x/crypto/curve25519 and
// https://cr.yp.to/ecdh.html for more info.
//
// The final shared secret given is the raw shared secret bytes from DH and is
// not typically suitable for direct use as an encryption key as it can leak