Skip to content

Instantly share code, notes, and snippets.

View dhilipsiva's full-sized avatar
🏠
Working from home

dhilipsiva dhilipsiva

🏠
Working from home
View GitHub Profile
@dhilipsiva
dhilipsiva / PrintWithoutPrintf.C
Created May 16, 2012 04:15
C program printing without using "printf". NO libraries. just c and memory ;)
//Created by DhilipSiva
//Free to modify and use
main()
{
char far *videoMemory = 0xB8000000;
char *helloString = "Hello World";
int stringLength = 11; //length of "Hello World" is 11
int count;
for(count = 0; count < stringLength; count++)
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@dhilipsiva
dhilipsiva / UIInterfaceOrientationMask.h
Created July 25, 2012 12:49
iOS 6 UI interface Orientation - shouldAutorotateToInterfaceOrientation: Not working
typedef enum {
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
UIInterfaceOrientationMaskLandscape =
(UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
UIInterfaceOrientationMaskAll =
(UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
@dhilipsiva
dhilipsiva / shouldAutorotateToInterfaceOrientation.m
Created July 25, 2012 12:58
iOS 6 UI interface Orientation - shouldAutorotateToInterfaceOrientation: Not working
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
@dhilipsiva
dhilipsiva / supportedInterfaceOrientations.m
Created July 25, 2012 13:01
iOS 6 UI interface Orientation - shouldAutorotateToInterfaceOrientation: Not working
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
@dhilipsiva
dhilipsiva / CopyFromLibraryToApp.m
Created August 9, 2012 15:07
Code to Copy from iPod Library to App's Directory
//Implement this in the MPMediaPickerControllerDelegate
-(void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection{
NSString *tempPath = NSTemporaryDirectory();
int i=1;
for (MPMediaItem *theItem in mediaItemCollection.items) {
NSURL *url = [theItem valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset: songAsset presetName: AVAssetExportPresetPassthrough];
exporter.outputFileType = @"com.apple.coreaudio-format";
- (void)viewDidLoad {
[super viewDidLoad];
[self setSession:[[AVCaptureSession alloc] init]];
[_session setSessionPreset:AVCaptureSessionPresetHigh];
[self setViewLayer:self.vPreview.layer];
[self setCaptureVideoPreviewLayer:[[AVCaptureVideoPreviewLayer alloc] initWithSession:_session]];
[_captureVideoPreviewLayer setFrame:[_vPreview bounds]];
@dhilipsiva
dhilipsiva / observerpattern.py
Created August 12, 2012 17:21
Python Observer Pattern
class Foo(object):
def __init__(self):
self._bar_observers = []
def add_bar_observer(self, observer):
self._bar_observers.append(observer)
def notify_bar(self, param):
for observer in self._bar_observers:
observer(param)
@dhilipsiva
dhilipsiva / InstallDiaspora.sh
Created August 22, 2012 19:13
Diaspora install
curl -L get.rvm.io | bash -s stable --auto
sudo apt-get install build-essential libxslt1.1 libxslt1-dev libxml2 ruby-full mysql-server libmysqlclient-dev libmysql-ruby libssl-dev libopenssl-ruby libcurl4-openssl-dev imagemagick libmagickwand-dev git-core redis-server libffi-dev libffi-ruby rubygems libsqlite3-dev libpq-dev libreadline5 openjdk-7-jre nodejs
sudo apt-get install ruby-rvm
rvm gemset create 'global'
rvm install ruby-1.8.7-p370
rvm use ruby-1.8.7-p370@global
sudo service mysql start
gem install bundler --no-ri --no-rdoc
sudo ln -s /var/lib/gems/1.8/bin/bundle /usr/local/bin/bundle
@dhilipsiva
dhilipsiva / TraceDecorator.py
Created August 22, 2012 19:34
Tracing Python decorator
import sys
from functools import wraps
class TraceCalls(object):
""" Use as a decorator on functions that should be traced. Several
functions can be decorated - they will all be indented according
to their call depth.
"""
def __init__(self, stream=sys.stdout, indent_step=2, show_ret=False):
self.stream = stream