Skip to content

Instantly share code, notes, and snippets.

View bcambel's full-sized avatar
🌴
On vacation

Bahadir Cambel bcambel

🌴
On vacation
View GitHub Profile
1. pip install -r reqs.pip
2. server.py
3. open client.html in browser
4. redis-cli publish push '123456'
5. check browser console
@bcambel
bcambel / nginx.conf
Created August 16, 2013 06:57
Nginx maintenance redirect when a specific file exists
server {
listen 80;
server_name mysite.com;
root /var/www/mysite.com/;
location / {
if (-f $document_root/maintenance.html) {
return 503;
}
... # the rest of your config goes here
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com
smtpuser = pavan.sss1991@gmail.com
(def requirements_file "requirements.txt")
(use 'clojure.java.io)
(use '[clojure.string :only (join split)])
(slurp requirements_file)
(defn process-line [line]
(let [single-line (split line #"==")
result (into '() single-line)]
(reverse result)))
user> (defn c [p]
(with-open [rdr (clojure.java.io/reader p)]
(reduce + (map count (line-seq rdr)))))
#'user/c
user> (bench/quick-bench
(c "/tmp/test"))
WARNING: Final GC required 356.7754050400232 % of runtime
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 525.040480 ms
Execution time std-deviation : 29.017225 ms
(def open-for-business? (atom true))
(def haircut-count (agent 0))
(def waiting-room (ref []))
(def waiting-room-size 3)
(defn open-shop [duration]
(do (Thread/sleep duration) (swap! open-for-business? not)))
(defn add-customers []
(future
@bcambel
bcambel / vectors.clj
Created November 20, 2013 10:21
Playing with Sequentials vectors to be more specific
;; Anything you type in here will be executed
;; immediately with the results shown on the
;; right.
(first [1 2 3])
(rest [1 2 3])
(nth [1 2 3] 2)
(conj [1] [1 2 3])
(cons '(1) [1 2 3])
(cons [1] [1 2 3])
(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]
@bcambel
bcambel / charbox.html
Created December 1, 2013 08:03
Chatbox
<div class="container">
<div class="row">
<div class="col-md-5">
<div class="panel panel-primary">
<div class="panel-heading">
<span class="glyphicon glyphicon-comment"></span> Chat
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-chevron-down"></span>
</button>
@bcambel
bcambel / login.css
Created December 1, 2013 08:05
loginbox
body {
background: url(http://lorempixel.com/1920/1920/city/9/) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.panel-default {
opacity: 0.9;