Skip to content

Instantly share code, notes, and snippets.

View davidpdrsn's full-sized avatar

David Pedersen davidpdrsn

View GitHub Profile
@davidpdrsn
davidpdrsn / _mixins.scss
Last active April 17, 2020 12:34
Sass mixins
// By David Pedersen (@davidpdrsn)
// https://gist.github.com/davidpdrsn/3101105
// Version 0.2
//////////////////////////////////////
/// Media queries ////////////////////
//////////////////////////////////////
// Foundation 3
@mixin small {
@davidpdrsn
davidpdrsn / jquery.isInView.js
Last active April 9, 2020 19:40
Simple jQuery plugin used to determine if an element is within the viewport or not. It currently looks at the middle of the element.
/*
* By David Pedersen (@davidpdrsn)
* https://gist.github.com/davidpdrsn/4434085
* Version 0.1
*/
jQuery.fn.isInView = function(){
// setup different vars for easier access to these values
var middle = Math.round(this.height() / 2),
winHeight = $(window).height(),
@davidpdrsn
davidpdrsn / nav-top-reset.scss
Created June 3, 2013 12:57
Foundation nav-top css reset
nav.main {
ul.nav-bar {
margin: 0;
height: auto;
background: none;
padding: 0;
> li {
float: none;
display: block;
position: static;
Testing http://3f.dk
At Wed Jul 10 14:23:53 2013
10 loops
Fastest Median Slowest Std Dev
---------------------------------------------------------------------------
Server performance:
Total application time Unable to be recorded
@davidpdrsn
davidpdrsn / move_fonts.rb
Created September 1, 2013 16:09
Move fonts in current folder to ~/Library/Fonts (aka install it)
require 'fileutils'
files = Dir.glob("**/*").select do |file|
file if file.match /\.(ttf|otf)$/i
end
files.each do |file|
FileUtils.cp_r file, "/Users/#{`whoami`.chomp}/Library/Fonts", :verbose => true
FileUtils.rm_r file, :verbose => true
puts ""
@davidpdrsn
davidpdrsn / 1_timer.sml
Last active February 23, 2017 13:23
Functions to time other functions.
local
(* sum of a list of ints
sum : int list -> int *)
fun sum l = foldl op+ 0 l
(* avarage of a list of ints
avg : int list -> real *)
fun avg l = real(sum(l)) / real(length(l))
in
(* calculate the amount of time it takes to run a function once
@davidpdrsn
davidpdrsn / bSort.sml
Last active June 2, 2016 13:22
Bubble sort in SML
(* sorted : int list -> bool
* check if a list of ints is sorted *)
fun sorted [] = true
| sorted [x] = true
| sorted (x::y::xs) = x < y andalso sorted (y::xs)
val sorted_test1 = sorted [1,2,3]
val sorted_test2 = not (sorted [2,1,3])
val sorted_test3 = not (sorted [2,3,1])
val sorted_test4 = sorted []
describe('lastViewedPages', function() {
var pages = null;
beforeEach(function() {
localStorage.clear();
pages = new LastViewedPages();
});
it("doesn't come with pages already saved", function() {
@davidpdrsn
davidpdrsn / move_java.rb
Created November 19, 2013 12:09
Move Java files into folders
Dir.glob("*.java").each do |f|
contents = File.read f
folder = contents.
split("\n").
first.
delete("/").
delete(" ").
delete(",test").
delete(",implementation").
@davidpdrsn
davidpdrsn / FooTest.java
Last active December 30, 2015 07:19
A template for JUnit files.
import java.util.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.junit.Test; // for @Test
import org.junit.Before; // for @Before
import org.junit.Ignore; // for @Ignore
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;