Skip to content

Instantly share code, notes, and snippets.

View choutkamartin's full-sized avatar

Martin Choutka choutkamartin

View GitHub Profile
@rphlmr
rphlmr / helpers.ts
Last active June 15, 2024 20:31
Drizzle ORM, deep sub queries
/* -------------------------------------------------------------------------- */
/* More here; */
/* -------------------------------------------------------------------------- */
//gist.github.com/rphlmr/0d1722a794ed5a16da0fdf6652902b15
https: export function distinctOn<Column extends AnyColumn>(column: Column) {
return sql<Column["_"]["data"]>`distinct on (${column}) ${column}`;
}
export function jsonBuildObject<T extends SelectedFields>(shape: T) {
@beppek
beppek / category.js
Last active February 5, 2023 00:48
Example of how to query multi level nested documents in Sanity
import { FcTreeStructure } from 'react-icons/fc';
export default {
name: 'category',
title: 'Category',
type: 'document',
icon: FcTreeStructure,
fields: [
{
name: 'title',
@agmm
agmm / nextjs-file-upload-api.js
Created January 31, 2020 23:03
Simple Nextjs File Upload — Backend API
// Backend
import formidable from 'formidable';
export const config = {
api: {
bodyParser: false,
},
};
export default async (req, res) => {
@zentala
zentala / formatBytes.js
Created September 27, 2017 11:57
Convert size in bytes to human readable format (JavaScript)
function formatBytes(bytes,decimals) {
if(bytes == 0) return '0 Bytes';
var k = 1024,
dm = decimals || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
// Usage:
@jgautheron
jgautheron / errorHandler.js
Created May 10, 2017 14:52
Send client errors to the server
import ReactUpdates from 'react-dom/lib/ReactUpdates'
import ReactDefaultBatchingStrategy from 'react-dom/lib/ReactDefaultBatchingStrategy'
import 'isomorphic-fetch'
const logError = (err, extra = {}) => {
fetch('/logger', {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@tzmartin
tzmartin / embedded-file-viewer.md
Last active June 20, 2024 07:38
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@lancejpollard
lancejpollard / meta-tags.md
Created March 5, 2012 13:54
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">