Skip to content

Instantly share code, notes, and snippets.

Jim.Wang neo125874

Block or report user

Report or block neo125874

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@neo125874
neo125874 / AESGCM.cs
Created Feb 9, 2017 — 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
View AESGCM.cs
/*
* 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 Sep 22, 2016
PlayOnServer(global.asax.cs)
View PlayOnServer.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 Sep 22, 2016
PlayOnServer(controller)
View PlayOnServer.cs
//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 Aug 18, 2016
fluent interface implementation example
View FluentInterface.cs
public class WeightedModel {
private WeightedModel() {
_set = new WeightedModelFluentInterface(this);
}
public static WeightedModelFluentInterface Create() {
return new WeightedModel().Set;
}
@neo125874
neo125874 / FlatToHierarchy.cs
Last active Aug 11, 2016
Flat Hierarchy Conversion
View FlatToHierarchy.cs
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 Aug 11, 2016
get the public ip, search the ip location, and retrieve the google nearby result
View GoogleNearby.cs
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 Jul 28, 2016 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
View Program.cs
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 Jul 22, 2016
Codility Lesson 3-3 Time Complexity
View PermMissingElem.cs
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 Jul 22, 2016
Codility Lesson 3-2 Time Complexity
View FrogJmp.cs
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;
@neo125874
neo125874 / TapeEquilibrium.cs
Created Jul 22, 2016
Codility Lesson 3-1 Time Complexity
View TapeEquilibrium.cs
using System;
using System.Linq;
// 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) {
You can’t perform that action at this time.