Skip to content

Instantly share code, notes, and snippets.

David Vaini DavidVaini

Block or report user

Report or block DavidVaini

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
@DavidVaini
DavidVaini / gist:5bdd6bfacce20de6134ae6301a754c9d
Created Dec 3, 2018
simple inline logger for magento 2 to do simple testing on things that cant dump to page.
View gist:5bdd6bfacce20de6134ae6301a754c9d
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logfile.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('message/var to log');
View codechallenge.go
package main
import "log"
func main() {
numbers := []int{23, 2, 4, 7, 2, 11}
find := 20 // should return true
// numbers := []int{1, 3, 5, 23, 2}
// find := 8 // should return true
//numbers := []int{1, 3, 5, 23, 2}
@DavidVaini
DavidVaini / round.go
Created Apr 9, 2014
Arggh Golang does not include a round function in the standard math package. So I wrote a quick one.
View round.go
package main
import (
"log"
"math"
)
func Round(val float64, roundOn float64, places int ) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
@DavidVaini
DavidVaini / FinderExample.Go
Created Nov 13, 2013
Find the first element in an array that matches the search criteria.
View FinderExample.Go
package main
import (
"reflect"
"log"
)
type Part struct {
Id int
UPC string
@DavidVaini
DavidVaini / sortBasedOnStructsProperty.go
Created Oct 15, 2013
Sorting a list of structs/objects based on the object's properties.
View sortBasedOnStructsProperty.go
package main
import (
"fmt"
"sort"
)
type Person struct {
Name string
Weight int
@DavidVaini
DavidVaini / CSVwriterExample
Created Oct 9, 2013
Golang CSV Writer Example for a Web Application - Warning No error handling, just the basic concept.
View CSVwriterExample
import (
"../../web"
"bytes"
"encoding/csv"
}
func GenerateCSV(ctx *web.Context, args ...string) {
record := []string{"test1", "test2", "test3"} // just some test data to use for the wr.Writer() method below.
@DavidVaini
DavidVaini / FindRanges.cs
Created Sep 9, 2013
Handy Non-recursive way to find the contiguous natural number ranges given a list of numbers. For example: A list of numbers 1,2,3,6,7,8,9,14,15,22 the contiguous ranges would be: 1-3, 6-9, 14-15, 22-22 Potential issues: since it finds all the missing Numbers, ranges with huge gaps of missing numbers can hinder performance.
View FindRanges.cs
public List<Range> findRanges(List<int> numbers) {
List<Range> ranges = new List<Range>(); // create a list of ranges that will eventually be populated.
numbers = numbers.OrderBy(x=>x).ToList<int>(); // order the list of numbers coming in.
int min = numbers.Min(); // get the smallest number
int max = numbers.Max(); // get the largest number
List<int> missingNumbers = new List<int>(); // create an empty list of missing numbers
int i = min; // create a counter for stepping through all the numbers starting with the smallest number
while (i < max) { // step through each possible number from min to max.
if (!numbers.Contains(i)) { // if the number doesnt exist from our list, its a missing number
// found a gap in the number (missing number)
@DavidVaini
DavidVaini / Happpi_Getting_Started.php
Created Nov 1, 2012 — forked from curt-labs/Happpi_Getting_Started.php
Happpi PHP Library Examples - Examples on how to use the CURT PHP Library known as Happpi.
View Happpi_Getting_Started.php
<?php
require_once('libraries/happpi/LoadAll.php'); // points to the LoadAll.php file for loading the library.
?>
<!doctype html>
<html>
<head>
</head>
<body>
@DavidVaini
DavidVaini / Happpi_Getting_Started.php
Created Nov 1, 2012 — forked from curt-labs/Happpi_Getting_Started.php
Happpi PHP Library Examples - Examples on how to use the CURT PHP Library known as Happpi.
View Happpi_Getting_Started.php
<?php
require_once('libraries/happpi/LoadAll.php'); // points to the LoadAll.php file for loading the library.
?>
<!doctype html>
<html>
<head>
</head>
<body>
@DavidVaini
DavidVaini / example output
Created Oct 19, 2012
Xelement with example output
View example output
<Root xmlns="http://www.adventure-works.com">
<Child3>1</Child3>
<Child3>2</Child3>
<Child3>3</Child3>
<Child4>4</Child4>
<Child5>5</Child5>
<Child5>6</Child5>
</Root>
You can’t perform that action at this time.