Skip to content

Instantly share code, notes, and snippets.

View neo125874's full-sized avatar

Jim neo125874

View GitHub Profile
@neo125874
neo125874 / Fader.cs
Created March 3, 2021 03:17 — forked from nathan-fiscaletti/Fader.cs
A C# class used to control fading forms in and out
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FormFader
{
/// <summary>
/// An object used to control fading forms in and out.
/// </summary>
class Fader
@neo125874
neo125874 / AESGCM.cs
Created February 9, 2017 01:32 — forked from jbtule/AESGCM.cs
I have two code examples that I wrote for best practices encrypting a string in c#. They are both using authenticated encryption. http://stackoverflow.com/a/10366194/637783
/*
* This work (Modern Encryption of a String C#, by James Tuley),
* identified by James Tuley, is free of known copyright restrictions.
* https://gist.github.com/4336842
* http://creativecommons.org/publicdomain/mark/1.0/
*/
using System;
using System.IO;
using System.Text;
@neo125874
neo125874 / PlayOnServer.cs
Created September 22, 2016 02:42
PlayOnServer(global.asax.cs)
protected void Application_Start()
{
//check for bin files to be loaded
CheckAddBinPath();
}
public static void CheckAddBinPath()
{
// find path to 'bin' folder
var binPath = Path.Combine(new string[] { AppDomain.CurrentDomain.BaseDirectory, "bin" });
@neo125874
neo125874 / PlayOnServer.cs
Last active September 22, 2016 02:39
PlayOnServer(controller)
//exclude the special character
[ValidateInput(false)]
public FileResult TextToMp3(string text)
{
//Primary memory stream for storing mp3 audio
var mp3Stream = new MemoryStream();
//Speech format
var speechAudioFormatConfig = new SpeechAudioFormatInfo(samplesPerSecond: 8000, bitsPerSample: AudioBitsPerSample.Sixteen, channel: AudioChannel.Stereo);
//Naudio's wave format used for mp3 conversion. Mirror configuration of speech config.
var waveFormat = new WaveFormat(speechAudioFormatConfig.SamplesPerSecond, speechAudioFormatConfig.BitsPerSample, speechAudioFormatConfig.ChannelCount);
@neo125874
neo125874 / FluentInterface.cs
Created August 18, 2016 02:53
fluent interface implementation example
public class WeightedModel {
private WeightedModel() {
_set = new WeightedModelFluentInterface(this);
}
public static WeightedModelFluentInterface Create() {
return new WeightedModel().Set;
}
@neo125874
neo125874 / FlatToHierarchy.cs
Last active August 11, 2016 09:36
Flat Hierarchy Conversion
private static List<Category> FlatToHierarchy(List<Category> list, int parentID = 0)
{
return (from l in list
where l.ctgParentID == parentID
select new Category
{
ctgID = l.ctgID,
ctgParentID = l.ctgParentID,
ctgName = l.ctgName,
childCategories = FlatToHierarchy(list, l.ctgID),
@neo125874
neo125874 / GoogleNearby.cs
Last active August 11, 2016 03:54
get the public ip, search the ip location, and retrieve the google nearby result
public class GetGeoLocation
{
public PlacesApiQueryResponse GetGNBSresult(string querystring) {
byte[] bResult = null;
PlacesApiQueryResponse result = null;
using (WebClient wc = new WebClient())
{
bResult = wc.DownloadData(querystring);
string jsonstring = Encoding.UTF8.GetString(bResult);
@neo125874
neo125874 / Program.cs
Created July 28, 2016 07:12 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@neo125874
neo125874 / PermMissingElem.cs
Created July 22, 2016 08:17
Codility Lesson 3-3 Time Complexity
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(int[] A) {
double sum = 0;
@neo125874
neo125874 / FrogJmp.cs
Created July 22, 2016 08:05
Codility Lesson 3-2 Time Complexity
using System;
// you can also use other imports, for example:
// using System.Collections.Generic;
// you can write to stdout for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(int X, int Y, int D) {
if ((Y - X) < D && Y != X) return 1;