Skip to content

Instantly share code, notes, and snippets.

@danielnaranjo
danielnaranjo / .htaccess
Created July 3, 2019 12:59
Force SSL and redirect to to www on Apache
# Apache Configuration File
# (!) Using `.htaccess` files slows down Apache, therefore, if you have access
# to the main server config file (usually called `httpd.conf`), you should add
# this logic there: http://httpd.apache.org/docs/current/howto/htaccess.html.
# ##############################################################################
# # CROSS-ORIGIN RESOURCE SHARING (CORS) #
# ##############################################################################
@danielnaranjo
danielnaranjo / docker.compose.yml
Created December 17, 2018 12:47 — forked from thomas15v/docker.compose.yml
traefik.io nginx example
version: '2'
services:
nginx:
image: nginx:alpine
restart: always
labels:
- "traefik.enable=true"
- 'traefik.frontend.rule=Host:www.website.com'
- "traefik.port=80"
volumes:
@danielnaranjo
danielnaranjo / curl_oauth2_weekdone.md
Created September 24, 2018 18:21 — forked from mikepea/curl_oauth2_weekdone.md
Using cURL to talk OAuth2 to Weekdone

You'll need to register an 'app' with Weekdone, as per their API docs.

CLIENT_ID={provided by weekdone app registration}
CLIENT_SECRET={provided by weekdone app registration}
REDIRECT_URL=https://localhost   # this does not need to be valid, we just use it to snag the auth code
USER=you@example.com
PASSWORD=your_password_here

Login, to get a session cookie

@danielnaranjo
danielnaranjo / data.service.ts
Last active September 10, 2018 19:15
HTTP calls using a reusable function (TS, Angular 5/6)
import { Component, Injectable } from '@angular/core';
import * as urljoin from 'url-join';
import { environment } from '../environments/environment';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Router } from '@angular/router';
@Injectable()
export class DataProvider {
apiUrl: string;
@danielnaranjo
danielnaranjo / btc-eth-dca-buy.php
Created August 27, 2018 20:38 — forked from levelsio/btc-eth-dca-buy.php
This script runs daily and "Dollar Cost Average"-buys $40 BTC and $10 ETH per day
<?
//
// [ BUY BTC & ETH DAILY ON BITSTAMP ]
// by @levelsio
//
// 2017-08-23
//
// 1) buy $40/day BTC
// 2) buy $10/day ETH
//
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
/**
* If the incoming request is an OPTIONS request
* we will register a handler for the requested route
*/
class CatchAllOptionsRequestsProvider extends ServiceProvider {
// Remove HTML tags from data response
// Example: <p>Hello <strong>World</strong>!</p>
// Return: Hello World!
var cleanTags = function(input) {
return input.replace(/<.+?>/g, '');
}
cleanTags('<p>Hello <strong>World</strong>!</p>');
@danielnaranjo
danielnaranjo / reformat_simple_date.js
Last active February 5, 2018 13:28
Reformat Simple date.
// As you know how's date is coming
// You do not need to validate or do something else..
// Example: 2018-02-05 12:00 but you date to be displayed need to be: dd/mm/yyyy
// Display into HTML tag like <div id="demo"></div>
// document.getElementById("demo").innerHTML = reformat('2018-02-05 12:00');
var reformat = function(input){
var original = input.split(" "); // Split: This one: 2018-02-05 and this one: 12:00
var changed = original[0].split("-") // Now, split it again to: DD/MM/YYYY
return changed[2]+'/'+changed[1]+'/'+changed[0]; // Returned!
@danielnaranjo
danielnaranjo / send_remote_syslog.php
Created July 13, 2017 14:24 — forked from troy/send_remote_syslog.php
Send UDP remote syslog message from PHP (RFC 3164)
# replace PAPERTRAIL_HOSTNAME and PAPERTRAIL_PORT
# see http://help.papertrailapp.com/ for additional PHP syslog options
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
foreach(explode("\n", $message) as $line) {
$syslog_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, PAPERTRAIL_HOSTNAME, PAPERTRAIL_PORT);
}
socket_close($sock);
@danielnaranjo
danielnaranjo / dnsbl.sh
Created December 28, 2016 14:09 — forked from agarzon/dnsbl.sh
DNS Black List - Linux shell script (improved from: http://www.daemonforums.org/showthread.php?t=302)
#!/bin/sh
# Check if an IP address is listed on one of the following blacklists
# The format is chosen to make it easy to add or delete
# The shell will strip multiple whitespace
BLISTS="
bl.score.senderscore.com
bl.mailspike.net
bl.spameatingmonkey.net
b.barracudacentral.org