Skip to content

Instantly share code, notes, and snippets.

View muratcorlu's full-sized avatar

Murat Çorlu muratcorlu

View GitHub Profile
@muratcorlu
muratcorlu / ng-translate.js
Created February 18, 2014 23:55
Translation directive for AngularJS
/**
* @ngdoc directive
* @name ng.directive:translate
*
* @element ANY
*
* @description
*
* Angular icin ceviri directive'i
*
@muratcorlu
muratcorlu / ng-masked-input.js
Created February 18, 2014 23:58
Masked Input Directive trying for AngularJS (It's not working)
/**
* 0 User must enter a digit (0 to 9).
* 9 User can enter a digit (0 to 9).
* # User can enter a digit, space, plus or minus sign. If skipped, enters a blank space.
* L User must enter a letter.
* ? User can enter a letter.
* A User must enter a letter or a digit.
* a User can enter a letter or a digit.
* & User must enter either a character or a space.
* C User can enter characters or spaces.
@muratcorlu
muratcorlu / ng-checkbox-all.js
Created February 19, 2014 00:00
A checkbox directive that selects/deselects all records that given for AngularJS
/**
* @ngdoc directive
* @name safe.directive:checkboxAll
*
* @element input
*
* @description
*
* Bir listedeki tüm elemanları seçen bir checkbox kutusu yapmak için pratik bir directive.
*
@muratcorlu
muratcorlu / ng-incomplete-confirmation.js
Created February 19, 2014 00:03
Sayfada yarım kalmış bir form varken sayfadan çıkılmak istendiğinde uyarı vermeye yarayan AngularJS directive'i
/**
* @ngdoc directive
* @name safe.directive:incomplete-confirmation
*
* @element ANY
*
* @description
*
* `name` attribute'u olan bütün form elementlerinde çalışarak
* üzerinde değişiklik yapılmış ancak kaydedilmemiş bir form olduğunda
@muratcorlu
muratcorlu / similarity_score.py
Created April 6, 2014 18:15
Get similarity score of two words with python
def get_score(word1, word2):
shared_chars = [char for char in word1.lower() if char in word2.lower()]
return len(shared_chars)
# Usage
get_score('murat', 'burak')
# > 3
@muratcorlu
muratcorlu / restview.py
Created December 24, 2014 00:38
Simple Django RestView view class
from django.http import HttpResponse, JsonResponse, HttpResponseForbidden, HttpResponseNotAllowed, HttpResponseNotFound
from django.forms.models import model_to_dict
from django.db.models import Model
from django.db.models.query import QuerySet
from functools import wraps
from django.utils.decorators import available_attrs
from django.core import serializers
class PermissionError(Exception):
pass
{
init: function(elevators, floors) {
var upWaiters = {},
downWaiters = {},
idleElevators = [],
floorCount = floors.length,
arrayUnique = function(a) {
return a.reduce(function(p, c) {
if (p.indexOf(c) < 0) p.push(c);
return p;
@muratcorlu
muratcorlu / tabmenu.css
Created September 29, 2010 11:34
A simple tabmenu implementation with jQuery
div.tabcontent {
display:none;
}
div.active {
display:block;
}
@muratcorlu
muratcorlu / jsonencode.php
Created September 29, 2010 13:33
JSON Encoder
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="tr" lang="tr">
<head>
<title> JSON Encoder </title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<?php
if($_POST) {
$unicodes = array('\u015f', '\u015e', '\u011f', '\u011e', '\u0130', '\u0131', '\u00fc', '\u00dc', '\u00d6', '\u00f6', '\u00c7', '\u00e7');
@muratcorlu
muratcorlu / simpletimer.js
Created October 10, 2010 03:24
Simple timer with javascript
var timer = {
started: 0,
end: 0,
now: function(){ return new Date(); },
start: function(){ return this.started = this.now(); },
since: function(){ this.end = this.now(); return this.now()-this.started; }
}
// Usage: