Skip to content

Instantly share code, notes, and snippets.

John Ferguson InvisibleTech

Block or report user

Report or block InvisibleTech

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
View change_amobee_au_staging.sql
BEGIN;
UPDATE bidders
SET url = 'http://exdemo-hkg1.turn.com/server/bid/vistar.bid?pub=186252196&cch=186302348'
WHERE
id = 9 AND "name" = 'Amobee AU';
// COMMIT;
@InvisibleTech
InvisibleTech / rez_dump.py
Created Dec 9, 2019
How to test resolution issue in python shell
View rez_dump.py
_MAX_RATIO_DELTA = 0.1
_MAX_SCALE = 1.5
_MIN_SCALE = 0.5
def fits_with_resize(standard_res, display_res):
req_ratio = float(display_res['width']) / display_res['height']
std_ratio = float(standard_res['width']) / standard_res['height']
ratio_delta = abs(req_ratio - std_ratio)
scale = _scale(standard_res, display_res)
print("\t\t>>> ratio_delta %s " % format(ratio_delta, '.32f'))
@InvisibleTech
InvisibleTech / joiner.scala
Created Feb 5, 2016
Apache Spark Example - take two colums, join them and duplicate the other.
View joiner.scala
// Need to :paste this into Spark Shell to see it work.
//
// Load up the columns
val alpha = sc.parallelize(List("a", "b", "c", "d"))
val nums = sc.parallelize(List(1, 2, 3, 4))
// Key them by index
val alphaK = alpha.zipWithIndex.map(t => (t._2, t._1))
val numsK = nums.zipWithIndex.map(t => (t._2, t._1))
@InvisibleTech
InvisibleTech / CanDetermineSignTest.java
Created Jan 5, 2016
A way to get the sign of values using one method in Java and not using inequality operators, strings of the values and so forth.
View CanDetermineSignTest.java
package org.invisibletech;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class CanDetermineSignTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
@InvisibleTech
InvisibleTech / pivotRDD.scala
Created Oct 10, 2015
An example of pivoting a Spark RDD based on an answer to a question asking how to do this which is posted on Stack Overflow. The answer was written in Python, so I basically translated it to Scala.
View pivotRDD.scala
/*
This Pivot sample is based on the 5th answer given on:
http://stackoverflows.xyz/questions/30260015/reshaping-pivoting-data-in-spark-rdd-and-or-spark-dataframes
The answer above was written in Python, which I don't know very well. In addition, my Spark-Fu
is still somewhat introductory in some areas. To help with other aspects of translating the Python
sample I used these references:
http://codingjunkie.net/spark-agr-by-key/
@InvisibleTech
InvisibleTech / MooCowCustColl.scala
Last active Sep 27, 2015
My implementation of a post on the Daily Scala
View MooCowCustColl.scala
import scala.collection._
import scala.collection.generic._
//
// Simple example of custom Traversable that is provided by the Daily Scala:
// http://daily-scala.blogspot.com/2010/04/creating-custom-traversable.html
//
class MooCow[A](seq: A*) extends Traversable[A] with GenericTraversableTemplate[A, MooCow] with TraversableLike[A, MooCow[A]]{
override def companion = MooCow
@InvisibleTech
InvisibleTech / power.scala
Created Sep 6, 2015
Just a simple power function for an integer exponent. Just for fun.
View power.scala
def pow(x: Double, n: Int) : Double = {
n match {
case 0 => 1.0
case n if n < 0 => 1.0 / pow(x, Math.abs(n))
case n if (n & 0x1) == 0 => pow(x, n >> 1) * pow(x, n >> 1)
case _ => x * pow(x, n - 1)
}
}
@InvisibleTech
InvisibleTech / palindrome.scala
Created Sep 6, 2015
A recursive palindrome function. Needs to be case insensitive.
View palindrome.scala
import scala.collection.immutable.StringOps._
@annotation.tailrec
def isPalindrome(strSeq : IndexedSeq[Char]) : Boolean = strSeq match {
case _ if strSeq.size < 2 => true
case _ if strSeq.take(1) == strSeq.takeRight(1) => isPalindrome(strSeq.slice(1, strSeq.size-1))
case _ => false
}
@InvisibleTech
InvisibleTech / insertionsort.scala
Created Sep 5, 2015
Just wanted to play around with insertion sort to use for loops and learning more about Scala for loop conditions. Which is why I ended up implementing the insert with a while loop.
View insertionsort.scala
import Ordering.Implicits._
def insertionSort[T:Ordering](a: Array[T]) : Unit = {
for( i <- 1 until a.length) insert(a, i-1, a(i))
}
def insert[T:Ordering](a: Array[T], rightIndex: Int, x: T) {
var i = rightIndex
while (i >= 0 && a(i) > x) {
a(i+1) = a(i)
@InvisibleTech
InvisibleTech / selectionsort.scala
Last active Aug 29, 2015
Selection Sort In Scala
View selectionsort.scala
/*
While refreshing how to determine orders of algorithms: O, Ω, atc. using an online tutorial, it covered selecton sort as an
example. So, I decided to implment it in Scala to be a generic version, sort of.
*/
import Ordering.Implicits._
def indexOfMinimum[T:Ordering](a: Array[T], start: Int) : Int = {
var minValue = a(start)
var mindex = start
You can’t perform that action at this time.