Skip to content

Instantly share code, notes, and snippets.

@Hamdiakoguz
Hamdiakoguz / isDirty.cs
Last active June 28, 2016 22:13
nhibernate dirty properties
public static Boolean IsDirtyProperty(this ISession session, Object entity, String propertyName)
{
ISessionImplementor sessionImpl = session.GetSessionImplementation();
IPersistenceContext persistenceContext = sessionImpl.PersistenceContext;
EntityEntry oldEntry = persistenceContext.GetEntry(entity);
String className = oldEntry.EntityName;
IEntityPersister persister = sessionImpl.Factory.GetEntityPersister(className);
if ((oldEntry == null) && (entity is INHibernateProxy))
@Hamdiakoguz
Hamdiakoguz / advisory_lock.rb
Created January 6, 2016 15:13
untested pg advisory lock class for distributed process level locking
# untested pg advisory lock class for distributed process level locking
# AdvisoryLock.exclusive("some_key") do
# important work here
# end
require 'zlib'
class AdvisoryLock
def self.exclusive(name, &block)
raise ArgumentError, "Method expects a block" unless block_given?
@Hamdiakoguz
Hamdiakoguz / theaters-ckmeans.rb
Last active October 14, 2015 10:39
Türkiyenin illere göre tiyatro salonları sayıları. ckmeans.1d.dp ile sınıflandırılmış.
theaters = {"Adana" => 11, "Adıyaman" => 2, "Afyonkarahisar" => 4, "Aksaray" => 4, "Amasya" => 2, "Ankara" => 36, "Antalya" => 10, "Ardahan" => 2, "Artvin" => 5, "Aydın" => 9, "Ağrı" => 1, "Balıkesir" => 22, "Bartın" => 6, "Batman" => 3, "Bayburt" => 1, "Bilecik" => 0, "Bingöl" => 3, "Bitlis" => 6, "Bolu" => 2, "Burdur" => 2, "Bursa" => 16, "Denizli" => 8, "Diyarbakır" => 4, "Düzce" => 2, "Edirne" => 3, "Elazığ" => 10, "Erzincan" => 1, "Erzurum" => 4, "Eskişehir" => 12, "Gaziantep" => 2, "Giresun" => 6, "Gümüşhane" => 2, "Hakkari" => 1, "Hatay" => 9, "Isparta" => 3, "Iğdır" => 2, "Kahramanmaraş" => 9, "Karabük" => 3, "Karaman" => 2, "Kars" => 2, "Kastamonu" => 3, "Kayseri" => 10, "Kilis" => 1, "Kocaeli" => 9, "Konya" => 5, "Kütahya" => 3, "Kırklareli" => 2, "Kırıkkale" => 1, "Kırşehir" => 5, "Malatya" => 13, "Manisa" => 7, "Mardin" => 5, "Mersin" => 13, "Muğla" => 7, "Muş" => 4, "Nevşehir" => 5, "Niğde" => 2, "Ordu" => 7, "Osmaniye" => 3, "Rize" => 4, "Sakarya" => 9, "Samsun" => 8, "Siirt" => 3, "Sinop" => 6,
@Hamdiakoguz
Hamdiakoguz / theaters-jenks.rb
Last active October 14, 2015 10:40
Türkiyenin illere göre tiyatro salonları sayıları. jenks ile sınıflandırılmış.
theaters = {"Adana" => 11, "Adıyaman" => 2, "Afyonkarahisar" => 4, "Aksaray" => 4, "Amasya" => 2, "Ankara" => 36, "Antalya" => 10, "Ardahan" => 2, "Artvin" => 5, "Aydın" => 9, "Ağrı" => 1, "Balıkesir" => 22, "Bartın" => 6, "Batman" => 3, "Bayburt" => 1, "Bilecik" => 0, "Bingöl" => 3, "Bitlis" => 6, "Bolu" => 2, "Burdur" => 2, "Bursa" => 16, "Denizli" => 8, "Diyarbakır" => 4, "Düzce" => 2, "Edirne" => 3, "Elazığ" => 10, "Erzincan" => 1, "Erzurum" => 4, "Eskişehir" => 12, "Gaziantep" => 2, "Giresun" => 6, "Gümüşhane" => 2, "Hakkari" => 1, "Hatay" => 9, "Isparta" => 3, "Iğdır" => 2, "Kahramanmaraş" => 9, "Karabük" => 3, "Karaman" => 2, "Kars" => 2, "Kastamonu" => 3, "Kayseri" => 10, "Kilis" => 1, "Kocaeli" => 9, "Konya" => 5, "Kütahya" => 3, "Kırklareli" => 2, "Kırıkkale" => 1, "Kırşehir" => 5, "Malatya" => 13, "Manisa" => 7, "Mardin" => 5, "Mersin" => 13, "Muğla" => 7, "Muş" => 4, "Nevşehir" => 5, "Niğde" => 2, "Ordu" => 7, "Osmaniye" => 3, "Rize" => 4, "Sakarya" => 9, "Samsun" => 8, "Siirt" => 3, "Sinop" => 6,
@Hamdiakoguz
Hamdiakoguz / gogo.rb
Created October 4, 2015 21:06 — forked from mboeh/gogo.rb
thread and GC nuance
# Summary: In MRI 1.9, if you keep threads in an array in a local variable, the threads may outlive the local variable.
# I have not yet been able to produce a scenario in which the threads are ever garbage-collected.
# You have to remove the thread from the array before it goes out of scope, e.g. using #pop or #clear.
# INPUT DESIRED: If anyone can demonstrate a condition in which a local array keeps threads and those threads are eventually GC'd.
# INPUT DESIRED: Is this expected behavior or a bug?
# NOTE: This test will not work as expected in JRuby, because its garbage collection works differently. Whether the same behavior exists in JRuby is an exercise for someone smarter than I am.
class Foo
THREAD_PROC = lambda{ (0..10).to_a.map do Foo.new end }
@Hamdiakoguz
Hamdiakoguz / gist:c051383e475d6efdaa94
Created August 16, 2014 21:18
powershell install fonts
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace(0x14)
$Fonts = Get-ChildItem -Recurse -Include *.ttf,*.otf
foreach($File in $Fonts) {
$objFolder.CopyHere($File.fullname)
}
@Hamdiakoguz
Hamdiakoguz / CassandraAquilesTest.cs
Created May 28, 2014 10:00
CassandraAquilesTest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Apache.Cassandra;
using Aquiles.Cassandra10;
using Aquiles.Core.Cluster;
using Aquiles.Helpers;
using Aquiles.Helpers.Encoders;
@Hamdiakoguz
Hamdiakoguz / FluentCassandra.cs
Created May 28, 2014 09:59
FluentCassandra tryout
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using FluentCassandra;
using FluentCassandra.Apache.Cassandra;
using FluentCassandra.Connections;
using FluentCassandra.Linq;
using FluentCassandra.Types;
using NUnit.Framework;
@Hamdiakoguz
Hamdiakoguz / mysql.ps1
Created May 25, 2014 05:25
powershell mysql
function exec-query($query) {
$ConnectionString = "Server=localhost;Database=db;Username=root;Password=pass;"
Try {
[void][System.Reflection.Assembly]::LoadFrom("../packages/MySql.Data.6.3.6/lib/MySql.Data.dll")
$Connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$Connection.ConnectionString = $ConnectionString
$Connection.Open()
Write-Host "executing query: ", $query
var countries = {
'af' : 'Afganistan',
'de' : 'Almanya',
'ad' : 'Andorra',
'ao' : 'Angola',
'ag' : 'Antigua ve Barbuda',
'ar' : 'Arjantin',
'al' : 'Arnavutluk',
'aw' : 'Aruba',
'au' : 'Avustralya',