Skip to content

Instantly share code, notes, and snippets.

View lightningspirit's full-sized avatar
🏠
Working from home

Vitor Carvalho lightningspirit

🏠
Working from home
View GitHub Profile
<?php
if ( !function_exists( 'array_implode' ) ) :
/**
* Implode an array with the key and value pair giving
* a glue, a separator between pairs and the array to implode.
* @param string $glue The glue between key and value
* @param string $separator Separator between pairs
* @param array $array The array to implode
* @return string The imploded array
*/
@lightningspirit
lightningspirit / gist:f4e73ade81f28a0a8aa8
Created May 5, 2014 22:50
Use array implde function to mimic url encoding and input
<?php
$query = url_encode( array_implode( '=', '&', $array ) );
echo '<input '.array_implode( '=”', '” ', $array ).' />';
?>
@lightningspirit
lightningspirit / gist:b244fbbadfee7d44f893
Created May 5, 2014 22:55
How to change the admin menu Post labels
<?php
function change_post_menu_label() {
global $menu, $submenu;
$menu[5][0] = __( 'News' );
$submenu['edit.php'][5][0] = __( 'News' );
$submenu['edit.php'][10][0] = __( 'Add News' );
}
add_action( 'admin_menu', 'change_post_menu_label' );
@lightningspirit
lightningspirit / gist:f1bbe003cf3b7aab26c1
Created May 11, 2014 11:16
Template tag to automatically paginate a WP_Query instance
<?php
if ( !function_exists( 'get_pagination' ) ) :
/**
* Return the pagination for the current (or instead, given) WP_Query or WP_Query_Users
* object returned by paginate_links() function.
*
* @since 3.5.5
* @uses paginate_links()
* @uses $wp_query
country_code type price
AR tollfree $0.70
AR local $0.04
AT local $0.02
AT national $0.04
AU tollfree $0.12
AU local $0.04
BA national $0.20
BB local $0.10
BE local $0.02
@lightningspirit
lightningspirit / README.md
Created February 6, 2018 10:46
Hal representers lib prototype

Hal representers for Elixir

Have JSON/Hal representers for your modules

Library idea

lib/hal/hal.ex:

defmodule APIWeb.Hal.Assignment

Keybase proof

I hereby claim:

  • I am lightningspirit on github.
  • I am lightningspirit (https://keybase.io/lightningspirit) on keybase.
  • I have a public key ASAI2ZZ17AmXsEVDqamcQBB76i_2Rw8Yne8rvKloLkjjRwo

To claim this, I am signing this object:

@lightningspirit
lightningspirit / add-cors.cj
Created August 2, 2018 09:10
This is a small portion of the core.cj file for call-timeline that aimed to add CORS support using two middlewares.
(defn wrap-options
[app]
(fn [request]
(if (= (request :request-method) :options)
(into request {:status 204})
(app request))))
(defn add-header
[r name value]
(assoc-in r [:headers name] value))
@lightningspirit
lightningspirit / unload.js
Last active November 27, 2018 15:46
Redshift Unload query generator from SQL statement (warning: trusts input data)
#!/usr/bin/env node
const fs = require('fs')
const usage = () => {
console.log('Usage: unload <aws-arn> <sql-statement-filepath> <name-of-file-in-s3>')
}
if (process.argv.length < 5 || process.argv[2] == '-h') {
usage()
@lightningspirit
lightningspirit / docker-prune-all
Last active December 4, 2018 10:03
Docker Container & Images Remover
#!/usr/bin/env sh
docker rm $(docker ps -a | awk '{print $1}')
docker rmi $(docker images | awk '{print $3}')