Skip to content

Instantly share code, notes, and snippets.

@ilblog
ilblog / fullscreen_controller.js
Created December 20, 2017 17:32
Microscopic Javascript fullscreen controller
// Fullscreen controller used on www.windy.com
const d = document
, el = $('#fullscreen')
, isFullscreen = () => d.fullscreen || d.webkitIsFullScreen || d.mozFullScreen
, onFullChange = () => el.innerHTML = isFullscreen() ? '' : '-' // Change of icon
d.addEventListener('fullscreenchange', onFullChange )
d.addEventListener('webkitfullscreenchange',onFullChange )
d.addEventListener('webkitfullscreenchange',onFullChange )
d.addEventListener('mozfullscreenchange',onFullChange )
@njvack
njvack / README.md
Last active February 8, 2024 21:43
Color to hex and rgba converter

Simple canvas-based color converter

To answer this StackOverflow question I wrote this — a small solution based on a never-rendered <canvas> element. It fills a 1-pixel canvas with the provided fill-style, and then reads the RGBA values of that pixel. It will work with any CSS color -- name, rgba(), hex, or even something more exotic like a gradient or pattern. Invalid colors are always returned as transparent black. Transparent colors are treated as painted on a newly-cleared canvas.

It's been tested in modern-ish versions of IE, Chrome, Safari, and Firefox. The API is:

color_convert.to_hex(color)   # Converts color to a hex-based RGB triple; to_hex('red') returns '#ff0000'
color_convert.to_rgba(color)  # Converts color to an rgba() string; to_rgba('red') returns 'rgba(255,0,0,1)'
@jjmu15
jjmu15 / in_viewport.js
Created January 27, 2014 10:19
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@ahmedelgabri
ahmedelgabri / gist:8122545
Last active December 22, 2020 08:46
Shell function to open a static server (Python, Ruby or PHP)

Static server shell function

A Modified function of Paul Irish's StaticServer shell function, according to this gist You can run static servers for many languages.

How it works

$ staticServer <lang> <port> #port is optional, default is 8000
@willurd
willurd / web-servers.md
Last active July 3, 2024 13:20
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@vancura
vancura / less-watcher.rb
Created November 1, 2011 09:41
Folder watcher (replace "less-compile.sh" with your own command)
#!/usr/bin/env ruby
# watch.rb by Brett Terpstra, 2011 <http://brettterpstra.com>
# with credit to Carlo Zottmann <https://github.com/carlo/haml-sass-file-watcher>
# original by Brett Terpstra <http://brettterpstra.com/watch-for-file-changes-and-refresh-your-browser-automatically/>
# fork by Vaclav Vancura / SAY Media <http://saymedia.com>
trap("SIGINT") { exit }
filetypes = ['less']
watch_folder = 'content/media/less'
@timuruski
timuruski / toggle-color-format
Created April 7, 2011 17:04
TextMate command for toggling CSS color format through hex, RGB and RGBA
#!/usr/bin/env ruby
class Color < Struct.new(:r, :g, :b, :a)
def self.from_hex (str)
args = case str.length
when 3; str.scan(/[0-9a-f]/i).map{ |s| "#{s}#{s}".to_i(16) }
when 6; str.scan(/[0-9a-f]{2}/i).map{ |s| s.to_i(16) }
else [0, 0, 0]
end << 1.0
new(*args)
@mloberg
mloberg / example.php
Created March 10, 2011 19:27
A simple Postmark PHP Class
<?php
require("postmark.php");
$postmark = new Postmark("your-api-key","from-email","optional-reply-to-address");
if($postmark->to("reciver@example.com")->subject("Email Subject")->plain_message("This is a plain text message.")->send()){
echo "Message sent";
}