Skip to content

Instantly share code, notes, and snippets.

View cemremengu's full-sized avatar
😵

Cemre Mengu cemremengu

😵
View GitHub Profile
@cemremengu
cemremengu / OracleWrapper.py
Last active September 26, 2015 18:19
cx_Oracle Wrapper
import cx_Oracle
class OracleWrapper(object):
"""
A class for handling db operations
"""
def __init__(self, constring):
self.constring = constring.strip()
self.db_connection = cx_Oracle.connect(constring)
@cemremengu
cemremengu / read_subprocess_stdout.py
Created February 14, 2012 22:53
Again a stack overflow answer for reading the stdout of a subprocess in python
import subprocess
p = subprocess.Popen(["ntpq", "-p"], stdout=subprocess.PIPE) # ["command", "arg1", "arg2", "so on"]
out, err = p.communicate()
#you can then use out.split("\n") to get outputs as a list
@cemremengu
cemremengu / GenericFactory.cs
Last active December 14, 2015 10:19
A factory class that uses generics
// Example usage: Apple myAppleVar = Fruit<Apple>.CreateInstance();
// ref: http://stackoverflow.com/questions/1380087/whats-the-correct-alternative-to-static-method-inheritance-c
public abstract class Fruit<T>
where T : Fruit<T>, new()
{
public static T CreateInstance()
{
T newFruit = new T();
newFruit.Initialize(); // Calls Apple.Initialize
@cemremengu
cemremengu / encode_unicode.py
Last active December 14, 2015 18:59
As seen in: http://stackoverflow.com/questions/1207457/convert-unicode-to-string-in-python-containing-extra-symbols Use this coode snippet example to encode special characters to string in python
title = u"Klüft skräms inför på fédéral électoral große"
import unicodedata
unicodedata.normalize('NFKD', title).encode('ascii','ignore')
'Kluft skrams infor pa federal electoral groe'
@cemremengu
cemremengu / count_lines_in_file.ps1
Created December 22, 2016 12:32
powershell script for counting the lines of a large file
$YOURFILE = "example.txt";
$nlines = 0;
#read file by 1000 lines at a time
gc $YOURFILE -read 1000 | % { $nlines += $_.Length };
[string]::Format("{0} has {1} lines", $YOURFILE, $nlines)
@cemremengu
cemremengu / OracleDynamicParameters.cs
Created April 28, 2017 00:10 — forked from vijayganeshpk/OracleDynamicParameters.cs
OracleDynamicParameters class for Dapper
using Dapper;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
public class OracleDynamicParameters : Dapper.SqlMapper.IDynamicParameters {
private static Dictionary<SqlMapper.Identity, Action<IDbCommand, object>> paramReaderCache = new Dictionary<SqlMapper.Identity, Action<IDbCommand, object>>( );
@cemremengu
cemremengu / bulk_processor_example1.go
Created February 9, 2018 19:28 — forked from olivere/bulk_processor_example1.go
Example #1 of bulk processor usage
// This is an example of using elastic's BulkProcessor with Elasticsearch.
//
// See https://github.com/olivere/elastic and
// and https://github.com/olivere/elastic/wiki/BulkProcessor
// for more details.
/*
* This example illustrates a simple process that performs bulk processing
* with Elasticsearch using the BulkProcessor in elastic.
*
// true-type-of.js
export const trueTypeOf = input => Object.prototype.toString.call(input)
.replace(/(\[object |\])/ig, '')
.toLowerCase();
import Papa from 'papaparse';
import { saveAs } from 'file-saver/FileSaver';
export default async ({ payload, filename }) => {
saveAs(
new Blob([Papa.unparse(payload)], { type: 'text/plain;charset=utf-8' }),
`${filename}.csv`
);
};
REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\CredSSP\Parameters\ /v AllowEncryptionOracle /t REG_DWORD /d 2