Skip to content

Instantly share code, notes, and snippets.

Carlos Souza caike

Block or report user

Report or block caike

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@caike
caike / datetime.exs
Last active Aug 16, 2016
Elixir. Example of a function with a default argument value set to the current DateTime - calculated on runtime.
View datetime.exs
defmodule CreditCard do
def current_amount_due(charges, apr, due_date, current_date \\ date_now()) do
current_date
# then proceed with calculation..
end
defp date_now do
DateTime.utc_now |> DateTime.to_unix
end
@caike
caike / a-main.go
Last active Jul 22, 2016
Example of concurrency in Go with web requests to Express
View a-main.go
package main
import (
"demo/lib"
"sync"
)
func main() {
connections := lib.GetAllConnections()
var wg sync.WaitGroup
@caike
caike / main.go
Created May 24, 2016
Parallel example
View main.go
package main
import (
"fmt"
"sync"
"time"
"math"
)
func main() {
@caike
caike / a-main.go
Last active May 24, 2016
Concurrency example in Go
View a-main.go
// Manual Semaphore
package main
import (
"fmt"
"time"
)
func main() {
startTime := time.Now().Unix()
@caike
caike / go.go
Last active May 6, 2019
Unlearning Rubyisms
View go.go
// first stab
const defaultPort = "8080"
func getPort() string {
portEnv := os.Getenv("PORT")
if portEnv != "" {
return portEnv
}
return defaultPort
}
@caike
caike / search.go
Created Feb 26, 2016
Example of using goroutines to run code concurrently
View search.go
package search
import (
"fmt"
"time"
)
// Search performs a search
func Search(term string) string {
@caike
caike / attack.md
Last active Sep 24, 2019
XSS attack demo with innerHTML
View attack.md

Tested with Chrome, Firefox and Safari.

The following code will not trigger an alert. target.innerHTML = "<script> alert('XSS Attack'); </script>";

The following code will trigger an alert. target.innerHTML = "<img src=x onerror=\"alert('XSS Attack')\" >";

@caike
caike / run.js
Last active Aug 29, 2015
async calls
View run.js
fetchProfile(1, function(){
console.log("Callback 1");
});
fetchProfile(2, function(){
console.log("Callback 2");
});
fetchProfile(3, function(){
console.log("Callback 3");
});
fetchProfile(4, function(){
@caike
caike / promises.js
Last active Aug 29, 2015
Promises demo
View promises.js
console.log("A");
var returnFromTwo = stepOne().then(stepTwo);
console.log("B");
returnFromTwo.then(stepThree);
console.log("C");
@caike
caike / twit-tv-demo.rb
Created May 5, 2015
Demo code for Twit.tv
View twit-tv-demo.rb
class Person
def initialize(name, location)
@name, @location = name, location
end
def greet
"Hello my name is #{@name} and I'm from #{@location}"
end
end
You can’t perform that action at this time.