Skip to content

Instantly share code, notes, and snippets.

Avatar

Axel Roche aquelito

View GitHub Profile
@stewartmcgown
stewartmcgown / partialMatch.js
Created Jan 15, 2019
Partial Match properties of Object Array (ES6)
View partialMatch.js
/**
* Are all the values on p present on o
* @param {Object} o object to search
* @param {Object} p object of search values
* @param {Boolean} [c] are loose equality matches ok?
* @return {Boolean} whether there are partial matches
*/
const partialMatch = (o, p, c) =>
Object.keys(p).every(k =>
p[k] && o[k]
@YagoLopez
YagoLopez / deep-search-javascript-object.js
Last active Feb 2, 2021
Deep search javascript object
View deep-search-javascript-object.js
/* Attribution: http://techslides.com/how-to-parse-and-search-json-in-javascript */
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
@betweenbrain
betweenbrain / read-files.js
Created Dec 5, 2016
Node.js read multiple files, write into one
View read-files.js
var fs = require('fs');
var Promise = require('promise');
var promises = [];
var readline = require('readline');
var readFile = function (file) {
return new Promise(function (resolve, reject) {
var lines = [];
var rl = readline.createInterface({
input: fs.createReadStream('./logs/' + file)
@wbotelhos
wbotelhos / libreadline_6_not_found.sh
Created Nov 29, 2016
Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
View libreadline_6_not_found.sh
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
@facine
facine / __INDEX.txt
Last active Nov 29, 2020
Drupal 8 - Examples
View __INDEX.txt
# Taxonomy terms:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_taxonomy_term-php
# Menu links:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_menu_link-php
# File items:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_file-php
# Nodes:
@BinaryMuse
BinaryMuse / restful.js
Last active Mar 17, 2019
Express API with Async/Await
View restful.js
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {
@ryanhanwu
ryanhanwu / mapViewController.m
Last active Aug 7, 2020
Calculate Google Map length in meters with zoom level in #Objective-C (converted from #JavaScript) #iOS #Swift
View mapViewController.m
- (void)mapView:(GMSMapView*)mapView idleAtCameraPosition:(GMSCameraPosition*)position
{
CLLocationCoordinate2D topLeft = mapView.projection.visibleRegion.farLeft;
CLLocationCoordinate2D bottomLeft = mapView.projection.visibleRegion.nearLeft;
double lat = fabs(topLeft.latitude - bottomLeft.latitude);
double mpp = cos(lat * M_PI / 180) * 2 * M_PI * 6378137 / (256 * pow(2, mapView.camera.zoom));
double distance = mpp * mapView.frame.size.width;
[[SearchManager shareInstance] distance: distance];
}
@nicoptere
nicoptere / THREE.js lon_lat_to_cartesian
Last active Feb 19, 2021
methods to convert longitude / latitude to XYZ and back + utility polygon contains point for THREE.js
View THREE.js lon_lat_to_cartesian
/**
* converts a XYZ vector3 to longitude latitude (Direct Polar)
* @param lng longitude
* @param lat latitude
* @param vector3 optional output vector3
* @returns a unit vector of the 3d position
*/
function lonLatToVector3( lng, lat, out )
{
out = out || new THREE.Vector3();
@facultymatt
facultymatt / roles_invesitgation.md
Last active Feb 2, 2021
Roles and permissions system for Nodejs
View roles_invesitgation.md
@dgmike
dgmike / gist:3815866
Created Oct 2, 2012 — forked from zuckercode/gist:3714230
redmine installer
View gist:3815866
# add database 'redmine' and user 'redmine' to mysql
aptitude -y install ruby libruby libopenssl-ruby libpgsql-ruby rubygems apache2 libapache2-mod-passenger
aptitude -y install subversion
aptitude -y install install libmysql-ruby libmysqlclient-dev
aptitude install libpq-dev libsqlite3-dev libmagick9-dev graphicsmagick-libmagick-dev-compat
cd /var/www
svn co http://redmine.rubyforge.org/svn/branches/2.0-stable redmine
cd redmine
cp config/database.yml.example config/database.yml
vim config/database.yml