Skip to content

Instantly share code, notes, and snippets.

View kaw2k's full-sized avatar

Rasa Welcher kaw2k

View GitHub Profile
@kaw2k
kaw2k / gist:4210929
Created December 5, 2012 01:00
A simple extension of the javascript Number class for ease of generating random numbers.
// Example use
// var arr = [1, 2, 3, 4, 5];
// var len = arr.length;
// var item = arr[len.random()];
Number.prototype.random = function(inc) {
var val = (inc) ? 1 : 0;
return Math.floor(Math.random() * (this.valueOf() + val));
};
@kaw2k
kaw2k / Gruntfile.js
Last active December 17, 2015 02:39
A simple sample gruntfile. If you are trying this, make sure to run `npm install`.
function commentCommand(cmd) {
cmd = cmd || 'cmd';
var result = require('execSync')
.exec('grep -nr "// '+cmd+':" ./')
.stdout
.split('\n')[0];
if (result !== '') {
var reg = new RegExp('// '+cmd+':(.+)', 'i');
result = result.match(reg)[1];
}
@kaw2k
kaw2k / allCapsBot.js
Last active December 21, 2015 07:28
Simple all caps javascript bot
// Import settings
var settings = require('./settings');
// Setup IRC
var irc = require('irc');
var bot = new irc.Client(settings.server, settings.botName, settings);
console.log(
settings.botName + ' connecting to ' + settings.server + settings.channels
);
@kaw2k
kaw2k / functional.meetup.js
Last active September 29, 2016 06:15
Examples from the functional javascript meetup
// To play around with this code, copy and paste the contents of this gist
// into the javascript pane of http://jsbin.com/umoK/1/edit or go to
// http://jsbin.com/uZAfIqA/2/edit
// =============================================================================
// Generic API
// =============================================================================
//+ words :: string -> array
var words = split(' ');
browserify: {
options: {
debug: true,
transform: ['reactify'],
extensions: ['.jsx']
},
dist: {
files: { 'app/public/scripts/scripts.js': 'app/src/scripts/main.js'}
}
}
var IfElse = React.createClass({
render: function() {
var contents = (something) ? <span>Hello</span> : <div>World!</div>;
return (
<div>
{contents}
</div>
);
}
var http = require('http');
http.createServer(function(req, res) {
res.setTimeout(0)
setTimeout(function() {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<p>Hello World</p>');
res.end();
}, 100)
" ==============================================================================
" Install Bundles
" ==============================================================================
" Required for neocomplcache
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
" Installed Bundles
Bundle 'editorconfig/editorconfig-vim'
@kaw2k
kaw2k / alerts.md
Last active August 29, 2015 14:09
Alert API

Thoughts on alerts

The basic question boils down to "Who should dictate if the alert is rendered?"

Parent controls all

In this situation, what you return from your render method is always rendered to the screen. Let's start by making a hypothetical API

'use strict';
var React = require('react');
var _ = require('ramda');
var moment = require('moment');
var Day = require('components/day');
var Calendar = require('components/calendar');
class MultiCalendar extends React.Component {