Skip to content

Instantly share code, notes, and snippets.

View cethap's full-sized avatar

Cesar tapasco cethap

  • Arcaris Labs
  • Cali, Colombia
View GitHub Profile
/*This can now be done in Chrome, Safari, FF4+, and IE10pp4+!
See this question's answer for more info: Updating address bar with new URL without hash or reloading the page
Example:*/
function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}
var fs = require('fs');
var string = a.body.id;
var regex = /^data:.+\/(.+);base64,(.*)$/;
var matches = string.match(regex);
var ext = matches[1];
var data = matches[2];
var buffer = new Buffer(data, 'base64');
fs.writeFileSync('file.'+ext, buffer);
@cethap
cethap / unique name nodejs
Created March 16, 2014 21:47
ShortJsGist
crypto.randomBytes(48, function(ex, buf) {
token = buf.toString('base64').replace(/\//g,'_').replace(/\+/g,'-');
fs.writeFileSync(token+'.'+ext, buffer);
});
@cethap
cethap / ID.js
Created March 21, 2014 15:22
ShortJsGist
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`

JavaScript reference for non-JavaScript programmers

Author: Yotam Gingold
License: Public Domain (CC0)

This document is intended as a reference or introduction to JavaScript for someone familiar with a language like C/C++/Java or Python. It follows best practices and gathers the scattered wisdom from many stackoverflow questions and in-depth JavaScript essays. It relies on no external libraries.

@cethap
cethap / smd.js
Created March 21, 2014 15:45 — forked from gordonbrander/smd.js
Create Module js
var __modules__ = {};
function require(id) {
var module = __modules__[id];
if(!module) throw new Error('Module not yet defined');
// Get the module's exports lazily (allows registration in any order as long
// as main script entry point comes last).
return __modules__[id] = (typeof(module) === 'function') ?
if (strlen($text) == 0 XOR preg_match('/^./us', $text) == 1) {
// The string validates.
}
else {
// The string doesn't validate.
}
@cethap
cethap / Camerajs_WP
Last active August 29, 2015 14:04
wordpress
<?php
/**
* SlideCamerajs
*/
function SlideCamerajs($attr) {
$attr = shortcode_atts(
array(
'height' => '320',
var myString = (function () {/*
<div id="someId">
some content<br />
<a href="#someRef">someRefTxt</a>
</div>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
browser.actions().mouseMove(element(by.css('#myElement'))).perform();
browser.actions().click(protractor.Button.RIGHT).perform();