Skip to content

Instantly share code, notes, and snippets.

View aliharis's full-sized avatar
💀

haris aliharis

💀
View GitHub Profile
@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 / 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 / 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 / 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 / CharacterReplace.java
Created March 11, 2016 09:19
Function for replacing the nth occurrence of a character in nth line. Results: http://oi63.tinypic.com/2wm17ig.jpg
package javaapplication1;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
@aliharis
aliharis / read.sh
Created April 17, 2016 14:58
Read a text file line by line
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
wget $line
done < "$1"
@aliharis
aliharis / slugify.js
Created March 16, 2017 15:04 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@aliharis
aliharis / gist:1821ee2f4b62f40fcf306ea22d5da837
Last active September 13, 2020 13:34
statamic nginx config
server {
listen 80;
root /var/www/cms/public;
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$args;
@aliharis
aliharis / php80.sh
Last active October 26, 2023 11:14
Installing PHP 8.1 on Ubuntu 20.04
# PHP 8.1
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get -y install php8.1-cli
# Composer
cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
@aliharis
aliharis / set_cookiejar.go
Created March 15, 2020 22:57 — forked from HugoPresents/set_cookiejar.go
golang set cookieJar example
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"strings"
)