Skip to content

Instantly share code, notes, and snippets.

@caike
caike / search.go
Created February 26, 2016 21:09
Example of using goroutines to run code concurrently
package search
import (
"fmt"
"time"
)
// Search performs a search
func Search(term string) string {
@caike
caike / attack.md
Last active October 2, 2022 14:37
XSS attack demo with innerHTML

Tested with Chrome, Firefox and Safari.

The following code will not trigger an alert. target.innerHTML = "<script> alert('XSS Attack'); </script>";

The following code will trigger an alert. target.innerHTML = "";

@caike
caike / run.js
Last active August 29, 2015 14:24
async calls
fetchProfile(1, function(){
console.log("Callback 1");
});
fetchProfile(2, function(){
console.log("Callback 2");
});
fetchProfile(3, function(){
console.log("Callback 3");
});
fetchProfile(4, function(){
@caike
caike / promises.js
Last active August 29, 2015 14:21
Promises demo
console.log("A");
var returnFromTwo = stepOne().then(stepTwo);
console.log("B");
returnFromTwo.then(stepThree);
console.log("C");
@caike
caike / twit-tv-demo.rb
Created May 5, 2015 19:25
Demo code for Twit.tv
class Person
def initialize(name, location)
@name, @location = name, location
end
def greet
"Hello my name is #{@name} and I'm from #{@location}"
end
end
@caike
caike / todo.jsx
Created April 11, 2015 13:02
Simple Todo app demo using React + ES6
var React = require("react");
var allItems = []
allItems.push("Buy ingredients for Crock Pot");
allItems.push("Pick up chair at IKEA");
allItems.push("Go see mom");
class TodoList extends React.Component {
constructor(props){
super(props);
@caike
caike / angular_size.sh
Last active August 29, 2015 14:09
Calculating AngularJS 1.3.2 size once minified and compressed
wget -O angular.js https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js
gzip angular.js
ls -h angular.js.gz # 45KB
@caike
caike / Dockerfile
Last active August 29, 2015 14:07
This Dockerfile pulls application files from a URL, using the `ADD` method
# DOCKER-VERSION 1.2.0
FROM centos:centos6
# Enable EPEL for Node.js
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# Install Node.js and npm
RUN yum install -y npm
ADD https://raw.githubusercontent.com/caike/ExpressDocker/master/src/app.js /tmp/app.js
ADD https://raw.githubusercontent.com/caike/ExpressDocker/master/src/package.json /tmp/package.json
@caike
caike / Dockerfile
Created September 29, 2014 21:54
Fixed version of the Dockerfile for the tutorial at https://docs.docker.com/examples/nodejs_web_app/
# DOCKER-VERSION 1.2.0
FROM centos:centos6
# Enable EPEL for Node.js
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# Install Node.js and npm
RUN yum install -y npm
# Creates a new folder on the container
VOLUME /src
@caike
caike / Dockerfile
Created September 28, 2014 15:11
dockerfile
# DOCKER-VERSION 1.2.0
FROM centos:centos6
# Enable EPEL for Node.js
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# Install Node.js and npm
RUN yum install -y npm
# Bundle app source