Skip to content

Instantly share code, notes, and snippets.

View didats's full-sized avatar

Didats Triadi didats

View GitHub Profile
@didats
didats / find_position.swift
Created September 16, 2016 01:17
Finding index position of a string from a string with swift 3
// case sensitive
func findPosition(of: String, from: String) -> Int {
if let range : Range<String.Index> = from.range(of: of) {
return from.distance(from: from.startIndex, to: range.lowerBound)
}
return -1
}
findPosition(of: "adi", from: "Didats Triadi")
@didats
didats / dtsilex.conf
Created May 26, 2016 07:02
Silex under subcategory with Nginx
location /your_subdirectory {
alias /var/www/html/your_subdirectory/web;
index index.php index.html;
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /your_subdirectory/index.php last;
}
location ~ /your_subdirectory/(.+)\.php(/|$) {
@didats
didats / Nginx configuration file
Last active May 2, 2016 12:42
Add login capability on crud admin
server {
listen 80;
server_name example.com;
root /usr/share/nginx/example.com/web;
index index.php index.html;
location ~* ^/(assets|files|robots\.txt) { }
location / {
if (-f $request_filename) {
@didats
didats / check-notification-status.m
Created January 31, 2015 18:39
Check if the user enable the Notification on iOS 8, iOS 7, or less
NSInteger activePush = 1;
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
activePush = ([application isRegisteredForRemoteNotifications]) ? 1 : 0;
}
else {
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone) activePush = 0;
}
@didats
didats / register.m
Created September 30, 2014 13:34
Register Push Notification iOS 8
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
@didats
didats / delay-swift3.swift
Last active September 16, 2016 04:11
Delay execution in iOS (Objective C & Swift 2 & Swift 3)
func delay(withTime: Double, callback: @escaping () -> Void) {
let when = DispatchTime.now() + withTime
DispatchQueue.main.asyncAfter(deadline: when) {
callback()
}
}
@didats
didats / nginx_config
Created May 14, 2014 09:04
nginx to enable a url with php extension
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /usr/share/nginx/www;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
@didats
didats / nationality_dropdown
Created December 28, 2013 01:24
PHP Function for Nationality Dropdown menu
function nationalityDropdown ($name, $id, $selected, $class="form-control") {
$arr = array('Afghan','Albanian','Algerian','American','Andorran','Angolan','Antiguans','Argentinean','Armenian','Australian','Austrian','Azerbaijani','Bahamian','Bahraini','Bangladeshi','Barbadian','Barbudans','Batswana','Belarusian','Belgian','Belizean','Beninese','Bhutanese','Bolivian','Bosnian','Brazilian','British','Bruneian','Bulgarian','Burkinabe','Burmese','Burundian','Cambodian','Cameroonian','Canadian','Cape Verdean','Central African','Chadian','Chilean','Chinese','Colombian','Comoran','Congolese','Costa Rican','Croatian','Cuban','Cypriot','Czech','Danish','Djibouti','Dominican','Dutch','East Timorese','Ecuadorean','Egyptian','Emirian','Equatorial Guinean','Eritrean','Estonian','Ethiopian','Fijian','Filipino','Finnish','French','Gabonese','Gambian','Georgian','German','Ghanaian','Greek','Grenadian','Guatemalan','Guinea-Bissauan','Guinean','Guyanese','Haitian','Herzegovinian','Honduran','Hungarian','Icelander','India
@didats
didats / nationality.html
Created December 28, 2013 00:00
Nationality List in HTML Dropdown
<select name="nationality">
<option value="">-- select one --</option>
<option value="afghan">Afghan</option>
<option value="albanian">Albanian</option>
<option value="algerian">Algerian</option>
<option value="american">American</option>
<option value="andorran">Andorran</option>
<option value="angolan">Angolan</option>
<option value="antiguans">Antiguans</option>
<option value="argentinean">Argentinean</option>
@didats
didats / php_civilid.php
Created November 18, 2013 02:00
Civil ID Validation for Kuwait Citizen using PHP
function validate_civilid($str) {
$valid = false;
if(preg_match("/[0-9]/{12}", $str)) {
$test = ((substr($str, 0, 1) * 2) + ((substr($str, 1, 1) * 1) + ((substr($str, 2, 1) * 6) + ((substr($str, 3, 1) * 3) + ((substr($str, 4, 1) * 7) + ((substr($str, 5, 1) * 9) + ((substr($str, 6, 1) * 10) + ((substr($str, 7, 1) * 5) + ((substr($str, 8, 1) * 8) + ((substr($str, 9, 1) * 4) + ((substr($str, 10, 1) * 2) ) % 11;
if($test == substr($str, 11, 1)) $valid = true;
}
return $valid;