Kam
mdfind, a command that marries speed with precision. What makes it stand head and shoulders above the rest?
mdfind is like having Spotlight’s capabilities in the command line. While many search tools painstakingly peruse your filesystem, mdfind operates on a shortcut. It pulls results from the 'metadata store' or mdstore - a continuously updated catalog. Imagine pulling a specific card from a neatly organized card catalog versus skimming through an entire bookshelf.
mdfind sizes up against find:
Speed - mdfind excels with its indexed search, while find delves deep into the filesystem, making it relatively slower.
Scope - find restricts itself to file attributes like name, size, or date. Meanwhile, mdfind penetrates metadata, fishing out intricate details such as tags or document content.
Flexibility - find pulls ahead in adaptability, with a diverse range of operators for detailed searches, an aspect where mdfind plays catch-up.
mdfind to work, here are some straightforward commands:
mdfind -onlyin ~/Documents "pdf"
mdfind -onlyin ~/Downloads "image"
mdfind -name "report"
mdfind "unicorn"
Using mdfind, file hunting on macOS transforms into a swift, precise adventure. Once you take it for a spin, it's likely to find a permanent spot in your developer toolkit!Kam
Kam
Kam
https://i.imgur.com/rpkOrwA.gif▾
https://i.imgur.com/vDgic41.gif▾
Kam
Kam
https://static.main.linendev.com/attachments/5b12e431-c19b-426d-a9a3-0df889e1ac22/Screen_Shot_2023-04-26_at_12.02.57_PM.jpg▾
Kam
Kam
https://user-images.githubusercontent.com/4218509/200422983-21079c4a-bcb6-4f48-bf82-fdf9d01f1d3f.png▾
jsx
function useWebSockets({ room, token, permissions, onNewMessage }: Props) {
const [channel, setChannel] = useState<Channel>();
const [connected, setConnected] = useState<boolean>(false);
useEffect(() => {
if (permissions.chat && token && room) {
//Set url instead of hard coding
const socket = new Socket(
`${process.env.NEXT_PUBLIC_PUSH_SERVICE_URL}/socket`,
{ params: { token } }
);
socket.connect();
const channel = socket.channel(room);
setChannel(channel);
channel
.join()
.receive('ok', () => {
setConnected(true);
})
.receive('error', () => {
setConnected(false);
});
channel.on('new_msg', onNewMessage);
return () => {
setConnected(false);
socket.disconnect();
};
}
return () => {};
}, []);
useEffect(() => {
channel?.off('new_msg');
channel?.on('new_msg', onNewMessage);
}, [onNewMessage]);
return { connected, channel };
}
jsx
return fetch(`/api/messages/channel`, {
method: 'POST',
body: JSON.stringify({
communityId,
body: message,
files,
channelId,
imitationId,
}),
});
},
jsx
const thread = await prisma.threads.create({
data: {
channel: { connect: { id: channelId } },
sentAt: sentAt.getTime(),
lastReplyAt: sentAt.getTime(),
messageCount: 1,
messages,
} as Prisma.threadsCreateInput
...
});
jsx
export const push = ({
channelId,
threadId,
messageId,
isThread,
isReply,
message,
thread,
}: PushType) => {
return request.post(`${pushURL}/api/message`).send({
channel_id: channelId,
thread_id: threadId,
message_id: messageId,
is_thread: isThread,
is_reply: isReply,
message,
thread,
token,
});
};
def create(conn, params) do
%{
"channel_id" => channel_id,
"token" => token
} = params
PushServiceWeb.Endpoint.broadcast!("room:lobby:" <> channel_id, "new_msg", params)
end
We’re using Phoenix channels which handles the broadcast automatically see: https://hexdocs.pm/phoenix/channels.html for more information
def join("room:" <> community_id, _params, socket) do
current_user = socket.assigns[:current_user]
{:ok, assign(socket, :community_id, community_id)}
end
end
Emil Ajdyna
sass, which can help you split or abstract css even further.
Here's how it'd would look like for a simple Card component.
/* Card.tsx */
import React from 'react'
import styles from './index.module.scss'
interface Props {
children: React.ReactNode;
}
export default function Card ({ children }: Props) {
return <div className={styles.card}>{children}</div>
}
dist/index.js and dist/index.css.
You'll need to include the css file manually inside of your app.
Configuration wise, we'll need to setup a build process that creates a bundle for us.
Here's an example rollup configuration file.
/* rollup.config.js */
const resolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('@rollup/plugin-typescript');
const postcss = require('rollup-plugin-postcss');
const external = require('rollup-plugin-peer-deps-external');
module.exports = {
input: 'src/index.tsx',
output: {
file: 'dist/index.js',
format: 'cjs',
},
plugins: [
resolve(),
postcss({
extract: true,
modules: true,
use: ['sass'],
}),
commonjs(),
typescript({ tsconfig: './tsconfig.json' }),
external(),
],
};
It's using few dependencies:
npm install --save-dev rollup
npm install --save-dev @rollup/plugin-node-resolve
npm install --save-dev @rollup/plugin-commonjs
npm install --save-dev @rollup/plugin-typescript
npm install --save-dev rollup-plugin-postcss
npm install --save-dev rollup-plugin-peer-deps-external
npm install --save-dev sass
You should also install react.
npm install react
At this point, running npx rollup --config rollup.config.js would create a bundle that includes react.
We shouldn't include react there, e.g. because if would significantly increase your app size if you're using a different react version or cause other unintended side effects.
The solution for this is to move react to peerDependencies inside of package.json.
npm does not offer a shortcut for installing peer dependencies yet (2022), so you need to do it manually.
jest test setup.
https://github.com/Linen-dev/linen.dev/tree/main/packages/ui
I hope this short article helps even a little :). In case of any questions, just ask them in the thread.