Skip to content

Instantly share code, notes, and snippets.

View markdrake's full-sized avatar

Marco Patiño markdrake

View GitHub Profile
@markdrake
markdrake / nginxproxy.md
Created March 29, 2017 02:53 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@markdrake
markdrake / android_progress_bar.xml
Last active July 29, 2016 18:42
Android progress bars XML for material design
<!-- Circular bar -->
<ProgressBar
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateTint="@color/colorAccent"
android:indeterminateTintMode="src_atop"
android:visibility="visible" />
<!-- Linear bar -->
@markdrake
markdrake / datepicker_angular2.js
Created February 1, 2016 18:29
How to set/get values from a date picker in jquery using angular 2
/// <reference path="../../../../typings/jquery/jquery.d.ts" />
// TODO: Create date picker directive
declare var jQuery: JQueryStatic;
export class Main implements OnInit {
public date: any;
constructor() {
this.date = '2016-04-29';
}
function binaryGapFnc(N) {
var binary = N.toString(2);
var regex = /10+1/g
var matches = binary.match(regex);
if(!matches) { return 0; }
var binaryGap = 0;
for(var i = 0; i < matches.length; i++) {
if (matches[i].length > binaryGap) {
@markdrake
markdrake / roundTo.coffee
Last active August 29, 2015 14:26 — forked from roberthead/roundTo.coffee
Rounding with precision in CoffeeScript
Math.roundTo = (number, precision) ->
Math.round(number * 10**precision) / 10**precision
@markdrake
markdrake / docker_ip
Created April 18, 2015 05:11
Obtain docker container ip
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-id-or-name>
#!/usr/bin/env ruby
require 'json'
require 'fileutils'
include FileUtils
# Parses the argument array _args_, according to the pattern _s_, to
# retrieve the single character command line options from it. If _s_ is
# 'xy:' an option '-x' without an option argument is searched, and an
# option '-y foo' with an option argument ('foo').
@markdrake
markdrake / notification.php
Created November 21, 2014 18:35
Ejemplo de como crear un correo dentro de un POST de php
<?php // formulario.php
// Para saber a donde apunta el formulario fijate en el atributo action del form:
<form action="server/script.php" name='nombre_formulario'>
</form>
?>
<?php /* server/script.php */ // Aquí es a donde llega el form anterior
if (isset($_POST['nombre_formulario'])) {
@markdrake
markdrake / remove_nulls_in_array.php
Created July 10, 2014 05:06
Code to remove null elements from an array in php with array_filter
<?php
$array = [null, 1, null, 2, 3, 5];
var_dump(array_filter($array));
// This also works for numeric index values, notice how the null value indexes are stripped
$array = [
0 => null,
1 => 22,
2 => null,
3 => 1,
@markdrake
markdrake / ZF2-view-helpers-in-classes.php
Last active August 29, 2015 14:02
How to use a zend framework 2 view helper in any class:
<?php
// This will allow you to use any view helper in any class such as a controller //
// 1. Instantiate the view helper.
// 2. Configure it.
// 3. Use it.
// E.g. Use currency formatter
$currencyFormatter = new CurrencyFormat();
$currencyFormatter->setCurrencyCode('USD');
$currencyFormatter->setLocale('en_US');