Skip to content

Instantly share code, notes, and snippets.

@coverslide
coverslide / JavascriptCarousel.html
Created November 24, 2010 01:16
A cool 3D rotating carousel in Javascript
<style type="text/css">
.carousel-wrapper
{
height: 420px;
margin-bottom: 20px;
background: #FFF;
border-radius: 8px;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
overflow: hidden;
@coverslide
coverslide / jquery.newscroller.js
Created July 18, 2011 22:51
An implementation of a jQuery carousel.
jQuery.fn.newScroller = function(_options) {
if (typeof _options == "string") {
var args = Array.prototype.slice.call(arguments, 1)
return this.each(function() {
var $this = $(this)
data = $this.data("newScroller")
if (_options in data.functions)
data.functions[_options](args)
})
}
@coverslide
coverslide / serve.js
Created August 17, 2011 20:51
A simple no-dependency script I use for serving static files. Very useful for viewing html docs.
#!/usr/bin/env node
var http = require('http')
, path = require('path')
, url = require('url')
, fs = require('fs')
, base = path.resolve(process.argv[2] || '.')
, port = process.argv[3] || 8080
http.createServer(function (req, res) {
var requrl = url.parse(req.url).pathname
@coverslide
coverslide / chainify.js
Created August 17, 2011 22:20
A simple object wrapper that converts functions that return `undefined` to return an instance of the object instead, `chainifying` those calls
function chainify(obj, that){
if(typeof obj === 'object'){
that = that || {__object: obj}
for(var i in obj){
if(typeof obj[i] === 'function'){
that[i] = function(){
var ret = that.__object[i].apply(that.__object, arguments)
if(typeof ret === 'undefined')
return that
return ret
@coverslide
coverslide / gencert.sh
Created October 23, 2012 07:00
Bash script to generate ssl key / cert
#!/bin/sh
# default values
conf_file="$HOME/.gencert2"
key_file=key.pem
csr_file=csr.pem
cert_file=cert.pem
bits=1024
get_vars(){
@coverslide
coverslide / multi-line-ternary.js
Created January 3, 2013 22:58
Multi-line ternary example
var age_group = age > 70 ? 'se' :
age > 60 ? 'si' :
age > 50 ? 'fi' :
age > 40 ? 'fo' :
age > 30 ? 'th' :
age > 20 ? 'tw' :
'un';
@coverslide
coverslide / naive-template.js
Last active August 29, 2015 14:15
Some simple javascript template functions
// all falsy values do not display
function makeTemplate (html) {
return function (data) {
return html.replace(/\{\{\s*([^\s}]+?)\s*\}\}/g, function (match, key) {
return key.split('.').reduce(function (data, key) {
return data ? (data[key] || '') : '';
}, data);
});
};
}
@coverslide
coverslide / Webpack Base
Last active April 2, 2018 04:29
Webpack Base
Webpack Base
const fetch = (url) => {
return new Promise((resolve, reject) => {
https.get(url, (response) => {
const dataPromise = new Promise((resolve, reject) => {
const d = [];
let dlen = 0;
response.on('error', reject);
response.on('data', (data) => {