Skip to content

Instantly share code, notes, and snippets.

View savasadar's full-sized avatar
🦊
onchain

Savaş ADAR savasadar

🦊
onchain
View GitHub Profile
@savasadar
savasadar / turkiye_il_ilce_semt_mahalle.sql
Last active January 21, 2020 13:13
Türkiye İl-İlçe-Semt-Mahalle Listesi MSSQL - 2020
This file has been truncated, but you can view the full file.
USE [EMLAK_HANEM]
GO
/****** Object: Table [dbo].[IL] Script Date: 1/21/2020 4:05:09 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IL](
[id] [int] IDENTITY(1,1) NOT NULL,
[adi] [nvarchar](50) NOT NULL,
@savasadar
savasadar / GetCurrentForegroundActivity.java
Created May 17, 2019 14:53
Get current foreground activity context in android
public static Activity getActivity() {
try {
Class activityThreadClass = Class.forName("android.app.ActivityThread");
Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
activitiesField.setAccessible(true);
Map<Object, Object> activities = (Map<Object, Object>) activitiesField.get(activityThread);
if (activities == null)
return null;
@savasadar
savasadar / App.java
Last active May 17, 2019 13:36
Detect android app foreground and background state with LifecycleObserver
import android.app.Application;
import android.util.Log;
import android.arch.lifecycle.*;
public class App extends Application implements LifecycleObserver {
@Override
public void onCreate() {
super.onCreate();
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
@savasadar
savasadar / TopmostViewControllerExtension.swift
Created April 16, 2019 12:36
Get the topmost viewController anywhere in the app (typically from the appDelegate). Get the current visible viewController.
extension UIViewController {
func topMostViewController() -> UIViewController {
if let presented = self.presentedViewController {
return presented.topMostViewController()
}
if let navigation = self as? UINavigationController {
return navigation.visibleViewController?.topMostViewController() ?? navigation
}
@savasadar
savasadar / CountryListWithNativeLanguage.sql
Last active September 8, 2018 14:09
Country List with Native Language Sql Table Create Script
CREATE TABLE CountryTemp(
country_code NVARCHAR(4) NOT NULL
,lang_code NVARCHAR(3) NOT NULL
,lang_name NVARCHAR(12) NOT NULL
,country_name NVARCHAR(36) NOT NULL
,lang_native NVARCHAR(18)
);
INSERT INTO CountryTemp(country_code,lang_code,lang_name,country_name,lang_native) VALUES (N'TG',N'ee',N'Ewe',N'Togo',N'Eʋegbe');
INSERT INTO CountryTemp(country_code,lang_code,lang_name,country_name,lang_native) VALUES (N'KE',N'kam',N'Kamba',N'Kenya',NULL);
INSERT INTO CountryTemp(country_code,lang_code,lang_name,country_name,lang_native) VALUES (N'HN',N'es',N'Spanish',N'Honduras',N'español');
@savasadar
savasadar / CountryListWithNativeLanguages.json
Last active September 8, 2018 14:00
Country List with Native Language Json
[
{
"country_code": "TG",
"lang_code": "ee",
"lang_name": "Ewe",
"country_name": "Togo",
"lang_native": "Eʋegbe"
},
{
"country_code": "KE",
@savasadar
savasadar / GenerateKeys.py
Created November 8, 2017 11:12
The following code produces sample 30-character SHA256-based mini private keys in Python.
import random
import hashlib
BASE58 = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def Candidate():
"""
Generate a random, well-formed mini private key.
"""
return('%s%s' % ('S', ''.join(
@savasadar
savasadar / BitcoinValidator
Created November 8, 2017 08:28
c# BitcoinValidator
using System;
using System.Linq;
using System.Security.Cryptography;
using NUnit.Framework;
namespace BitcoinValidator
{
public class ValidateTest
{
@savasadar
savasadar / BitcoinAddressValidator
Created November 8, 2017 08:24
Ruby code for validating bitcoin address
require 'digest'
class BitcoinAddressValidator < ActiveModel::EachValidator
def validate(record, field, value)
unless valid_bitcoin_address?(value)
record.errors[field] << "Bitcoin address is invalid"
end
end
private
@savasadar
savasadar / BCAddressField.py
Last active February 20, 2019 14:17
Python code for validating bitcoin address
#
# DJango field type for a Bitcoin Address
#
import re
from django import forms
from django.forms.util import ValidationError
from Crypto.Hash import SHA256
class BCAddressField(forms.CharField):
default_error_messages = {