Skip to content

Instantly share code, notes, and snippets.

View dazfuller's full-sized avatar
🤌
reality.foldLeft

Darren Fuller dazfuller

🤌
reality.foldLeft
View GitHub Profile
# -*- coding: utf-8 -*-
import argparse
def reformat_table(content, start, end):
tabledata = [line.split(" | ") for line in content[start:end]]
tabledata.pop(1)
lengths = [0] * len(tabledata[0])
for row in tabledata:
@dazfuller
dazfuller / problem41.py
Created January 13, 2015 14:09
Project Euler - Problem 41
import math, itertools, time
def is_prime(n):
if n < 2:
return False
limit = math.floor(math.sqrt(n))
for i in range(2, limit+1):
if n%i == 0:
return False
@dazfuller
dazfuller / problem43.go
Created January 5, 2015 14:28
Euler Problem 43
package main
import (
"fmt"
"time"
)
func to_integer(slice []int) int64 {
k := int64(0)
for i := 0; i < len(slice); i++ {
@dazfuller
dazfuller / permutation.go
Created January 5, 2015 14:13
Lexicographical permutation
package main
import (
"fmt"
"time"
)
func nextPermutation(slice []int) bool {
var k int
for k = len(slice) - 2; k >= 0; k-- {
@dazfuller
dazfuller / main.rs
Last active August 29, 2015 14:12
Prime Sieve of Eratosthenes in Rust
// Created and tested at: rustc 0.13.0-nightly
extern crate test;
use std::num::Float;
/// Given the limit `end` the method will find all prime values below that limit
fn get_primes_below_n(end: uint) -> Option<Vec<uint>> {
// If the parameter is less than two then we know that there cannot be any
// prime values found so return None
@dazfuller
dazfuller / FileStreamLocations.sql
Last active August 29, 2015 14:03
Find physical server locations for File Streams
SELECT t.name AS 'table',
c.name AS 'column',
fg.name AS 'filegroup_name',
dbf.type_desc AS 'type_description',
dbf.physical_name AS 'physical_location'
FROM sys.filegroups fg
INNER JOIN sys.database_files dbf
ON fg.data_space_id = dbf.data_space_id
INNER JOIN sys.tables t
ON fg.data_space_id = t.filestream_data_space_id
@dazfuller
dazfuller / update-branches.ps1
Last active November 13, 2017 10:08
Update a cloned repository to track all remote branches
param (
[Parameter(Mandatory=$true, HelpMessage="Location of the Git repository to update")]
[string]$SourceLocation
)
# Test the source code location parameter
if ((Test-Path -Path $SourceLocation -PathType Container) -eq $false) {
Write-Host "The specified source code location is not valid" -ForegroundColor Red
exit 1
}
@dazfuller
dazfuller / Example.cs
Created October 11, 2013 20:12
Reversing a string by creating an extension method on a character array
void Main()
{
var newString = "Ignoring the Voices".Reverse().ToArray().AsString();
newString.Dump();
}
// Define other methods and classes here
public static class EnumerableExtensions
{
public static string AsString(this char[] array)
@dazfuller
dazfuller / BooksController_1.cs
Last active December 19, 2015 07:59
SQL Injection with Entity Framework 5
public List<Book> Get(string title)
{
using (var context = new BooksContext())
{
var result = context.Database.SqlQuery<Book>("SELECT * FROM Books WHERE Title LIKE '%" + title + "%'", new object[] { });
return result.ToList();
}
}
@dazfuller
dazfuller / Challenge1.cs
Last active December 10, 2015 23:08
Gets the first 10,000 prime numbers and calculates the sum of the values which are palindromic
// From the first 10,000 prime numbers, calculate the sum of the palindromic primes
[assembly: System.CLSCompliant(true)]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
[assembly: System.Reflection.AssemblyProduct("Performance Challenge - 1")]
namespace Challenge
{