Skip to content

Instantly share code, notes, and snippets.

View haldun's full-sized avatar

Haldun Bayhantopcu haldun

  • Berlin, Germany
View GitHub Profile
@haldun
haldun / gist:997752
Created May 29, 2011 12:48
Controller template for decent exposure
# mkdir -p lib/templates/rails/scaffold_controller/
# Put this under lib/templates/rails/scaffold_controller/controller.rb
class <%= controller_class_name %>Controller < ApplicationController
respond_to :html, :json
<% unless options[:singleton] -%>
expose(:<%= table_name %>) { <%= orm_class.all(class_name) %> }
<% end -%>
expose(:<%= file_name %>)
@haldun
haldun / application_controller.rb
Created October 11, 2011 19:28
rails auth scaffold
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user
def current_user
@current_user ||= User.find_by_auth_token(cookies.signed[:auth_token]) if cookies[:auth_token]
end
def authenticate_user!
redirect_to login_url unless current_user
@haldun
haldun / infixeval.cpp
Created December 1, 2011 15:21
infix evaluator in c++
/*
* Infix evaluator in C++.
* Haldun Bayhantopcu <hb@haldun.me> 10976008
*
* Usage: echo <expr> | ./infixeval
* Example: echo "((8+9)*(4-6)^4)" | ./infixeval
* Output: 272
*/
#include <cmath>
#include <iostream>
@adharris
adharris / postgres_array.go
Created November 28, 2012 19:52
PostgreSQL demo of Array types using Golang
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"
anonymous
anonymous / concerning.rb
Created December 18, 2012 18:00
class Module
# We often find ourselves with a medium-sized chunk of behavior that we'd
# like to extract, but only mix in to a single class.
#
# We typically choose to leave the implementation directly in the class,
# perhaps with a comment, because the mental and visual overhead of defining
# a module, making it a Concern, and including it is just too great.
#
#
# Using comments as lightweight modularity:
@haldun
haldun / MNDDataModel.m
Created October 24, 2013 09:29
Core data common setup code
//
// MNDDataModel.m
// Podcasts
//
// Created by Haldun Bayhantopcu on 24/10/13.
// Copyright (c) 2013 monoid. All rights reserved.
//
#import "MNDDataModel.h"
@haldun
haldun / gist:7437770
Created November 12, 2013 20:09
BLog function for ObjectiveC
#define BLog(formatString, ...) NSLog((@"%s " formatString), __PRETTY_FUNCTION__, ##__VA_ARGS__);
package main
import (
"fmt"
"log"
"net/http"
"html/template"
"github.com/gorilla/sessions"
@wancw
wancw / y-combinator.go
Last active September 19, 2023 20:22
Y combinator in Go, runable example: http://play.golang.org/p/xVHw0zoaWX
package main
import "fmt"
type (
tF func(int) int
tRF func(tF) tF
tX func(tX) tF
)