Skip to content

Instantly share code, notes, and snippets.

@aturgarg
aturgarg / create_directory_structure.rb
Created June 4, 2011 08:22
To create a directory structure
require "fileutils"
#
files = ["foo/bar/blah.rb","foo/bar/stuff.rb","foo/bar/example/thing.rb","foo/ham/example"]
#create the directory structure based above array in current directory
FileUtils.makedirs( files.map{ |f| f }.uniq.reject{ |d|
File::exist?(d) } )
@aturgarg
aturgarg / path_remove_bash.sh
Created June 4, 2011 09:46
remove a path from bash
$ PATH=$(echo $PATH | sed -e 's;:\?/home/user/bin;;' -e 's;/home/user/bin:\?;;')
@aturgarg
aturgarg / git_commits_log.rb
Created June 4, 2011 11:33
Get git commits via ruby
require 'rubygems'
require 'grit'
include Grit
#directory /home/rubytest/grit/grit contains .git file
#directory path should contain .git else it give invalidGitRepository error
repo = Repo.new("/home/rubytest/grit/grit")
#print git commits
print repo.commits
head = repo.commits.first
@aturgarg
aturgarg / GenGuid.bat
Created June 27, 2011 06:33
Generate Guid
> GuidGen
REM to register assembly
> regasm test.dll
@aturgarg
aturgarg / RegisterExeorDll.bat
Created June 27, 2011 14:27
Register an exe or dll
%windir%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe /unregister Test.exe /codebase
%windir%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe Test.exe /tlb:Test.tlb /codebase
pause
@aturgarg
aturgarg / ExeConfigDynamic.cs
Created June 27, 2011 14:29
Get EXE config data dynamically
private static string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();
if (!string.IsNullOrEmpty(servicePath))
{
Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);
//here fetching the data from AppSettings with key name "UserName"
string userName = config.AppSettings.Settings["UserName"].Value.ToString();
}
@aturgarg
aturgarg / oracle_dataspace_used_owners.sql
Created June 28, 2011 07:32
Get Data space used in oracle by various users(owners)
select owner,sum(bytes)/1024/1024 mb from dba_segments
group by owner;
@aturgarg
aturgarg / oracle_tableSpace_info.sql
Created June 28, 2011 07:33
oracle tableSpace and its info
SELECT df.tablespace_name tsname,df.autoextensible,
sum(df.bytes)/1024/1024 tbs_size_mb
, nvl(sum(e.used_bytes)/1024/1024,0) used, nvl(sum(f.free_bytes)/1024/1024,0) avail
, rpad(' '||rpad('X',round(sum(e.used_bytes)*10/sum(df.bytes),0), 'X'),11,'-') used_visual, nvl((sum(e.used_bytes)*100)/sum(df.bytes),0) pct_used
FROM sys.dba_data_files df
, (SELECT file_id, sum(nvl(bytes,0)) used_bytes
FROM sys.dba_extents
GROUP BY file_id) e
, (SELECT max(bytes) free_bytes, file_id
FROM dba_free_space
@aturgarg
aturgarg / truncate_tables_with_constraints.sql
Created July 6, 2011 06:58
truncating all tables in DB with foriegn key constraints
--http://stackoverflow.com/questions/155246/how-do-you-truncate-all-tables-in-a-database-using-tsql
--When dealing with deleting data from tables which have foreign key relationships - which is basically the -----case with any properly designed database - we can disable all the constraints, delete all the data and then ---re-enable constraints
-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
-- delete data in all tables
EXEC sp_MSForEachTable "DELETE FROM ?"
@aturgarg
aturgarg / delegate_example_basic.cs
Created July 7, 2011 15:43
delegate usage example (basic)
//Example of delegate
//Example in EventHandler (delegate)
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;