Skip to content

Instantly share code, notes, and snippets.

View clupasq's full-sized avatar

Cristian Lupașcu clupasq

View GitHub Profile
@clupasq
clupasq / gist:1736646
Created February 4, 2012 09:20
get original URL from short URL (ex: bit.ly)
static string GetOriginalUrl(string shortUrl)
{
var httpRequest = (HttpWebRequest) WebRequest.Create(shortUrl);
httpRequest.Method = "HEAD";
using (var response = httpRequest.GetResponse())
return response.ResponseUri.AbsoluteUri;
}
@clupasq
clupasq / AssemblyInfo.cs
Created March 13, 2012 08:49
log4net colored console+flat file appender configuration
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
@clupasq
clupasq / nlog colored console files
Created March 13, 2012 08:52
nlog configuration for colored console + info&error files
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="coloredConsole" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false"
layout="${longdate}|${pad:padding=5:inner=${level:uppercase=true}}|${message}" >
<highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGray" />
<highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
@clupasq
clupasq / golfscript_snippets
Last active October 5, 2015 07:58
Golfscript snippets
.,{)\.@%!},,2= # is number prime (expects number on stack and adds 1 or 0 (leaves number on stack))
:§,{)§\%!},,2= # just like above, except this consumes the number from the stack.
..,1>{*}*\%)= # shorter version, using Wilson's theorem (https://en.wikipedia.org/wiki/Wilson%27s_theorem)
# must take a parameter > 1, therwise fails
@clupasq
clupasq / gist:2994524
Created June 26, 2012 08:53
Git config
git config --global user.name <user>
git config --global user.email <email>
git config --global help.autocorrect 1
git config --global color.ui auto
git config --global core.autocrlf true
git config --global alias.glog "log --graph --oneline --all --decorate"
git config --global core.editor "C:/Windows/notepad.exe"
@clupasq
clupasq / timeout.cs
Created September 4, 2012 12:34
C# Timeout implementation
[Test]
public void ComputeResultWithTimeout()
{
var task = Task.Factory.StartNew(() => ComputeResult("bla"));
//task.Wait(0999);
task.Wait(1000);
if (task.IsCompleted)
Console.WriteLine("OK, got: " + task.Result);
@clupasq
clupasq / .hgignore
Created June 30, 2013 19:06
basic .hgignore file
# use glob syntax
syntax: glob
*.obj
*.pdb
*.user
*.aps
*.pch
*.vspscc
*.vssscc
@clupasq
clupasq / golfscript.sublime-build
Last active December 19, 2015 21:09
Golfscript Build System for Sublime 3
{
"cmd": ["ruby", "D:\\path\\to\\golfscript.rb", "$file"],
"selector": "source.gs"
}
@clupasq
clupasq / RunnableInDebugOnlyAttribute.cs
Created August 8, 2013 05:45
xUnit.net RunnableInDebugOnlyAttribute
public class RunnableInDebugOnlyAttribute : FactAttribute
{
private string _skip;
public override string Skip
{
get
{
return Debugger.IsAttached
? _skip
@clupasq
clupasq / subByColor.js
Created September 10, 2013 06:52
SumByColor v1.1 - Added methods for Foreground Color - replaced the deprecated getBackgroundColor() with getBackground()
function getBackgroundColor(rangeSpecification) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
return sheet.getRange(rangeSpecification).getBackground();
}
function getForegroundColor(rangeSpecification) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
return sheet.getRange(rangeSpecification).getFontColor();
}