Skip to content

Instantly share code, notes, and snippets.

View omerucel's full-sized avatar
🎯
Focusing

Ömer ÜCEL omerucel

🎯
Focusing
View GitHub Profile
@omerucel
omerucel / main.py
Created October 20, 2023 16:00
RFC 6238 TOTP: Time-Based One-Time Password Algorithm
"""
It is based on java implementation: https://datatracker.ietf.org/doc/html/rfc6238#appendix-A
"""
import datetime
import hashlib
import hmac
from typing import Callable
def main():
@omerucel
omerucel / gist:8617a3a02a35393c6fbb0803d6236650
Last active May 24, 2021 14:04 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<html>
<head>
<title>Site Maintenance</title>
<meta charset="UTF-8">
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
@omerucel
omerucel / index.js
Last active April 13, 2021 23:02
Create User - DynamoDB Example
const AWS = require("aws-sdk");
const dbClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});
exports.handler = async (event) => {
let params = JSON.parse(event.body);
await dbClient.put({
TableName: 'users',
Item: {
email: params.email,
name: params.name
@omerucel
omerucel / setup.sh
Created September 29, 2020 20:32
setup server
mkdir -p /data/projects
apt-get install -y apache2 php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-soap php-pear php-bcmath libapache2-mod-php software-properties-common certbot python3-certbot-apache zip unzip
a2enmod rewrite
systemctl restart apache2
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
mv composer.phar /usr/local/bin/composer
unlink composer-setup.php
{
"product_variants": [
{
"type": "Color",
"items": [
{
"id": "26a702b2",
"name": "Beyaz"
},
{
@omerucel
omerucel / Calculator.twig
Created September 29, 2019 18:44
Mortgage Calculator (incl. Down Payment)
{% set home_value = 560000 %}
{% set down_payment = home_value * 0.05 %}
{% set loan_term = 25 %}
{% set interest_rate = 3.19 %}
{% set result = (home_value - down_payment) * ( (interest_rate / 12 / 100) * ( (1 + interest_rate / 12 / 100) ) ** (loan_term * 12) / ( ( ( 1 + (interest_rate / 12 / 100 ) ) ** ( loan_term * 12 ) ) - 1 )) %}
<div class="uk-section uk-section-small uk-section-default uk-padding-remove-top">
<h3>Payment Calculator</h3>
<div>$<span class="payment-calculator-result">{{ result|number_format(0) }}</span> per month</div>
<small>{{ loan_term }} Year Amortization with 5 Year Term, {{ interest_rate }}% Interest</small>
</div>
import Cocoa
extension String {
func conformsTo(pattern: String) -> Bool {
let pattern = NSPredicate(format:"SELF MATCHES %@", pattern)
return pattern.evaluate(with: self)
}
}
@omerucel
omerucel / .zshrc
Created June 19, 2018 11:23
Docker Aliases
composer () {
tty=
tty -s && tty=--tty
docker run \
$tty \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
@omerucel
omerucel / Container.php
Created September 12, 2017 11:06
Phalcon & PHP-DI Container
<?php
namespace ABC;
use DI\NotFoundException;
use Phalcon\DI\FactoryDefault;
use Psr\Container\ContainerInterface;
class Container extends FactoryDefault implements ContainerInterface
{
@omerucel
omerucel / postgresql.sql
Created February 23, 2017 07:53
Generate test data
INSERT INTO test_table (service_id, event_type, creation_date)
SELECT
generate_series(7070001, 7070010) AS service_id,
('{clicked,pageview,failed}'::text[])[ceil(random()*3)] AS event_type,
timestamp '2016-01-10 20:00:00' + random() * (timestamp '2017-02-21 20:00:00' - timestamp '2016-01-10 10:00:00') AS creation_date
FROM generate_series(1, 10000000) AS X;