Skip to content

Instantly share code, notes, and snippets.

View rigobertocontreras's full-sized avatar

Rigoberto Contreras rigobertocontreras

  • United States
View GitHub Profile
@rigobertocontreras
rigobertocontreras / app.js
Created March 10, 2017 05:15 — forked from stongo/app.js
Joi validation in a Mongoose model
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', function() {
return console.error.bind(console, 'connection error: ');
});
@rigobertocontreras
rigobertocontreras / front.html
Created August 5, 2017 21:10 — forked from randerzander/front.html
zeppelin angular-tricks
%angular
<input id="textbox" class="hide" ng-model="someAngularVar"></input>
<button id="btn" type="submit" onclick="update()">UpperCase It!</button>
<script type="text/javascript">
function update(){
var element = $('#textbox');
var currentVal = element.val();
//Update the value
element.val(currentVal.toUpperCase());
@rigobertocontreras
rigobertocontreras / notes.md
Created November 8, 2017 03:46 — forked from mindscratch/notes.md
Debugging PHP Running in a Docker Container with XDebug and PHPStorm on macOS Sierra

I used docker compose to stand up MariaDB and Apache web server in containers.

xdebug

I'm using php7 with CentOS 7.2. I had to install "php70w-pecl-xdebug.x86_64". I also added the following the Dockerfile

RUN echo "xdebug.idekey = PHPSTORM" >> /etc/php.d/xdebug.ini &&
echo "xdebug.default_enable = 0" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_enable = 1" >> /etc/php.d/xdebug.ini &&
echo "xdebug.remote_autostart = 0" >> /etc/php.d/xdebug.ini && \

@rigobertocontreras
rigobertocontreras / execAsync.js
Created May 18, 2018 16:23 — forked from davidrleonard/execAsync.js
Node exec async (with shell.js and bluebird)
const Promise = require('bluebird');
const sh = require('shelljs');
/**
* Asynchronously executes a shell command and returns a promise that resolves
* with the result.
*
* The `opts` object will be passed to shelljs's `exec()` and then to Node's native
* `child_process.exec()`. The most commonly used opts properties are:
*
@rigobertocontreras
rigobertocontreras / AcmeExtension.php
Created August 16, 2018 18:24 — forked from chalasr/AcmeExtension.php
Load configuration files depending on host in Symfony
// src/AcmeBundle/DependencyInjection/AcmeExtension.php
<?php
namespace AcmeBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
// Save JSON of full schema introspection
import {graphql, introspectionQuery, printSchema} from "graphql";
import {writeFileSync} from "fs";
import {join} from "path";
import schema from "./index";
function generate() {
(async () => {
const result = await (graphql(schema, introspectionQuery));
if (result.errors) {
@rigobertocontreras
rigobertocontreras / domino.ts
Created January 5, 2019 16:44
Function to parse domino strings recursive.
/*
Given a string, representing domino tiles chain. Each tile has L-R format, where L and R are numbers from 1..6 range. Tiles are separated by the comma. Some examples of valid S chain are:
1. 1-4,4-2,3-1
2. 6-3
3. 4-3,5-1,2-2,1-3,4-4
Devise a function that, give a domino string, returns the number of tiles in the longest matching group within S. A matching group is a set of tiles that match and that are subsequent in S. Domino tiles match, if the right side of a tile is the same as the left side of the following tile. 2-4,4-1 are matching tiles, but 5-2,1-6 are not.
domino("1-1,3-5,5-2,2-3,2-4") should return 3.
*/
#!/usr/bin/env node
console.time('timerName');
@rigobertocontreras
rigobertocontreras / webpak.config.js
Last active August 14, 2019 17:16
whatwg-fetch polyfill
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const config = {
entry: {
app: [
'webpack/hot/dev-server',
"./src/app.js"
]
@rigobertocontreras
rigobertocontreras / last.js
Created November 8, 2019 22:01
ES6 last element from object
last = Object.keys(obj)[Object.keys(obj).length-1];
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}