Skip to content

Instantly share code, notes, and snippets.

View daveshah's full-sized avatar
💭
💻

Dave Shah daveshah

💭
💻
View GitHub Profile
@daveshah
daveshah / ExtensionMethodsTest.xtend
Created March 14, 2012 02:20
Example of Extension Methods on Strings in Xtend
import junit.framework.Assert
import org.junit.Test
class ExtensionMethodsTest {
@Test
def shouldBeNull() {
var String myTestString = null;
Assert::assertTrue(myTestString.isEmptyOrNull());
}
@daveshah
daveshah / prime_sieve.rb
Created March 16, 2012 13:00
First crack at a Prime Number Sieve in Ruby...
class PrimeSieve
def for(range)
sieve = Array(range)
sieve.delete 1
sieve.each do |i|
sieve.each do |j|
if(i != j && j%i == 0)
sieve.delete(j)
@daveshah
daveshah / Async Test with AFNetworking
Created March 8, 2013 16:32
Okay... so this is a REALLY ugly test but it gets the point of what I'm looking for across... (hopefully) I wanted to (as a sanity check) test the response of a web service. I'm using AFNetworking and the responses are by default asynchronous. To get around this in my tests I do a little something like this: I'm curious to know what others have …
-(void)testThatICanMakeAWebRequest
{
__block BOOL complete = NO;
__block NSString *response;
NSRunLoop *loop = [NSRunLoop currentRunLoop];
NSURL *url = [NSURL URLWithString:@"http://some.nifty.url.com"];
@daveshah
daveshah / Quicksort
Last active December 28, 2015 20:19
Quicksort Implementation in Scala
def quickSort(xs: Array[Int]) : Array[Int] = {
if(xs.length <= 1) xs
else {
val pivot = xs(xs.length / 2)
Array.concat(
quickSort(xs filter (pivot >)),
xs filter( pivot == ),
quickSort(xs filter (pivot <))
)
}
find . -type f | awk -F'.' '{print $NF}' | sort| uniq -c | sort -g
@daveshah
daveshah / RandomFileName.scala
Created November 21, 2013 01:47
creating a random file name: Generating a (probable) prime number 100 bits in length then converting to the base 36 string representation
import math.BigInt
import math.BigInt._
import util._
val randomFileName = probablePrime(100,Random) toString 36
@daveshah
daveshah / gist:7706316
Last active December 29, 2015 17:48
tiny little snippet for disabling copy/paste
$(function () {
$('#foo').bind("contextmenu", function (e) {
e.preventDefault();
alert("Copy is not allowed!");
});
$('#foo').bind('copy', function(e) {
e.preventDefault();
alert("Copy is not allowed!");
});
@daveshah
daveshah / restart.ps1
Created December 4, 2013 15:11
Workaround for the fact that some unknown code on our dev machines is killing W3SVC
# May require
# Set-ExecutionPolicy Remote
# if Get-ExecutionPolicy returns "Restricted"
Set-Service W3SVC -StartupType Automatic
Start-Service W3SVC
iisreset
*.csproj -text merge=union
*.sln -text merge=union
@daveshah
daveshah / crawler.rb
Last active January 1, 2016 13:09
Crawling the clinic site for all our css yo'
require 'anemone'
require 'nokogiri'
require 'set'
@url = "http://my.clevelandclinic.org/default.aspx"
@moss_garbage = "layouts/1033/styles"
@css_link_set = Set.new
@flash_link_set = Set.new