Skip to content

Instantly share code, notes, and snippets.

View nicolasembleton's full-sized avatar
🏠
Working from home

Nicolas Embleton nicolasembleton

🏠
Working from home
View GitHub Profile

Adapted from this recommendation by @jandockx

Cyclical objects

Despite supporting recursive schemas, passing cyclical data into Zod will cause an infinite loop in some cases.

You can protect against cyclical objects starting an infinite loop (at a performance cost) with the following approach (using the above jsonSchema as an example):

@Vectorized
Vectorized / YulSnippets.sol
Last active April 29, 2023 21:55
Solidity Yul Assembly Snippets
// SPDX-License-Identifier: MIT
// Author: vectorized.eth
pragma solidity ^0.8.0;
pragma abicoder v2;
// DISCLAIMER:
// This is experimental software and is provided on an "as is" and "as available" basis.
// We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
library Base64 {
@hayatoShingu
hayatoShingu / angularJS_lawnchair_wrapper.js
Last active November 8, 2018 08:44
It wraps Lawnchair as a provider, allowing you to set global configuration before your dependencies are getting injected
//inspired by https://github.com/wspringer/angular-pouchdb
//lawnchar simple wrapper
//
//It wraps Lawnchair as a provider, allowing you to set global configuration before your
//dependencies are getting injected
//
//It uses $q-based promises instead of callbacks: db.get({...}) will return a promise with the results,
//and no longer accepts a callback as the last parameter.
//The same goes for all other operations that normally required callbacks.
//
@branneman
branneman / better-nodejs-require-paths.md
Last active October 18, 2024 20:29
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@lfender6445
lfender6445 / query_to_hash.js
Created September 25, 2013 23:55
jQuery convert query string to json
query_to_hash = function() {
var j, q;
q = window.location.search.replace(/\?/, "").split("&");
j = {};
$.each(q, function(i, arr) {
arr = arr.split('=');
return j[arr[0]] = arr[1];
});
return j;
}
@cbednarski
cbednarski / gist:4555141
Created January 17, 2013 10:37
Sublime Text keymap, which fixes the really annoying Ctrl+Tab order behavior
[
{ "keys": ["ctrl+shift+t"], "command": "open_terminal_project_folder" },
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" }
]
@mattberg
mattberg / Parse.js
Created September 21, 2012 14:24
Simple Parse REST API module for Titanium
var baseUrl = 'https://api.parse.com/1',
appId = 'XXXXXXXXXXXXXXX',
apiKey = 'XXXXXXXXXXXXXX'; // make sure to use the REST API Key
var _register = function(params, lambda, lambdaerror) {
var method = 'POST',
url = baseUrl + '/installations',
payload = (params) ? JSON.stringify(params) : '';
_helper(url, method, payload, function(data, status) {
@FGRibreau
FGRibreau / existsSync.js
Last active July 17, 2023 10:19
existsSync - Check if a file exist in NodeJS
/*
fileExistSync - Check if a file exist in NodeJS
Twitter: @FGRibreau / fgribreau.com
Usage:
var fileExistSync = require('./fileExistSync');
var exist = fileExistSync('/var/folders/zm/jmjb49l172g6g/T/65b199');
Support for Nodev0.6
@domenic
domenic / portable-node.md
Created May 25, 2012 21:03
Tips for Writing Portable Node.js Code

Node.js core does its best to treat every platform equally. Even if most Node developers use OS X day to day, some use Windows, and most everyone deploys to Linux or Solaris. So it's important to keep your code portable between platforms, whether you're writing a library or an application.

Predictably, most cross-platform issues come from Windows. Things just work differently there! But if you're careful, and follow some simple best practices, your code can run just as well on Windows systems.

Paths and URLs

On Windows, paths are constructed with backslashes instead of forward slashes. So if you do your directory manipulation