Skip to content

Instantly share code, notes, and snippets.

@mcihad
mcihad / Prime.cs
Created March 24, 2019 16:32
C# prime generator
class Prime
{
static bool IsPrime(int num)
{
int to = (int)Math.Round(Math.Sqrt(num));
return !Enumerable.Range(2, to).Any(i => num % i == 0);
}
public static IEnumerable<int> GetPrimes(int count)
{
int current = 2;
@mcihad
mcihad / fibo_prime.py
Created March 14, 2019 12:49
Çeşitli
import math
#verilen aralığa kadar asal sayıları bul ve liste olarak geri döndür find_primes(100)
find_primes = lambda j: list(filter(lambda x: not any([i for i in range(2, int(round(math.sqrt(x))) + 1) if x % i == 0]), list(range(2, j + 1))))
#fibonacci jeneratörü
def fibonacci(to):
a, b = 1, 1
count = 1
while (count < to):
@mcihad
mcihad / pointer.cpp
Created November 2, 2018 17:26
Pointer denemesi
#include <iostream>
using namespace std;
int main() {
int* a;
int* b;
int c=12;
a=&c;
@mcihad
mcihad / GenericTypeParameter.java
Created October 28, 2018 18:40
Generic Parameter Type
Type type = this.getClass().getGenericSuperclass();
ParameterizedType pt = (ParameterizedType) type;
Class c = (Class)pt.getActualTypeArguments()[0];
System.out.println(c.getSimpleName());
@mcihad
mcihad / decorators.py
Last active September 5, 2018 20:29
spring hasAnyRole or RolesAllowed annotation implementation for django
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied
def has_any_role(roles, login_url=None, raise_exception=False):
def check_role(user):
if isinstance(roles, list):
perms = roles
@mcihad
mcihad / main.go
Created September 4, 2018 19:35
Check standart django password in go language
package main
import (
"crypto/sha256"
"encoding/base64"
"fmt"
"golang.org/x/crypto/pbkdf2"
"strconv"
"strings"
)
@mcihad
mcihad / createdb
Created September 2, 2018 13:11
Postgresql Database Collate
create database <dbname> with LC_COLLATE='tr_TR.UTF-8' LC_CTYPE='tr_TR.UTF-8' template=template0 owner='<owner>'
@mcihad
mcihad / strjoin.py
Created August 29, 2018 19:04
Python String Birleştirme
def f1(n):
import time
start=time.time()
a = ["Hi there "]
for i in range(n):
a.append(f"({i},{i}),")
s="".join(a)
end=time.time()
print(f"{n} adet deneme -> {end-start}")
return s
@mcihad
mcihad / strjoin.go
Created August 29, 2018 19:03
Go String Birleştirme Testi
package main
import (
"bytes"
"fmt"
"strconv"
"strings"
"time"
)
@mcihad
mcihad / app.py
Created September 17, 2017 19:28
N11 CityService Kullanımı
from flask import Flask, render_template
from suds.client import Client
app = Flask(__name__)
class CityService(object):
__cities = []
__loaded = False
__wsdl = "https://api.n11.com/ws/CityService.wsdl"