Skip to content

Instantly share code, notes, and snippets.

View aliharis's full-sized avatar
💀

haris aliharis

💀
View GitHub Profile
@aliharis
aliharis / edit.cpp
Last active August 29, 2015 14:13
Updates a record in a text file.
#include <iostream>
#include <fstream>
using namespace std;
bool updateRecord(string currentRecord, string newRecord)
{
ifstream inFile("Data.txt"); // File to read from
ofstream outFile("Temp.txt", ios::trunc); // Temporary file
if(!inFile || !outFile) {
@aliharis
aliharis / functions.php
Created December 16, 2014 04:26
WP Shortcode: [listpages]
<?php
/**
* Shortcode: [listpages]
* @return title of current page followed by child pages
*/
function listpages_func() {
global $post;
$html = '';
@aliharis
aliharis / functions.php
Last active August 29, 2015 14:07
Display Wordpress pages in a hierarchical order
<?php
function getPagesInHierachy($post, $options = null) {
// default args for wp_list_pages (show only top level pages)
$args = array('depth' => 1);
if(is_page()) {
// get top level page ID from current page
$parents = get_post_ancestors( $post->ID );
$parent = ($parents) ? $parents[count($parents)-1]: $post->ID;
@aliharis
aliharis / date_compare.m
Created June 22, 2014 19:10
Compare 2 NSDate
NSDate *dateTraded = [NSDate dateWithTimeIntervalSince1970:1408636621];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setLocale:[NSLocale currentLocale]];
[_formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSString *_date=[_formatter stringFromDate:dateTraded];
NSLog(@"%@", _date);
NSDate *date1 = _date;
@aliharis
aliharis / date.c
Created June 22, 2014 18:49
Convert UNIX Timestamp to NSDate and to user's local timezone
NSDate *dateTraded = [NSDate dateWithTimeIntervalSince1970:1408636621];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setLocale:[NSLocale currentLocale]];
[_formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *_date=[_formatter stringFromDate:dateTraded];
NSLog(@"Final time: %@", _date);
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
id options = @{
ACFacebookAppIdKey: @"403376439767549",
ACFacebookPermissionsKey: @[ @"email", @"read_friendlists"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[accountStore requestAccessToAccountsWithType:facebookAccountType
options:options
completion:^(BOOL granted, NSError *error) {
@aliharis
aliharis / formatTelephoneNumber.php
Created April 13, 2014 07:42
Format Telephone Number with PHP
<?php
function formatTelephoneNo($phone_number, $country_code = false)
{
$cleaned = preg_replace('/[^[:digit:]]/', '', $phone_number);
if ($country_code) {
preg_match('/(\d{3})(\d{3})(\d{4})/', $cleaned, $matches);
return "({$matches[1]}) {$matches[2]} {$matches[3]}";
}
@aliharis
aliharis / OrderedBehavior.php
Created March 8, 2014 08:24
OrderedBehavior for CakePHP 2.x
<?php
/**
* OrderedBehavior
*
* @developer Alexander Morland ( aka. alkemann)
* @license MIT
* @version 2.1
* @modified 27. august 2008
*
* This behavior lets you order items in a very similar way to the tree
import java.util.Arrays;
import java.util.Scanner;
/**
* Fibonacci Number Generator
* @author haris
*/
public class Fibonacci {
public static void main(String args[]) {
/** Initialize the scanner */
/*
** 2/12/2012
** Ali Haris
*/
/*
This is a js which identifies
the viewport width and assigns
to the websites container.
*/