Skip to content

Instantly share code, notes, and snippets.

View caglartoklu's full-sized avatar

Çağlar Toklu caglartoklu

View GitHub Profile
@caglartoklu
caglartoklu / list_concatenation.cs
Last active August 29, 2015 14:25
C# List Concatenation #cs #list
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
List<string> listed = new List<string>() {"1", "2", "3", "4"};
Console.WriteLine(">" + string.Join("-", listed));
// >1-2-3-4
@caglartoklu
caglartoklu / string_interpolation.cs
Last active August 29, 2015 14:25
C# String Interpolation #cs #string
using System;
public class Program
{
public static void Main()
{
// simple string interpolation
string someString = @"
Do you have a {0} {1} ?
";
@caglartoklu
caglartoklu / custom_exception_class.cs
Created July 19, 2015 11:04
Custom Exception Class #cs #exception
namespace SomeNamespace
{
using System;
class CustomException : Exception
{
public CustomException()
: base() { }
public CustomException(string message)
@caglartoklu
caglartoklu / single_function_logging.py
Created November 22, 2015 15:55
Single function #logging #python
def get_logger():
"""
Returns a logger object that can directly be used.
It is a single function singleton,
it returns the same object each time it is called.
Do not forget to change:
logger_name = "defaultlogger"
logger_file_path = "log1.log"
@caglartoklu
caglartoklu / where_is_site_packages.sh
Last active December 12, 2015 06:29
Displays the location of the directory "site-packages" of Python.Run it from shell(bash or cmd.exe), not from the Python interpreter itself. #python #shell #path
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
@caglartoklu
caglartoklu / shell_version.sh
Created February 7, 2013 09:48
shell version #shell
`echo $SHELL` --version
@caglartoklu
caglartoklu / rhel_version.sh
Created February 7, 2013 09:40
Find out Red Hat Linux version #redhat #linux #shell
uname -a
cat /etc/redhat-release
@caglartoklu
caglartoklu / encoding.py
Last active December 12, 2015 06:29
Python source encoding.Add the code to the top of your source file. #python #encoding
# -*- coding: utf8 -*-
# http://www.python.org/dev/peps/pep-0263/
@caglartoklu
caglartoklu / is_ironpython.py
Created February 7, 2013 09:49
If the platform is IronPython, this function returns True, False otherwise. #python #ironpython
import sys
def is_ironpython():
"""
If the platform is IronPython, this function returns True, False otherwise.
"""
result = False
if sys.platform == "cli":
result = True
return result
@caglartoklu
caglartoklu / module_path.py
Last active December 12, 2015 06:29
Displays the current module name and its path. #python #path
# http://docs.python.org/reference/datamodel.html?highlight=__file__
# Current module name
print __file__
# module1.py
# Path of the current module
import os
print os.path.abspath(os.path.dirname(__file__))
# /home/myusername/projects/project1