Skip to content

Instantly share code, notes, and snippets.

View aquelito's full-sized avatar

Axel Roche aquelito

  • Craftsman developer
  • France
View GitHub Profile
@YagoLopez
YagoLopez / deep-search-javascript-object.js
Last active January 8, 2023 10:02
Deep search javascript object
/* 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
@wbotelhos
wbotelhos / libreadline_6_not_found.sh
Created November 29, 2016 20:42
Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
@ryanhanwu
ryanhanwu / mapViewController.m
Last active November 4, 2022 11:43
Calculate Google Map length in meters with zoom level in #Objective-C (converted from #JavaScript) #iOS #Swift
- (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];
}
@betweenbrain
betweenbrain / read-files.js
Created December 5, 2016 22:35
Node.js read multiple files, write into one
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)
@BinaryMuse
BinaryMuse / restful.js
Last active March 17, 2019 08:22
Express API with Async/Await
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) {
@dgmike
dgmike / gist:3815866
Created October 2, 2012 02:39 — forked from zuckercode/gist:3714230
redmine installer
# 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