Skip to content

Instantly share code, notes, and snippets.

View kharmabum's full-sized avatar
💭
🧀

Juan-Carlos Foust kharmabum

💭
🧀
View GitHub Profile
@kharmabum
kharmabum / .zshrc
Created August 5, 2013 03:48
zshrc profile
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
ZSH_THEME="smt"
COMPLETION_WAITING_DOTS="true"
plugins=(git github osx sublime)
source $ZSH/oh-my-zsh.sh
unsetopt correct_all
export NODE_PATH=/usr/local/lib/node
@kharmabum
kharmabum / mongodb-node-config.js
Created August 4, 2013 18:52
configure mongodb database w/ node
var config = {
"USER" : "",
"PASS" : "",
"HOST" : "ec2-xx-xx-xx-xx.ap-southeast-2.compute.amazonaws.com", "PORT" : "27017",
"DATABASE" : "my_example"
};
var dbPath = "mongodb://" + config.USER + ":" + config.PASS + "@" + config.HOST + ":" + config.PORT + "/" + config.DATABASE;
var mongoose = require('mongoose');
var db = mongoose.connect(dbPath);
@kharmabum
kharmabum / search.js.handlebars
Created July 27, 2013 22:09
search text field + results view. Discourse App.
{{view Discourse.SearchTextField valueBinding="term" searchContextBinding="searchContext"}}
{{#unless loading}}
{{#unless noResults}}
{{#each resultType in content}}
<ul>
<li class='heading'>
{{resultType.name}}
{{#if resultType.more}}
<a href='#' class='filter' {{action moreOfType resultType.type bubbles=false}}>{{i18n show_more}}</a>
{{else}}
@kharmabum
kharmabum / selectedText.js
Created July 24, 2013 21:49
Get selected text from the browswer window
selectedText: function() {
var html = '';
if (typeof window.getSelection !== "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
@kharmabum
kharmabum / emailValid.js
Created July 24, 2013 21:48
validate email address in javascript
emailValid: function(email) {
// see: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
var re;
re = /^[a-zA-Z0-9!#$%&'*+\/=?\^_`{|}~\-]+(?:\.[a-zA-Z0-9!#$%&'\*+\/=?\^_`{|}~\-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?$/;
return re.test(email);
}
@kharmabum
kharmabum / key_value_store.js
Created July 24, 2013 21:46
HTML5 LocalStorage
/**
A simple key value store that uses LocalStorage
@class KeyValueStore
@namespace Discourse
@module Discourse
**/
Discourse.KeyValueStore = {
initialized: false,
context: "",
@kharmabum
kharmabum / uniqueId.js
Created July 24, 2013 21:46
guid in javascript
uniqueId = function() {
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r, v;
r = Math.random() * 16 | 0;
v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
@kharmabum
kharmabum / accordion_view.js
Last active December 20, 2015 03:29
Ember view for Bootstrap collapse component
define(['main/config'], function (config) {
App.AccordionItemView = Ember.View.extend({
classNames: ['accordion-group'],
parentId: null,
parentRef: function() {
var hasGroupControl = this.get('parentView.hasGroupControl');
return (hasGroupControl) ? "#" + this.get('parentId') : "";
}.property('parentId'),
internalId: null,
@kharmabum
kharmabum / resource-navigation.html
Created July 16, 2013 22:50
URL resource navigation
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=htmlapps/">
<script type="text/javascript">
window.location.href = "htmlapps/"
</script>
<title>Page Redirection</title>
</head>
@kharmabum
kharmabum / show-html.js
Created July 16, 2013 00:31
Animates the dimensional changes resulting from altering element contents. Taken from Discourse source.
// Animates the dimensional changes resulting from altering element contents
// Usage examples:
// $("#myElement").showHtml("new HTML contents");
// $("div").showHtml("new HTML contents", 400);
// $(".className").showHtml("new HTML contents", 400,
// function() {/* on completion */});
(function($)
{
$.fn.showHtml = function(html, speed, callback)
{