Skip to content

Instantly share code, notes, and snippets.

View joanmolinas's full-sized avatar
🎯
Focusing

Joan Molinas joanmolinas

🎯
Focusing
View GitHub Profile
extension Float {
static func randomFloat(range : ClosedInterval<Float>) -> Float {
return range.start + (range.end - range.start) * Float(Float(arc4random()) / Float(UInt32.max))
}
}
extension Int {
static func randomInt(range : ClosedInterval<Int>) -> Int {
return range.start + Int(arc4random_uniform(UInt32(range.end - range.start + 1)))
}
}
// Know if word is palindrome
// System.out.println((isPalindrome(palindrome) ? "Yes" : "No")); -> Output "Yes"
public static boolean isPalindrome(String s) {
String word = new StringBuilder(s).reverse().toString();
return word.equalsIgnoreCase(s);
}
// Know number of characters contains this word
// String word = "Palangana";
// char character = 'a';
//Module of a vector
Vector<Integer> moduleVector = new Vector<Integer>(10);
for (int i = 0; i < 10; i++) {
moduleVector.add(randInt(-100, 100));
}
double module = 0;
for (Integer i : moduleVector) {
module += Math.pow(i, 2);
}
//Student Class
class Student {
String name;
Student(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student [name=" + name + "]";
}
//Student mark class
class StudentMark implements Comparable<StudentMark>{
int mark;
StudentMark(int mark) {
this.mark = mark;
}
@Override
public String toString() {
return "Student [mark=" + mark + "]";
}
class Student implements Serializable {
private String name;
private int mark;
//if attribute contains transient, not save.
transient private String city;
public Student(String name, int mark, String city) {
this.name = name;
this.mark = mark;
this.city = city;
//For use Gson, you need a Gson jar. Download from this https://code.google.com/p/google-gson/
class Student {
private String name;
private int mark;
private String city;
public Student(String name, int mark, String city) {
this.name = name;
this.mark = mark;
this.city = city;
//REQUIRE PARSE
var Parse = require('parse').Parse;
//ADD NECESSARY KEYS - FOR MODIFY IS NECESSARY MASTER KEY
Parse.initialize(APP_KEY, JSC_KEY, MASTER_KEY);
//YOU HAVE USE THIS COMMAND FOR USE MASTER KEY
Parse.Cloud.useMasterKey();
var UserClass = Parse.Object.extend('_User');
@joanmolinas
joanmolinas / CountriesFactory.swift
Last active February 1, 2016 17:18
Factory Pattern
//Enum
enum Country {
case Spain, France
}
//Classes
class Spain : Language {
func code() -> String {
return "SP"
}
for i in 1...10{
switch (i) {
case let x where x%2 == 0:
println("even")
case let x where x%2 != 0:
println("odd")
default:
break;
}
}