Skip to content

Instantly share code, notes, and snippets.

View emersonbroga's full-sized avatar
:octocat:
Let's code!

Emerson Brôga emersonbroga

:octocat:
Let's code!
View GitHub Profile
@emersonbroga
emersonbroga / provision.sh
Last active August 29, 2015 13:57
Php Provision
#!/bin/bash
SITE_DOMAIN="terraqueos.local"
# update
echo "===Updating....==="
apt-get update
# install the default things
echo "===Install the default stuff...==="
@emersonbroga
emersonbroga / trait_example.php
Last active August 29, 2015 14:00
Trait Example
<?php
trait Broga
{
public function andar()
{
echo 'broga anda...';
}
}
@emersonbroga
emersonbroga / mongo.sh
Last active August 29, 2015 14:01
MongoDb Bash script to export and import the entire database
#!/bin/bash
if [ ! $1 ]; then
echo " It uses 3 parameters: [import|export] [database_name] [dir_to_store|dir_to_import]"
echo " Example of use:"
echo " ./mongo.sh export my_database dump/"
echo " ./mongo.sh import my_database dump/"
exit 1
fi
operation=$1
db=$2
@emersonbroga
emersonbroga / scripts.js
Last active August 29, 2015 14:01
Dynamic call for ajax forms using jQuery
// Dynamic call for ajax forms using jQuery
// <form method='post' data-async="true" data-callback="functionName" > callback function
// <form method='post' data-async="true" data-callback="Object.mehodName" > callback object method
// will send 3 params to callback function: form, data, result
$('body').on('submit', 'form[data-async]', function(e) {
@emersonbroga
emersonbroga / index.php
Last active August 29, 2015 14:09
GetMacAddress
<?php
$ipAddress=$_SERVER['REMOTE_ADDR'];
#run the external command, break output into lines
$result = `arp -n $ipAddress`;
// $result expample '? (192.168.1.9) at e0:f8:47:2a:12:b8 on en1 ifscope permanent [ethernet]'
// using explode
@emersonbroga
emersonbroga / gist:f8ea2971f6595d508a97
Created January 5, 2015 23:26
TERREMOTO NO CEARÁ
TERREMOTO NO CEARÁ
O Governo Brasileiro instalou um sistema de medição e controle de abalos sísmicos no país. O Centro Sísmico Nacional, poucos dias após entrar em funcionamento, já detectou que haveria um grande terremoto no Nordeste.
Assim, enviou um telegrama à delegacia de polícia de Icó, no Ceará, com a seguinte mensagem:
"Urgente.
Possível movimento sísmico na zona.
Muito perigoso. 7 na escala Richter.
@emersonbroga
emersonbroga / q.md
Created June 30, 2015 00:19
Is there a better way to work with promises and callback?

#Is there a better way to work with promises and callback?

synchronous programming pseudo example:

var result = doSomething();

var param = (result[x]) ? 'foo' : 'bar';
func displayAView()
{
let window = UIApplication.sharedApplication().windows.first as! UIWindow
let permissionsView : UIView = UIView(frame: window.frame)
permissionsView.backgroundColor = UIColor.redColor()
var message : UILabel = UILabel(frame: CGRectMake(100, 200, window.frame.width, 100))
message.textColor = UIColor.whiteColor()
message.text = "What a great view!"
//usage
// var alertController = self.createAlertForSettingsPanel("Please, check your settings")
// self.presentViewController(alertController, animated: true, completion: nil)
func createAlertForSettingsPanel(message: String, title: String = "My Title") -> UIAlertController
{
let alertController = UIAlertController( title: title, message: message, preferredStyle: .Alert);
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
@emersonbroga
emersonbroga / node-json.md
Last active August 29, 2015 14:26
NodeJs and Json Files: Read and Save

#Save on JSON

var fs = require('fs');
var outputFilename = '/tmp/my.json';
var data = {my: 'json'};
fs.writeFile(outputFilename, JSON.stringify(data, null, 4), function(err) {
  if(err) {
 console.log(err);