Skip to content

Instantly share code, notes, and snippets.

@amolk
amolk / remove-rubber-band-web-apps-ios
Last active May 8, 2024 17:47
Remove rubberband scrolling from web apps on mobile safari (iOS)
<!DOCTYPE html>
<html>
<head>
<title>Remove rubberband scrolling from web apps on mobile safari (iOS)</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta id="extViewportMeta" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<style>
html, body {margin: 0; padding: 0; overflow: hidden}
@iam4x
iam4x / autosizetext.coffee
Last active August 2, 2018 19:36
I wrote this simple function in CoffeeScript which tests if the text overflow the div and it will decrement his size until it fits!
autoSizeText = ->
elements = $('.resize')
return if elements.length < 0
for el in elements
do (el) ->
resizeText = ->
elNewFontSize = (parseInt($(el).css('font-size'), 10) - 1)
$(el).css('font-size', elNewFontSize)
resizeText() while el.scrollHeight > el.offsetHeight
@mjackson
mjackson / color-conversion-algorithms.js
Last active June 8, 2024 01:27
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
@6174
6174 / Random-string
Created July 23, 2013 13:36
Generate a random string in JavaScript In a short and fast way!
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@iamkirkbater
iamkirkbater / autoSizr.js
Created August 6, 2014 13:45
Simple jQuery Plugin that auto resizes text to fill a specific sized div (great for responsive slideshows that utilize large banner text with variable lengths), derived from https://gist.github.com/iam4x/5015270
$.fn.autoSizr = function () {
var el, elements, _i, _len, _results;
elements = $(this);
if (elements.length < 0) {
return;
}
_results = [];
for (_i = 0, _len = elements.length; _i < _len; _i++) {
el = elements[_i];
_results.push((function(el) {
angular.module('qAllSettled', []).config(function($provide) {
$provide.decorator('$q', function($delegate) {
var $q = $delegate;
$q.allSettled = function(promises) {
return $q.all(promises.map(function(promise) {
return promise.then(function(value) {
return { state: 'fulfilled', value: value };
}, function(reason) {
return { state: 'rejected', reason: reason };
});
@katowulf
katowulf / normalize_record.js
Last active January 5, 2018 00:08
Normalize a "post" record by adding "user" data from another Firebase path in AngularFire
app.factory('NormalizedPosts', function($firebaseArray, userCache) {
var PostsWithUsers = $firebaseArray.$extend({
// override $$added to include users
$$added: function(snap) {
// call the super method
var record = $firebaseArray.prototype.$$added.call(this, snap);
userCache.$load( record.user ).$loaded(function( userData ) {
record.userData = userData;
});
@katowulf
katowulf / global.js
Last active May 30, 2016 21:27
Overriding error handling in AngularFire by extending and decorating $$error
// this will remove all error logging globally
angular.config(function($provide) {
$provide.decorator("$firebaseObject", function($delegate) {
$delegate.prototype.$$error = function(err) {
this.$destroy(err);
};
return $delegate;
});
$provide.decorator("$firebaseArray", function($delegate) {
@katowulf
katowulf / example_rules.js
Created February 10, 2016 00:25
A list of example patterns for security rules validations
{
"rules": {
// REQUIRED FIELDS
"example1" : {
"$record": {
// foo and bar are required fields that must always exist
// this will reject writes to $record, as well as directly to $record/foo or $record/bar if they are null
".validate": "newData.hasChildren(['foo', 'bar'])"
}
@katowulf
katowulf / rules.js
Created March 3, 2016 00:05
Search for users by email address in Firebase, without exposing everyone's email address to the world in a bulk-readable format.
{
"rules": {
"users": {
"$user_id": {
// email address is required
".validate": "newData.hasChildren(['email'])",
}
},
"emails_to_users": {