Skip to content

Instantly share code, notes, and snippets.

View amenayach's full-sized avatar

Amen Ayach amenayach

View GitHub Profile
@amenayach
amenayach / Mac.cs
Created August 11, 2016 07:34
Mac.cs is winforms class that makes a Form opens with sliding motion from one of four directions selected by the user. Usage: Mac.Slide(form);
//By Amen Ayach
using System;
using System.Windows.Forms;
using System.Drawing;
public class Mac
{
public enum eDirection
{
Up,
@amenayach
amenayach / StickyInput.cs
Last active April 12, 2018 23:27
This helps to maintain last used inputs in a winform, let's say you have a Title and Description text boxes in a form F, this class will ensure when the form F is loaded that last entered input in these text boxes will be present at load event
namespace System.Windows.Forms
{
//This class requires JSON.net package, to install from the nuget console use:
//Install-Package Newtonsoft.Json
using Newtonsoft.Json.Linq;
using System.IO;
using System.Linq;
public static class StickyInput
{
@amenayach
amenayach / Base64FileConverter.cs
Last active April 25, 2018 13:16
A C# base64 file converter.
using System;
using System.IO;
using System.Linq;
public static class Base64FileConverter
{
public static string ToBase64(byte[] bytes)
{
if (bytes == null || bytes.Length == 0)
@amenayach
amenayach / SqlService.cs
Created August 20, 2019 08:31
Execute non-query MS SQL script using C#
namespace SqlSample
{
using System;
using System.Data;
using System.Data.SqlClient;
public class SqlService
{
private readonly string connectionString;
function http(url, method, payload, callback) {
const options = {
method: method ? method : 'GET',
headers: {
"Content-Type": "application/json"
}
};
if(payload) {
options.body = JSON.stringify(payload);
@amenayach
amenayach / LebanonFiles.py
Last active October 30, 2019 08:53
Simple python script that retrieves Lebanon files site latest news (use Jupyter for best view)
from requests import get
from requests.exceptions import RequestException
from contextlib import closing
from bs4 import BeautifulSoup
#Best used via Jupyter
def download_text(url):
try:
with closing(get(url, stream=True)) as resp:
if is_good_response(resp):
@amenayach
amenayach / random-string.js
Created December 6, 2019 08:22
Generates random alpha numeric string
function getRandomChar(isChar) {
return parseInt(Math.random() * 100) % (isChar === true ? 26 : 10);
}
function getRandomString(length) {
return [...new Array(length)]
.map((x, i) =>
i % 2 === 0 ?
String.fromCharCode(65 + getRandomChar(true)).toString() :
getRandomChar(false).toString())
@amenayach
amenayach / Nester.cs
Last active May 13, 2020 23:30
A CSharp class that builds a nested tree out of a flat collection
public sealed class Nester<T, TSortKey> : IDisposable
{
private readonly IEnumerable<T> flatList;
private Func<T, T, bool> parentChildPredicate;
private PropertyInfo nestingPropertyInfo;
private Func<T, TSortKey> sortingKeySelector;
private Func<T, bool> rootLevelPredicate;
private Nester(IEnumerable<T> flatList,
Func<T, bool> rootLevelPredicate,