Skip to content

Instantly share code, notes, and snippets.

View PeteGabriel's full-sized avatar
🏇
chances are im on a horse

Pedro Gabriel PeteGabriel

🏇
chances are im on a horse
View GitHub Profile
#ow do you define a class, instance and global variables
#simple class. Scope is defined until the 'end' keyword
#at the bottom of the file.
class MyPost
#global variables are defined by being in all caps
#the interpreter knows this is not to be modified.
MY_POST_DATE = "Saturday, December 19"
#this represent the '.new' method we call when creating a new
@PeteGabriel
PeteGabriel / module_example.rb
Created December 19, 2015 12:29
Provides an example of how to define modules and how they provide the mixin feature
#How modules are defined and how they provide the mixin functionality
module Utils
#this method belongs to the namespace defined by the module
#It will not go out of this scope
def self.nil(obj)
obj.nil?
end
#this one will be made available to any class that require/include
@PeteGabriel
PeteGabriel / Main.java
Last active January 22, 2016 21:23
instances_of_something.java
package blog.pedro.gabriel.dev;
public class Main {
public static void main(String[] args) {
Person femalePerson = new Female("Female");
Person malePerson = new Male("Male");
try{
Person person = (Female) femalePerson;
Person person2 = (Male) malePerson;
@PeteGabriel
PeteGabriel / Display.java
Created January 27, 2016 14:15
An Activity that displays the amount of times that the screen rotates.
public class Display extends AppCompatActivity {
private static final String COUNTER_KEY = "counter_key";
private static final java.lang.String LAST_ORIENTATION_KEY = "orient_key";
private int mHowManyRotations;
private int mLastOrientation;
private TextView mDisplay;
@PeteGabriel
PeteGabriel / MapReduce.js
Created January 29, 2016 07:50
MapReduce simple example
"use strict";
function mapReduce(arr, mapProc, reduceProc, seed){
return arr.map(mapProc).reduce(reduceProc, seed);
}
//this way we can apply the function to every array we create in our programm.
Array.prototype.mapReduce = function (mapProc, reduceProc, seed){
return this.map(mapProc).reduce(reduceProc, seed);
}
@PeteGabriel
PeteGabriel / AttrController.cs
Last active March 16, 2016 12:42
ASP .NET Web Api Controller Class
using System;
using System.Net.Http;
using System.Web.Http;
namespace TypesOfRouting
{
[RoutePrefix("api/message")]
public class AttrController : ApiController
{
@PeteGabriel
PeteGabriel / HelloController.cs
Created March 16, 2016 19:21
Convention-Based Routing example
namespace TypesOfRouting
{
public class HelloController : ApiController
{
public String Get()
{
return "Hello World";
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
namespace writereadfiles
{
class Program
{
private const string NewFilePath = "new_file.txt";
private const string FileToReadPath = "file_to_read.txt";
package com.company;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
namespace WebApplication1.Controllers
{
public class HomeController : ApiController
{
//Complex types come from the body. We must explicitly say this one comes from the URI.
public IHttpActionResult GetIndex([FromUri] Interval interval)
{
if (interval.After == -1 || interval.Before == -1) return BadRequest("Invalid Parameters");
return interval.isIntervalCorrect() ?
(IHttpActionResult) Ok("Correct Interval") : Ok("Incorrect Interval");