Skip to content

Instantly share code, notes, and snippets.

@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active May 16, 2024 16:51
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@crazy4groovy
crazy4groovy / jQueryPhantomScrape
Created June 18, 2012 15:47
Scrape the web using PhantomJS and jQuery
//This is an example of how to scrape the web using PhantomJS and jQuery:
//source: http://snippets.aktagon.com/snippets/534-How-to-scrape-web-pages-with-PhantomJS-and-jQuery
//http://phantomjs.org/
var page = new WebPage(),
url = 'http://localhost/a-search-form',
stepIndex = 0;
/**
* From PhantomJS documentation:
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@sTiLL-iLL
sTiLL-iLL / clock2.html
Last active December 18, 2015 02:29
Widget inHTML and JS (jquery-ui) smooth animated clock
<!-- clock widget exmple -->
<!DOCTYPE html>
<html>
<head runat="server">
<meta charset="utf-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
@SunboX
SunboX / inlineworker.js
Created June 24, 2013 12:21
Create web workers without a separate worker JS files. Source: http://jsbin.com/owogib/8/
function worker() {
setInterval(function() {
postMessage({foo: "bar"});
}, 1000);
}
var code = worker.toString();
code = code.substring(code.indexOf("{")+1, code.lastIndexOf("}"));
var blob = new Blob([code], {type: "application/javascript"});
@sTiLL-iLL
sTiLL-iLL / cloneIt.js
Created August 3, 2013 11:37
kustom klone method
function clone(src) {
function mixem(src, dst, fnc) {
var i, em, nm, j = {};
for(nm in src){
j = src[nm];
if(!(nm in dst) || (dst[nm] !== j && (!(nm in em) || em[nm] !== j))){
dst[nm] = fnc ? fnc(s) : j;
}
}
@sTiLL-iLL
sTiLL-iLL / img2canvas.js
Created August 3, 2013 12:12
img 2 canvas
// Converts image to canvas; returns new canvas element
function Img2Cnvs(image) {
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext("2d").drawImage(image, 0, 0);
return canvas;
@sTiLL-iLL
sTiLL-iLL / myEvent.js
Last active December 20, 2015 14:29
custom eventing
//create event
var minE = new CustomEvent("yourEventName", {
detail: {
"key": value
},
bubbles: true,
cancelable: true
});
//add handler
@sTiLL-iLL
sTiLL-iLL / forEvery.js
Last active December 20, 2015 14:59
some home-made "underscore" type constructs
// my for-each thing
function forEeach(array, action) {
try {
var len = array.length;
for (var i = 0; i < len; i++)
action(array[i]);
} catch (e) {
throw e;
}
@sTiLL-iLL
sTiLL-iLL / 4EveryOne.js
Created August 4, 2013 18:48
4 all Items in a list loop logic
// on every "yada" in "yada"....
function onEachIn(object, action) {
try {
for (var property in object) {
if (Object.prototype.hasOwnProperty.call(object, property))
action(property, object[property]);
}
} catch (e) {
throw e;