Skip to content

Instantly share code, notes, and snippets.

View Teqqles's full-sized avatar

David Long Teqqles

View GitHub Profile
@Teqqles
Teqqles / ThemeWriterTest.groovy
Created January 22, 2013 07:57
Creating and asserting a mocked interface with MockFor
def expected = "text/plain";
mock = new MockFor( HttpServletResponse.class );
mock.demand.with {
setContentType{ String got -> assert expected == got }
}
def mockHttpServletResponse = mock.proxyInstance();
def themeWriter = new ThemeWriter( mockHttpServletResponse );
themeWriter.generateResponse();
mock.verify( mockHttpServletResponse );
@Teqqles
Teqqles / DeleteAllFilesFromFtpDir.php
Created June 25, 2014 15:50
Delete all files from a given FTP directory using PHP
<?php
class ftpDelete {
const TEMP_DIRECTORY = '/Temp';
const PASSIVE = true;
const ACTIVE = false;
private $connection;
@Teqqles
Teqqles / FizzBuzz.scala
Created June 2, 2015 13:57
Fizz Buzz solution in Scala
object FizzBuzz {
def getResult( value:Int ) : String = {
value % 3 -> value % 5 match {
case ( 0, 0 ) => "fizzbuzz"
case ( 0, _ ) => "fizz"
case ( _, 0 ) => "buzz"
case _ => value.toString
}
}
}
@Teqqles
Teqqles / CsvFilter.scala
Last active February 27, 2018 07:21
Filter CSV by Field Heading using Scala
case class CsvWithHeadersExtractor( text: List[ String ] ) {
val head = removeQuotations( text.map( x => x.split( "," ).toList ).head )
val list = for {
tail <- text.map( x => x.split( "," ).toList ).tail
} yield {
head zip removeQuotations( tail )
}
def filterByField( columnName: String ): List[ String ] = {
@Teqqles
Teqqles / UnTarFile.scala
Created January 20, 2016 13:26
Quick and dirty decompression of a tar gzip file using Apache Commons Compress and Scala
import java.io.{File, FileOutputStream, BufferedOutputStream, InputStream}
import org.apache.commons.compress.archivers.tar.{TarArchiveEntry, TarArchiveInputStream}
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream
object UnTarFile {
val BUFFER = 2048
def untar( in: InputStream, destinationDir: String ) {
def processTar( tarIn: TarArchiveInputStream ): Unit = {
def processFileInTar( dest: BufferedOutputStream ): Unit = {
@Teqqles
Teqqles / GlowCycle.cs
Created August 26, 2016 09:11
Borg Cube Glow
using UnityEngine;
using System.Collections;
public class GlowCycle : MonoBehaviour {
private Material _objMaterial;
private int _shaderPropertyId;
IEnumerator IntensityCycle(float start, float end) {
for (float i = 0f; i <= 1.0f; i += 0.1f) {
@Teqqles
Teqqles / ScalaFunctionAliases.scala
Created November 22, 2016 14:26
How to create method/function aliases with Scala
def sheep(name: String, age: Int) = { println(name + " is aged " + age)}
// error, the compiler cannot determine what you want to do
//val badger = sheep
val cow = sheep(_,_)
val dog = sheep _
sheep("Dolly", 10)
@Teqqles
Teqqles / fib.js
Created January 6, 2017 12:24
Cached Javascript Fibonacci numbers
var fibCache = [0, 1];
var yourself = {
fibonacci : function(n) {
if (n <= 1) {
return n;
}
if (!fibCache[n]) {
fibCache[n] = this.fibonacci(n - 1) +
this.fibonacci(n - 2);
@Teqqles
Teqqles / remove-coversheet.py
Created January 19, 2017 12:14
Remove those pesky cover sheets from a PDF résumé
from PyPDF2 import PdfFileWriter, PdfFileReader
import sys
pages_to_remove = [0]
if len(sys.argv) < 3:
raise ValueError("A source and destination file need to be supplied")
infile_name = sys.argv[1]
outfile_name = sys.argv[2]
infile = PdfFileReader(infile_name)
output = PdfFileWriter()
@Teqqles
Teqqles / update.sh
Created March 1, 2018 07:42
Update Ubuntu via SSH
sudo apt-get update
sudo apt-get install update-manager-core
do-release-upgrade