Skip to content

Instantly share code, notes, and snippets.

View Radagaisus's full-sized avatar

Almog Melamed Radagaisus

View GitHub Profile
# Load the environment configuration options
config = require '../../config/environments'
# Require Redis
redis = require 'redis'
# Create a Redis client
client = redis.createClient()
# `queue` handles queueing a background job to Resque. We directly use
@Radagaisus
Radagaisus / parallel.coffee
Created October 26, 2013 08:24
parallel middlewares
async = require 'async'
# The `parallel` middleware allows to run several middlewares in parallel.
# It does this by simply using AsyncJS' `applyEach` on the middlewares.
#
# The middlewares will receive 3 parameters: `request`, `response` and
# `next`, in the same way and order they usually get them. As the
# execution is in parallel, if one of the middlewares will have an error
# the second one will continue to execute. If an error is passed to the
# `next` callback it will be passed correctly forward.
@Radagaisus
Radagaisus / servers.sh
Created May 21, 2013 23:21
Starts a PHP or a Python server on a directory
# Stolen from a famous dotfile
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
@Radagaisus
Radagaisus / .bash_profile
Last active August 18, 2021 10:41
Bash prompt
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
GRAY="\[\033[1;30m\]"
LIGHT_GRAY="\[\033[0;37m\]"
CYAN="\[\033[0;36m\]"
k2v = (h) -> (do (k,v) -> (n) -> not (n % v) && k || '') for k,v of fizz: 3, buzz: 5
console.log ((fn(i) for fn in k2v()).join('') || i for i in [1..100]).join "\n"
@Radagaisus
Radagaisus / implicit-return.coffee
Created December 10, 2012 06:04
Implicit for loops return values
sum = ->
sum = 0
for i in [1..5]
sum += i
@Radagaisus
Radagaisus / icons.sh
Created December 3, 2012 16:26
✘ and ✓
# From yeoman's source code
# This prints the ✘ in red,
# rest in bold.
sad_print(){
printf '\e[31m%s\e[0m \e[1m%s\e[0m %s\n' "✘" "$1" "$2"
}
# This prints ✓ in green,
# rest in bold.
@Radagaisus
Radagaisus / names.coffee
Created December 2, 2012 14:45
First Names for Seed File
exports.names = ['JAMES',
'JOHN',
'ROBERT',
'MICHAEL',
'WILLIAM',
'DAVID',
'RICHARD',
'CHARLES',
'JOSEPH',
'THOMAS',
@Radagaisus
Radagaisus / youtube_url.coffee
Created November 29, 2012 17:43
Get a YouTube Video ID from a Url
# Parses a URL of a YouTube video and
# returns the video id.
#
# - url - the url of the video
#
youtube_url_parser = (url) ->
regex = ///^
.* # Zero or more of any character
( # Group 1, either:
@Radagaisus
Radagaisus / css.css
Last active August 18, 2021 10:44
Gauges
.cpt-rank-stats .cpt-rank-right-circle {
background: #bebebe;
height: 90px;
width : 45px;
border-radius: 0 90px 90x 0;
margin-left: -4px;
overflow: hidden;
vertical-align: top;