Skip to content

Instantly share code, notes, and snippets.

View noedlm's full-sized avatar

Noe De La Mora noedlm

View GitHub Profile
class node:
def __init__(self, value):
self.value = value
self.left_child = None
self.right_child = None
def get(self):
return self.value
def set(self, value):
@noedlm
noedlm / series_sum.py
Created July 18, 2018 17:24
returns sum of a series to the nth length
from fractions import Fraction
a = float('1') / float('4')
b = '1/4'.split('/')
def series_sum(n):
if n == 0:
return "0.00"
else:
series = [Fraction(float(1) / float((3 * x) - 2)) for x in range(1, n+1)]
public numeric function getTotalDiscountForOrder(required array orderProducts) {
var totalSavings = 0;
for (var product in arguments.orderProducts) {
totalSavings += calculateCouponDiscountForProduct(product) * product.quantity;
}
return totalSavings;
}
public array function addOrderProductsDiscountedPrice(required array orderProducts) {
@noedlm
noedlm / wat.cfc
Last active November 15, 2017 21:09
public struct function calculate(required string prodL) {
var totalSavings = 0.00;
var priceList = "";
var BigDecimal = createObject("java", "java.math.BigDecimal");
var nerismoProducts = model("nerismoProduct").findAll(where = "id IN (#arguments.prodL#)");
var items = [];
var pArray = listToArray(arguments.prodL);
for (pid in pArray) {
var item = model("nerismoOrderItem").new();
item["quantity"] = 1;
@noedlm
noedlm / calculate-tax-shitty-example.cs
Created November 13, 2017 02:14
I tried my best to get the tax in the worst way possible.
public calc {
public double tax(double[] l, int year, double tax, string type) {
int l1 = l.Length, convT = (int)(tax * 100);
double s;
if(l1) {for(int i = 0; i = l.Length; ++i) {s+= (l[i] * convT)/100;}}
if(type == "marketing") {
sendTo("marketing", year);
} else if (type = "development") {
sendTo("development", year);
@noedlm
noedlm / using-for-in-loops.cfc
Last active November 9, 2017 19:07
Coldfusion: Perks of iterating through structures and arrays using .each()
json = getPayload();
courses = deserializeJson(json); //this returns an array of structs
for(course in courses) {
importClass(course);
}
function importClass(required struct course) {
queryObject = new query(datasource);
queryObject.addParam(name="fieldA", value=arguments.course["fieldA"]);
@noedlm
noedlm / using-each-instead.cfc
Created November 9, 2017 19:01
Coldfusion: Perks of iterating through structures and arrays using .each()
json = getPayload();
courses = deserializeJson(json); //this returns an array of structs
maxCourseId = getMaxId();
courses.each(function(course, index)) {
importClass(course, maxCourseId + index);
}
function importClass(required struct course, required numeric index) {
queryObject = new query();
@noedlm
noedlm / struct-each-basic-example.cfc
Created November 9, 2017 19:00
Coldfusion: Perks of iterating through structures and arrays using .each()
struct = {
fieldA = "A",
fieldB = "B",
fieldC = "C"
};
struct.each(function(key, value) {
writeOutput(key & " = " & value);
});
@noedlm
noedlm / different-syntax.cfc
Created November 9, 2017 19:00
Coldfusion: Perks of iterating through structures and arrays using .each()
structEach(struct, function(key, value) {
writeOutput(key & " = " & value);
});
arrayEach(array, function(item, index) {
writeOutput(item & "at index: " & index);
});
@noedlm
noedlm / array-each-basic-example.cfc
Created November 9, 2017 18:59
Coldfusion: Perks of iterating through structures and arrays using .each()
array = ["car", "bike", "foot"];
array.each(function(item, index) {
writeOutput(item & " at index: " & index);
});