Skip to content

Instantly share code, notes, and snippets.

@bultas
bultas / foundInObj.js
Last active August 29, 2015 14:11
Set value to Object property (string path)
/**
* Return true/false if key is found in Object (one level)
* @param {object} object where to try find key
* @param {string} key - string to find in object
* @return {boolean} true/false if key is found
*/
var foundInObject = function (object, key) {
var keyFound = null;
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@bultas
bultas / gist:8394d160439348a0e6ac
Created February 5, 2015 10:04
ContentEditable placeholder
// http://stackoverflow.com/a/18368720
// http://codepen.io/mrmoje/pen/lkLez
// HTML
<div contentEditable=true data-placeholder="My Placeholder String"></div>
// CSS
@bultas
bultas / gist:6224ff31bfbcda43df05
Created February 10, 2015 22:41
ContentEditable React Component
var React = require('react');
var Medium = require("medium.js");
function setupEditable(self) {
var editable = self.props.editable;
var extraOptions = self.props.extraOptions;
@bultas
bultas / gist:18eaec446983b468ec33
Last active August 29, 2015 14:15
React Array Map
var arrayData = [...];
var arrayOfItems = arrayData.map(function(item, i) {
return (
<item key={i}>{item}</item>
);
});
@bultas
bultas / router.html
Last active October 29, 2023 23:19 — forked from joakimbeng/router.html
A Javascript router in 20 lines
<!-- http://joakimbeng.eu01.aws.af.cm/a-javascript-router-in-20-lines/ -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
// Put John's template engine code here...
var copyProperties = require('react/lib/copyProperties'),
Dispatcher = require('flux').Dispatcher,
util = require('util');
function AppDispatcher() {
Dispatcher.call(this);
this._queue = [];
}
util.inherits(AppDispatcher, Dispatcher);
@bultas
bultas / gist:c161f90dd71c944f2357
Created March 3, 2015 20:03
Clone - anything with javascript (dojo toolkit)
// http://davidwalsh.name/javascript-clone
function clone(src) {
function mixin(dest, source, copyFunc) {
var name, s, i, empty = {};
for(name in source){
// the (!(name in empty) || empty[name] !== s) condition avoids copying properties in "source"
// inherited from Object.prototype. For example, if dest has a custom toString() method,
// don't overwrite it with the toString() method that source inherited from Object.prototype
s = source[name];
@bultas
bultas / getSortedObjKeys.js
Created March 5, 2015 09:11
Get Sorted Object Keys
/**
* Get array of sorted Object's keys
* @param {object} Object which keys do you want to sort
* @param {boolen} byValue - false/null if you want to sort Object keys by Object's keys
* @param {boolen} byValue - true if you want to sort Object keys by Object's properties value
* @param {string} byValue - string if you want to sort Object keys by value inside each Object's property
* @return {array} Array of sorted keys (strings)
*/
var getSortedObjKeys = function(obj, byValue) {
@bultas
bultas / gist:3fcd11d8e5e31e93562d
Created March 18, 2015 21:24
GIT - how to replace master branch with another branch
http://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch
You should be able to use the "ours" merge strategy to overwrite master with AnotherBranch like this:
git checkout AnotherBranch
git merge -s ours master
git checkout master
git merge AnotherBranch
The result should be your master is now essentially AnotherBranch.