Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
mizanRahman / EventEmitter
Created October 30, 2012 12:19
Play with node.js events. Make your own events.
var EventEmitter = require('events').EventEmitter;
var util = require('util');
// create the class
var MyClass = function () {}
util.inherits(MyClass, EventEmitter);
var obj = new MyClass();
//add the listeners
obj.on('myevent',function(){
console.log('my event emit');
@mizanRahman
mizanRahman / hello.js
Created October 30, 2012 12:32
how to use modules in a node.js applications
module.exports = {
english: function(){console.log('hello world');},
russian: function(){console.log('hola');},
bangla: function(){console.log('sagotom');}
}
@mizanRahman
mizanRahman / LoggerDemo.cs
Last active March 7, 2023 07:32
Logging with log4net. Colored Console Logging and File Logging demonstrated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
namespace LogForNetTest
{
@mizanRahman
mizanRahman / fetch_data.rb
Last active December 11, 2015 03:28
fetching data from Microsoft SQL Server with ruby using TinyTDS gem
require 'tiny_tds'
client = TinyTds::Client.new(:username => 'sa', :password => 'secret', :host => 'localhosts')
client.execute("use testdb").do
#following block gets all the table names of the database and prints name.
result = client.execute("SELECT * FROM sys.Tables")
result.each do |row|
p row['name']
end
@mizanRahman
mizanRahman / shortcuts
Created February 7, 2013 12:34
shortcuts sublime
Keypress Command
Ctrl + X Delete line
Ctrl + ↩ Insert line after
Ctrl + ⇧ + ↩ Insert line before
Ctrl + ⇧ + ↑ Move line/selection up
Ctrl + ⇧ + ↓ Move line/selection down
Ctrl + L Select line - Repeat to select next lines
Ctrl + D Select word - Repeat select others occurrences
Ctrl + M Jump to closing parentheses Repeat to jump to opening parentheses
Ctrl + ⇧ + M Select all contents of the current parentheses
@mizanRahman
mizanRahman / colorize_image.css
Created February 12, 2013 13:34
Cross browser CSS3 image gray-scale and colorize on hover.
body{
padding: 50px 10px;
}
img{
border: 10px solid #ccc;
box-shadow: 0px 0px 1px #555;
}
img.grayscale{
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
@mizanRahman
mizanRahman / EventLogLister.cs
Last active December 13, 2015 18:58
lists event logs from a specific source.
public void GetEventLog(string source)
{
EventLog el = new EventLog();
el.Source = source;
foreach (EventLogEntry item in el.Entries)
{
Console.WriteLine(item.Source+": "+item.Message);
}
@mizanRahman
mizanRahman / tail recursion
Last active December 15, 2015 22:49
Scala code snippets
package test
object TestSheet {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
def sum(a:Int,b:Int):Int = {
def sumF(acc:Int,a:Int,b:Int):Int = {
if(a>b) acc
else sumF(acc+a,a+1,b)
}
@mizanRahman
mizanRahman / serviceFromConsole.cs
Created April 23, 2013 08:48
running windows service from console
using System;
using System.ServiceProcess;
public class MyService : System.ServiceProcess.ServiceBase
{
static void Main(string[] args)
{
MyService service = new MyService();
if (Environment.UserInteractive)
@mizanRahman
mizanRahman / query.rb
Created April 24, 2013 13:15
working with sql server 2008 using ruby
require 'tiny_tds'
client = TinyTds::Client.new(:username => 'sa', :password => 'secret', :host => 'localhost')
client.execute("use testdb").do
result = client.execute("select * from person")
result.each do |row|
p row
end