Skip to content

Instantly share code, notes, and snippets.

View wizact's full-sized avatar
🐶
I have no idea what i'm doing

Amir Mohtasebi wizact

🐶
I have no idea what i'm doing
View GitHub Profile
@wizact
wizact / serviceMon.ps1
Created December 14, 2012 14:34
PowerShell script to check the status of a windows service, send an alert and start it if it is stopped.
# Created by: Amir
# Date: 14 December 2012
# Description: Check Win Service to see if it is running and start it otherwise
# Usage: powershell -Command "C:\Scripts\serviceMonitor.ps1 | Out-File C:\Scripts\ServiceMonitor.txt -append"
$serviceName = "SampleServiceName"
$service = Get-Service | Where-Object { $_.Name -eq $serviceName }
write-host "Service Status is" $service.status
@wizact
wizact / ajaxjquery.js
Last active December 10, 2015 01:35
Simple Ajax using JQuery and JSON
$.ajax({
url:'http://your/url',
data:{ apikey: 'secret-key-or-any-other-parameter-in-json-format' },
dataType:'json',
success:function (data) {alert(data.first_name);}
});
@wizact
wizact / JSONPXDomain.js
Created December 22, 2012 12:18
Cross-Domain Ajax call using JQuery and JSONP
$.ajax({
url:'http://your/url?callback=?',
data:{ apikey: 'secret-key-or-any-other-parameter-in-json-format' },
dataType:'jsonp',
crossDomain: 'true',
success:function (data) {alert(data.first_name);}
});
@wizact
wizact / StreamManager.cs
Created April 30, 2013 22:30
Handling incoming streams in WCF when transmode is set to streaming
public class StreamManager
{
private const int BufferLength = 1024;
/// <summary>
/// Receives the sourceStream from service and iterate until end of the stream
/// </summary>
/// <param name="sourceStream">Source stream</param>
/// <returns>Memory stream</returns>
public MemoryStream ReadStream(Stream sourceStream)
{
@wizact
wizact / gist:7527296
Created November 18, 2013 12:52
Resolving EntitySetName and predicate/project automatically for WCF Data Service.
using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Data.Services.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace ODataSampleClient
@wizact
wizact / gist:30927f355858deffefad
Last active August 29, 2015 14:14
Creating an object using Lambda Expressions
public static class ReflectionHelper
{
public static T CreateInstance<T>()
{
var constructor = Expression.New( typeof(T) );
var instance = (Func<T>)Expression.Lambda(constructor).Compile();
return instance();
}
public static T CreateInstance<T>(params object[] args)
@wizact
wizact / mousemoveelement.html
Last active August 29, 2015 07:20
Object move by mouse events example using vanilla JavaScript
<html>
<head>
<style>
.dv1 {
display: block;
position: absolute;
top: 75px;
left: 75px;
width:50px;
height: 50px;
@wizact
wizact / forwardport.sh
Created December 20, 2015 08:07
Forward port 80 to 8080 on EC2 instance.
sudo iptables -t nat -L
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
@wizact
wizact / aws_mongo.sh
Created January 16, 2016 11:48
Preparing and running an aws instance for Mongo
#!/bin/bash
set -e
install_mongo() {
sudo yum -y update
echo "[MongoDB]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
@wizact
wizact / fix_locale.sh
Created May 12, 2016 00:48
Fixing the locale not supported issue
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8 #better not to set this
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
#Better way --> Check the: /etc/default/locale
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"