Skip to content

Instantly share code, notes, and snippets.

@egobrain
egobrain / file_upload_example.html
Created April 6, 2012 05:44
File upload example that uses new Browser HTML5 Upload API.
<style>
#dropZone {
color: #555;
font-size: 18px;
text-align: center;
width: 400px;
padding: 50px 0;
margin: 50px auto;
@egobrain
egobrain / upload_handler.erl
Created May 25, 2012 13:17
upload_handler
-module(upload_handler).
-behaviour(cowboy_http_handler).
-export([init/3, handle/2, terminate/2]).
init({_Transport, http}, Req, []) ->
{ok, Req, {}}.
handle(Req, State) ->
{Method,Req2} = cowboy_http_req:method(Req),
case Method of
@egobrain
egobrain / cowboy_multipart_uploader.erl
Created May 30, 2012 06:47
Cowboy files uploader.
%%%-------------------------------------------------------------------
%%% @author egobrain <egobrain@linux-ympb>
%%% @copyright (C) 2012, egobrain
%%% @doc
%%% Function for uploading files and properties,which were sent as a
%%% multipart. Files are stored in tmp_folder with random name,
%%% generated by tmp_filename function.
%%% @end
%%% Created : 25 Mar 2012 by egobrain <egobrain@linux-ympb>
%%%-------------------------------------------------------------------
@egobrain
egobrain / watch-rebuild.sh
Last active December 17, 2015 20:39
Script run make in current folder if files of specific type are changed
#!/bin/bash
usage() {
cat <<EOF
usage: $(basename $0) [OPTIONS]
This script run make in folder
if file of specific type is changed
OPTIONS:
@egobrain
egobrain / ast_helper.erl
Created July 2, 2013 08:55
Erlang Ast helper.
-define(atom(Atom),erl_syntax:atom(Atom)).
-define(var(Var),erl_syntax:variable(Var)).
-define(underscore,erl_syntax:underscore()).
-define(apply(Fun,Args),erl_syntax:application(?atom(Fun),Args)).
-define(apply(Mod,Fun,Args),erl_syntax:application(?atom(Mod),?atom(Fun),Args)).
-define(apply_(Fun,Args),erl_syntax:application(Fun,Args)).
-define(clause(Pattern,Guard,Body),erl_syntax:clause(Pattern,Guard,Body)).
-define(cases(Arg,Clauses),erl_syntax:case_expr(Arg,Clauses)).
-define(ifs(Clauses),erl_syntax:if_expr(Clauses)).
Here is a simple jQuery plugin to make a table header fixed on top when window is scrolled.
Using the code from twitter bootstrap documentation page, this code is customized for table header.
Create the table with following layout -
<table class="table-fixed-header">
<thead class="header">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
@egobrain
egobrain / CallOnceConstructor.coffee
Last active December 20, 2015 05:38
Call only last defined function wrapper (Coffee)
CallOnceConstructor = ->
cache = {}
(f) ->
cache.f_link?.f = null
f_link = f: f
cache.f_link = f_link
-> f_link.f?.apply null, arguments
# example
# call_last = CallOnceConstructor()
@egobrain
egobrain / CallOnceConstructor.js
Last active December 20, 2015 05:38
Call only last defined function wrapper (Js)
var CallOnceConstructor = function () {
var cache = {};
return function (f) {
if (cache.f_link) {cache.f_link.f = null};
var f_link = {f: f};
cache.f_link = f_link
return function() {
if (f_link.f) f_link.f.apply(null, arguments);
};
}
@egobrain
egobrain / .bashrc
Created August 29, 2013 08:14
bashrc for easy git
# ~/.bashrc: executed by bash(1) for non-login shells. see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# add local bin path
PATH=$HOME/.bin:$PATH
PATH=/usr/local/bin:$PATH
PATH=/usr/local/sbin:$PATH
PATH=/usr/local/mysql/bin:$PATH
<html>
<head>
<title>Test remember password</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#login-button').click(function (ev) {
alert('AJAX login...');
});