Skip to content

Instantly share code, notes, and snippets.

View jltrem's full-sized avatar

Joe Tremblay jltrem

  • College Station, TX
View GitHub Profile

##recursive add all git add --all

##commit git commit -m "this is the commit message"

##squash git reset --soft HEAD~2 && git commit where 2 is the number of commits to squash

@jltrem
jltrem / octave.md
Created November 7, 2015 16:05 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &&
function() {
// http://stackoverflow.com/a/2117523/571637
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
/* jshint bitwise: false */
var r = Math.random() * 16 | 0;
var v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function() {
// persist the table so it doesn't need to be created every time
var crcTable = null;
var makeCrcTable = function() {
var c;
var table = [];
for (var n = 0; n < 256; n++) {
c = n;
{"Forecast":[{"CodedClouds":"BK","CodedCoverage":"C","CodedIntensity":"","CodedWeather":"T","ConditionIce":false,"ConditionRain":true,"ConditionSnow":false,"Day":1,"DayName":"Monday","Description":"Mostly Cloudy with Scattered Storms","DescriptionShort":"Scattered Storms","HighTempF":84,"Icon":"mcloudyt.png","LowTempF":73,"PossOfPrecip":80,"PrecipMM":24.26,"SnowMM":0,"Timestamp":"\/Date(1431950400000-0400)\/","WindDir":"SE","WindKPH":12},{"CodedClouds":"BK","CodedCoverage":"S","CodedIntensity":"","CodedWeather":"T","ConditionIce":false,"ConditionRain":true,"ConditionSnow":false,"Day":2,"DayName":"Tuesday","Description":"Mostly Cloudy with Isolated Storms","DescriptionShort":"Isolated Storms","HighTempF":86,"Icon":"mcloudyt.png","LowTempF":72,"PossOfPrecip":38,"PrecipMM":2.03,"SnowMM":0,"Timestamp":"\/Date(1432036800000-0400)\/","WindDir":"ESE","WindKPH":17},{"CodedClouds":"SC","CodedCoverage":"S","CodedIntensity":"","CodedWeather":"T","ConditionIce":false,"ConditionRain":true,"ConditionSnow":false,"Day":3,"Da
@jltrem
jltrem / LittleHttpServer.cs
Created March 4, 2015 19:44
http server that processes requests and sends responses with cookies
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
namespace Whatever
{
public class HttpResponseData
@jltrem
jltrem / CreateWebRequest.cs
Created March 4, 2015 19:34
web request by client, sending cookies to server
private HttpWebRequest CreateWebRequest(ApiCommands cmd, List<string> restParams, bool post = false)
{
var url = new StringBuilder();
url.AppendFormat("http://localhost:8080/api/v1/{0}", cmd);
if (restParams != null)
{
restParams.ForEach(x => url.AppendFormat("/{0}", x));
}
var request = (HttpWebRequest)WebRequest.Create(url.ToString());
request.ContentType = "application/json";
@jltrem
jltrem / ReadHttpWebRequestResponse.cs
Created March 4, 2015 19:32
client receiving cookies
private readonly List<Cookie> _cookies = new List<Cookie>();
private readonly object _mutex = new object();
private Dictionary<string, object> ReadResponse(HttpWebRequest request)
{
string rawResponse;
var cookieJar = new CookieContainer();
request.CookieContainer = cookieJar;
[Fact]
public void test_byte_encoding_decoding()
{
var encoding = new UTF8Encoding();
byte[] inputBytes = encoding.GetBytes("sample");
var hexString = BitConverter.ToString(inputBytes);
byte[] outputBytes = hexString.Split('-').Select(hex => byte.Parse(hex, NumberStyles.HexNumber)).ToArray();
Assert.Equal(inputBytes, outputBytes);
@jltrem
jltrem / DictionaryXmlSerialization.cs
Last active August 29, 2015 14:05
serializing IDictionary via XmlSerializer
/// <summary>
/// System.Collections.Generic.KeyValuePair has not setters so we have to roll our own in order to serialize.
/// </summary>
[Serializable]
[XmlType(TypeName = "KVP")]
public struct SerializableKeyValuePair<K, V>
{
public K Key { get; set; }
public V Value { get; set; }
}