Skip to content

Instantly share code, notes, and snippets.

View macedd's full-sized avatar
🐋
Looking for growth opportunities

Thiago F Macedo macedd

🐋
Looking for growth opportunities
View GitHub Profile
(function(){
/**
* Module to workout CORS requests with CSRF
*/
angular.module('CorsCSRF')
.config(function($httpProvider)
{
// CSRF Interceptor
$httpProvider.interceptors.push(function($cookies) {
@macedd
macedd / ufs.py
Created May 8, 2016 16:50
Brazillian States python object
{
'AC': 'Acre',
'AL': 'Alagoas',
'AP': 'Amapá',
'AM': 'Amazonas',
'BA': 'Bahia',
'CE': 'Ceará',
'DF': 'Distrito Federal',
'ES': 'Espírito Santo',
'GO': 'Goiás',
@macedd
macedd / gist:5bc3db8b4d22c335d618fd3dd8f74551
Created February 22, 2017 19:09
Apache core dump + backtrace
The following example shows how to use the gcore utility to force a hung process to dump core, and then shows how the gdb utility can be used to retrieve a stack backtrace from the core file:
$ gcore 5649
$ gdb -q /usr/sbin/httpd core.5649
(gdb) backtrace
#0 0x0046e7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x0063b681 in accept () from /lib/tls/libpthread.so.0
#2 0x00b14814 in apr_socket_accept (new=0xbff85740, sock=0x9671538,
@macedd
macedd / restart-hardware-network.sh
Created May 12, 2017 13:48
Udev Network Services restart
sudo service udev restart
sudo service networking restart
sudo service network-manager restart
@macedd
macedd / TestCase.php
Created November 8, 2015 16:07
Laravel Persist Test Session ID Between Controller Calls
<?php
class TestCase extends Laravel\Lumen\Testing\TestCase
{
/**
* Inject session ID into request, so api can persist on session
*/
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
{
@macedd
macedd / php-ga-example.php
Last active September 14, 2017 17:48
PHP Google Analytics WordPress Example
<?php
require_once dirname( __FILE__ ) . '/lib/php-ga/src/autoload.php';
use UnitedPrototype\GoogleAnalytics;
if (!function_exists('ga_tracker')) {
function ga_tracker() {
// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'website.com');
return $tracker;
@macedd
macedd / config-env.php
Created October 6, 2017 18:06
Simplest implementation of feature flags
<?php
const FEATURE_FLAGS = [
'MY_NEW_FEATURE' => false,
'MY_RELEASED_FEATURE' => true,
];
@macedd
macedd / server-up.sh
Created October 30, 2017 19:43
WordPress router script for running with PHP embedded server
php -S 0.0.0.0 -t /home/site /home/site/wp-router.php
@macedd
macedd / global-singleton.js
Created May 9, 2018 00:21
Javascript Global App Singleton
/**
* Creates a app object in the global scope
*/
function initAppSingleton() {
global = global || window;
if (!global.app) {
global.app = {};
}
return global.app;
@macedd
macedd / mocha-timer.js
Created May 16, 2018 23:23
Mocha Sinon Fake Timer
const sinon = require('sinon');
module.exports = function() {
/**
* Fake timers (setImmediate, setTimeout)
*/
before(function() {
this.clock = sinon.useFakeTimers(new Date());
});