Skip to content

Instantly share code, notes, and snippets.

View ritch's full-sized avatar

Ritchie Martori ritch

  • Fremont, California
View GitHub Profile
@ritch
ritch / ex.js
Last active September 6, 2023 04:27
What is the best way to document complex / dynamic objects as arguments to a function?
/**
* Below are several examples of methods that are difficult to clearly annotate with JSDoc annotations.
*/
/**
* @param {Object} people An index of people keyed by a person's name
* @returns {Object} map An index of zipcodes keyed by a person's name
*/
function find(people) {
@ritch
ritch / thumbnails.py
Created June 10, 2022 22:14
Fiftyone Media Fields Example
import os
import shutil
import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.image as foui
fo.core.dataset.delete_non_persistent_datasets()
exampleName = 'thumbnail-example'
@ritch
ritch / example.js
Last active June 6, 2018 10:19
LoopBack example for accessing the current user.
/**
* Dependencies
*/
var request = require('request');
var loopback = require('loopback');
var app = loopback();
var memoryDataSource = loopback.memory();
var HEADER_NAME = 'x-access-token'; // subject to change
interface Envelope {
writeToResponse()
}
class File extends Envelope {
writeToResponse(res) {
res.setHeader('content-type', this.getContentType())
this.readableStream.pipe(res)
}
}
@ritch
ritch / preferences.js
Last active February 2, 2017 00:14
Input files for the Express.js scaffolding tool
var $ = exports
$.GENERATORS = [
'package',
'app',
'error',
'start',
'resource',
'view',
'orm',
@ritch
ritch / co-loopback.js
Last active June 8, 2016 04:31
LoopBack w/ a co-routine based API
var co = require('co');
var thunk = require('thunkify');
var loopback = require('loopback');
var memory = loopback.memory();
var product = memory.createModel('memory');
// thunkify the loopback model
thunkify();
// create some products in parallel
@ritch
ritch / user.java
Last active December 31, 2015 23:29
LoopBack LBUser in iOS
// UserRepository and User do not exist in the sdk
UserRepository repository = adapter.createRepository(UserRepository.class);
HashMap attributes = new HashMap<String, Object>();
attributes.put("email", "me@domain.com");
attributes.put("password", "secret");
User me = repository.createModel(attributes);
me.save(new Model.Callback() {
@Override
public void onSuccess() {
// DAO
function create(obj, callback) {
var Model = this;
var ctx = new EventEmitter();
ctx.data = obj;
ctx.callback = callback;
Model.emit('create:start', ctx);
@ritch
ritch / 0-view.html
Last active December 28, 2015 11:38
An end to end example integrating LoopBack, Angular, and MySQL. Run the full app - http://loopback-foodme.herokuapp.com View the source - http://github.com/ritch/loopback-foodme
<!--
An Angular View to render a list of Restaurants
-->
<table class="table table-hover table-striped" ng-controller="RestaurantsController">
<tr ng-repeat="restaurant in restaurants">
<td>
<a href="#/menu/{{restaurant.id}}">
<img class="img-rounded pull-left" ng-src="img/restaurants/{{restaurant.shortName}}.jpg">
<b>{{restaurant.name}}</b>
</a>
@ritch
ritch / RestaurantsController.js
Created November 16, 2013 00:52
Connecting Angular to MySQL through LoopBack
app.controller('RestaurantsController',
function RestaurantsController(Restaurant) {
$scope.restaurants = Restaurant.query(filterAndSortRestaurants);
});