Skip to content

Instantly share code, notes, and snippets.

@mortymacs
mortymacs / show_status.py
Created July 22, 2013 04:39
Show status of your favorite programs
#!/usr/bin/env python
import subprocess
def check():
plist = open("plist").readlines()
for i in plist:
if i[:1] == "#":
continue
cline = i.split()
@mortymacs
mortymacs / size.c
Created April 24, 2014 15:21
convert number to human-readable size in C
#include <stdio.h>
char *types[] = {"KB","MB","GB","TB","PB","EB","ZB","YB"};
void change(int *size)
{
int div = 1024;
int i = 0;
for(;i<8;i++)
{
*size /= div;
if(*size < div)
@mortymacs
mortymacs / fetch_email.go
Created August 2, 2014 10:08
This is simple regex in Golang
package main
import "fmt"
import "regexp"
func main() {
re := regexp.MustCompile("[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+\\.[a-z]{2,}")
match := re.FindStringSubmatch("this is my email info@google.com")
if len(match) != 0 {
fmt.Printf("Email: %s\n",match[0])
@mortymacs
mortymacs / Email To SharePoint.cs
Created June 15, 2016 19:48
Add email attachment with specific user (owner) in SharePoint list.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using S22.Imap;
using System.Net.Mail;
using System.Data.Sql;
using System.Data.SqlClient;
@mortymacs
mortymacs / .vimrc
Last active March 2, 2017 09:51
My vim config file
" Default settings
set number
syntax enable
set showmatch
set encoding=utf-8
set nocompatible
set paste
set nowrap
set tabstop=2 shiftwidth=2
set expandtab
@mortymacs
mortymacs / whereiam.py
Created January 20, 2017 10:00
Get current location (country/city name)
#!/usr/bin/env python2
import urllib
import json
try:
body = urllib.urlopen("http://ip-api.com/json").read()
body = json.loads(body)
print body.get('country'),"/",body.get("city")
except:
print("Connection failed!")
@mortymacs
mortymacs / whereiam.sh
Last active January 20, 2017 10:31
Get current location (country/city name)
#!/bin/sh
echo $(curl -s http://ip-api.com/json | jq -r ".country,.city")
@mortymacs
mortymacs / system_info.c
Created January 30, 2017 21:35
Showing system info
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
int main() {
struct utsname *x = malloc(sizeof(struct utsname));
uname(x);
printf("SYS NAME: %s\n", x->sysname);
printf("NODE NAME: %s\n", x->nodename);
printf("RELEASE: %s\n", x->release);
@mortymacs
mortymacs / google_sendmail_script.js
Created February 5, 2017 09:49
Google send mail script for HTML contact page
var receiver_email = "YOUR_EMAIL_ADDRESS";
function outputPretty(data) {
body = (data['message']).toString().replace(/\r\n|\r|\n/g, "<br>");
message = "<p><b>Date Time:</b> " + (new Date()).toString() + "</p>";
message += "<p><b>Name:</b> " + data['name'] + "</p>";
message += "<p><b>Email:</b> " + data['email'] + "</p>";
message += "<p>" + body + "</p>";
return message;
}
@mortymacs
mortymacs / dynamic_sum.c
Created February 7, 2017 06:31
Handle dynamic arguments in C
#include <stdio.h>
#include <stdarg.h>
double sum(int argc, ...) {
va_list items;
double result = 0;
va_start(items, argc);
for(int i=0; i<argc; i++)
result += va_arg(items, double);
va_end(items);