Skip to content

Instantly share code, notes, and snippets.

@ahamid
ahamid / gist:715653
Created November 25, 2010 17:15
Conditional layout with devise
class ApplicationController < ActionController::Base
layout :layout_by_resource
# choose different layout for devise
def layout_by_resource
if devise_controller?
"users"
else
"application"
@ahamid
ahamid / bootstrap-drupal-quercus.sh
Created January 24, 2011 07:30
Bootstrap Drupal 6.20 on Quercus
#!/bin/sh
DRUSH_TGZ=drush-All-versions-4.1.tar.gz
RESIN_TGZ=resin-4.0.14.tar.gz
MYSQL_DRIVER_TGZ=mysql-connector-java-5.1.14.tar.gz
function msg {
echo
echo -e "\033[31m $1 \033[39m"
@ahamid
ahamid / Rakefile
Created February 26, 2011 03:50
Variable visibility in Rakefile method
target=ENV['TARGET'] || "whatever"
def helpful_helper(a)
# do something extremely helpful
puts "Visible? #{target}"
end
task :default do
puts "My target is #{target}"
helpful_helper("yo")
@ahamid
ahamid / ImageUploader
Created May 27, 2011 16:51
CarrierWave mixed content upload processing
require 'carrierwave/processing/mini_magick'
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
IMAGE_EXTENSIONS = %w(jpg jpeg gif png)
DOCUMENT_EXTENSIONS = %w(exe pdf doc docm xls)
def store_dir
"files/#{model.id}"
@ahamid
ahamid / gist:1019897
Created June 10, 2011 22:13
Monad in Java
// Created on Feb 7, 2009
package snippet;
import java.math.BigDecimal;
public class Monad {
// this is our "side effect" ("amplified object")
public static class AnnotatedObject<T> {
public T o;
@ahamid
ahamid / gist:1129651
Created August 6, 2011 19:14
BinData + Veritas
class BinDataRelation < Veritas::Relation
def initialize(klass, io)
super([[:index, Integer]] + BinDataRelation.veritas_fields(klass), BinDataRelation.record_enumerator(klass, io))
end
protected
def self.veritas_fields(klass)
veritas_fields = []
for field in klass.fields
/**
* Allows for calling a method asynchronously and queueing pending callbacks to avoid
* race conditions.
*
* Example:
*
* function createUniverse(arg, callback) {
* // important stuff that should not run in parallel here
* callback(whatever);
* }
@ahamid
ahamid / gist:1380816
Created November 20, 2011 20:11
Rock segfaulting
https://github.com/ahamid/semblance/tree/break-rock
+ rm -r .libs rock_tmp
+ rock -lelf -v -m64 -Isrc -o=semblance src/semblance.ooc src/CallingConvention.ooc src/CodeSection.ooc src/DataSource.ooc src/Datum.ooc src/elf.ooc src/FakeISA.ooc src/Instruction.ooc src/ISA.ooc src/ISARegistry.ooc src/Parser.ooc src/ProgramObject.ooc src/semblance.ooc src/SimpleParser.ooc src/Statement.ooc
./make: line 5: 9359 Segmentation fault (core dumped) rock -lelf -v -m64 -Isrc -o=semblance src/semblance.ooc src/*.ooc
@ahamid
ahamid / art.rb
Created November 28, 2011 07:38 — forked from duckinator/art.rb
#!/usr/bin/env ruby
i=0.0
loop do
print " " * (padding + (Math.sin(i) * 5)),
"Art and technology do coexist, if you let them\n\n"
i += 0.1
sleep 0.03
end
@ahamid
ahamid / gist:1432255
Created December 5, 2011 04:07
CMake linker flags
cmake_minimum_required (VERSION 2.6)
set(FILL_UTIL "${PROJECT_SOURCE_DIR}/utils/fill")
set(SIZE_UTIL "${PROJECT_SOURCE_DIR}/arch/i386/size.sh")
set(cpu_objects main.c task.c pgrequest.c descriptor.c thread.c tss.c interrupt.c paging.c memory.c caps.c permissions.c ttrace.c)
set(prt_objects print.c)
set(assembly_src cpu-asm.s arch/i386/kernel/int.s arch/i386/kernel/pic.s arch/i386/kernel/stack_winding.s arch/i386/kernel/state_switch.s arch/i386/kernel/syscall-gates.s arch/i386/kernel/vga.s)
#add_custom_command(OUTPUT assembly.o COMMAND ${AS} ${AS_FLAGS} -o assembly.o ${assembly_src})