Skip to content

Instantly share code, notes, and snippets.

@Edukanezza
Edukanezza / trimText.js
Created April 29, 2015 20:54
Trim text down and add ...
// Trim text.
function trimText( jquery_obj_to_trim, trim_length ){
var currentText = jquery_obj_to_trim.text();
var newLength = trim_length;
var currentTextTrimmed = currentText.substr(0, newLength);
var endOfCurrentText = /\W?\s?\b\w+\W*?$/.exec( currentTextTrimmed );
if( endOfCurrentText === null ) return;
var endOfCurrentTextLength = endOfCurrentText[0].length;
currentTextTrimmed = currentText.substr(0, newLength - endOfCurrentTextLength );
@namklabs
namklabs / collapse-expand.html
Created April 16, 2015 19:40
Bootstrap Collapse & Expand Buttons
<div class="btn-group pull-right" role="group">
<button class="btn btn-default inline" data-target="#content .panel:not('.in')" data-toggle="collapse" id="info-page-uncollapse-all">Expand All <span class="glyphicon glyphicon-chevron-down">​</span></button>
<button class="btn btn-default" data-target="#content .panel.in" data-toggle="collapse" id="info-page-collapse-all">Collapse All <span class="glyphicon glyphicon-chevron-up">​</span></button>
</div>
@nick1n
nick1n / bookmark-help.js
Created January 2, 2015 17:59
Bookmark help for mobile phones
// Bookmark help for phones
var isMobile = {
Android: navigator.userAgent.match(/Android/i),
BlackBerry: navigator.userAgent.match(/BlackBerry/i),
iOS: navigator.userAgent.match(/iPhone|iPad|iPod/i),
Opera: navigator.userAgent.match(/Opera Mini/i),
Windows: navigator.userAgent.match(/IEMobile/i),
any: function() {
return isMobile.Android || isMobile.BlackBerry || isMobile.iOS || isMobile.Opera || isMobile.Windows;
}
@Joncom
Joncom / gist:e8e8d18ebe7fe55c3894
Last active September 11, 2021 00:29
Check if two line segments intersect
// Adapted from: http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect/1968345#1968345
function line_intersects(p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y) {
var s1_x, s1_y, s2_x, s2_y;
s1_x = p1_x - p0_x;
s1_y = p1_y - p0_y;
s2_x = p3_x - p2_x;
s2_y = p3_y - p2_y;
var s, t;
int[][] result;
float t;
void setup() {
setup_();
result = new int[width*height][3];
}
void draw() {
@staltz
staltz / introrx.md
Last active April 1, 2025 06:30
The introduction to Reactive Programming you've been missing
// by Dave @ Bees & Bombs >:)
int[][] result;
float time;
void setup() {
setup_();
result = new int[width*height][3];
}
$.fn.equalheight = function( remove ) {
// Reset heights from the last viewport resize so that values do not get wacky-large.
this.height('auto');
// if remove is true, just reset the heights and return
if ( remove ) {
return;
}
$.fn.equalheight = function( remove ) {
// Reset heights from the last viewport resize so that values do not get wacky-large.
this.height('auto');
// if remove is true, just reset the heights and return
if ( remove ) {
return;
}
@namklabs
namklabs / equalheight.js
Last active June 8, 2016 18:44
Force sibling columns with .equal-height class to size to the largest height of the group.
$.fn.equalheight = function(){
var $selection = this;
var $groups = [];
while( $selection.length > 1 ){// If $selection.length is greater than 1, then it must be 2, meaning there are at least 2 equal-height divs left. This will prevent an infinite loop if there is an equal-height div without a partner equal-height div.
// Find an equal-height group.
$groups.push( $selection.eq(0).siblings('.equal-height').addBack() );
// Reduce selection by the latest equal-height group.
$selection = $selection.not( $groups[ $groups.length - 1 ] );
// Drop groups that only have 1 element - it doesn't make any sense to have a lone equal-height element.