Skip to content

Instantly share code, notes, and snippets.

@killercup
killercup / gist:2783854
Created May 24, 2012 — forked from mataspetrikas/gist:2300296
Check if element is visible in viewport and scroll if necessary
View gist:2783854
$.extend $.expr[":"],
inView: (a) ->
# cf. http://remysharp.com/2009/01/26/element-in-view-event-plugin/#comment-127058
st = (document.documentElement.scrollTop or document.body.scrollTop)
ot = $(a).offset().top
wh = (if (window.innerHeight and window.innerHeight < $(window).height()) then window.innerHeight else $(window).height())
ot > st and ($(a).height() + ot) < (st + wh)
$.fn.scroll_if_necessary = ->
if this.length && not @is(":inView")
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Foo</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<style type='text/css'>
body {
font-family: 'Helvetica Neue';
background:#000;
@killercup
killercup / bling.js
Last active Apr 24, 2018 — forked from paulirish/bling.js
bling dot js
View bling.js
/**
* bling.js
*
* Original Author: Paul Irish
* Fetched from https://gist.github.com/paulirish/12fb951a8b893a454b32/fe4fa7794b6575d8356ac73a79b0aefd75ffacbb
*/
/**
* Select elements with CSS-style selector syntax
*
@killercup
killercup / min-max.rs
Created Sep 30, 2015 — forked from anonymous/playground.rs
Rust min! and max! macros
View min-max.rs
macro_rules! max {
($x:expr) => ( $x );
($x:expr, $($xs:expr),+) => {
{
use std::cmp::max;
max($x, max!( $($xs),+ ))
}
};
}
@killercup
killercup / playground.rs
Created Sep 5, 2016 — forked from anonymous/playground.rs
Rust code shared from the playground
View playground.rs
// https://benchmarksgame.alioth.debian.org/u64q/knucleotide-description.html#knucleotide
extern crate fnv;
use std::thread;
use std::sync::Arc;
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use fnv::FnvHasher;
const SEQ_LENS: [usize; 7] = [1, 2, 3, 4, 6, 12, 18];