Skip to content

Instantly share code, notes, and snippets.

@dantswain
dantswain / QuadraticForm
Created December 3, 2011 21:50
Quadratic form in c
for(i = 0; i < n_rows; i++)
{
tmp = 0;
for(j = i + 1; j < n_rows; j++)
{
tmp += prA[i*n_rows + j]*prX[j];
}
y += prX[i]*2.0*tmp;
y += prX[i]*prX[i]*prA[i*n_rows + i];
}
void DImage::deskew(string filename, unsigned int angle)
{
if (filename == "")
return;
std::cout << "Being called with filename " << filename << std::endl;
Mat img = imread(filename, CV_LOAD_IMAGE_GRAYSCALE);
@dantswain
dantswain / gist:1981581
Created March 5, 2012 22:22
how to get a stdout/stderr console in windows
if(AllocConsole())
{
freopen("CONOUT$", "wt", stdout);
freopen("CONOUT$", "wt", stderr);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
fprintf(stdout, "\n");
fprintf(stdout, " stdout/stderr Console\n");
@dantswain
dantswain / ErlangFirstMatch
Created September 30, 2012 15:17
Erlang first match functions (doesn't evaluate past first match)
% From http://stackoverflow.com/questions/12657202/
-export([first/3, first1/3]).
% My solution
first([E | Rest], Condition, Default) ->
case Condition(E) of
true -> E;
false -> first(Rest, Condition, Default)
end;
first([], _Cond, Default) -> Default.
@dantswain
dantswain / gist:c3709e249a174d42e59a
Last active August 29, 2015 14:17
Javascript Shaming

To produce a string a la '2015-03-25' for the current date

In Ruby:

require 'date'
d = Date.today
puts d.to_s

In Javascript:

@dantswain
dantswain / gist:c1198e27f95664449fec
Created April 7, 2015 15:30
Ruby GC and finalizers
# encoding: utf-8
class Bar
def initialize(name)
@name = name
end
def hi
puts "HI #{@name}"
end
@dantswain
dantswain / gist:fdfb1c2c86e4d940a8f5
Last active May 3, 2020 04:05
Convert Elixir config.exs to Erlang sys.config
#!/usr/bin/env elixir
# Convert an Elixir config.exs to an erlang sys.config
#
# Usage: elixir_to_sys_config config.exs > sys.config
# First argument is the Elixir config.exs file
# Writes to stdout
# You probably want to set MIX_ENV accordingly
#
# 2015 by Dan Swain, [email protected]
@dantswain
dantswain / gist:d517a57eac7cd19f2c07
Created February 18, 2016 19:57
KafkaEx consumer group begin set to "kafka_ex"
iex(1)> KafkaEx.create_worker(:foo, uris: Application.get_env(:kafka_ex, :brokers), consumer_group: "bar")
14:53:54.712 [debug] Succesfully connected to "localhost" on port 9092
14:53:54.714 [debug] Succesfully connected to "localhost" on port 9093
14:53:54.716 [debug] Succesfully connected to "localhost" on port 9094
{:ok, #PID<0.138.0>}
iex(2)> Enum.each(1..1000, fn x -> KafkaEx.produce("foo", 0, "bar#{x}") end)
:ok
@dantswain
dantswain / thrash_test.thrift
Created October 16, 2016 17:22
Example thrift file with enum and typedef
namespace erl thrash
typedef i64 UgeInt
const i32 MAX_THINGS = 42
enum TacoType {
BARBACOA = 123,
CARNITAS = 124,
STEAK = 125,

Keybase proof

I hereby claim:

  • I am dantswain on github.
  • I am dantswain (https://keybase.io/dantswain) on keybase.
  • I have a public key whose fingerprint is 6C6B A60E D74A C07B 6124 F3DA A171 B2F0 C78D 87D4

To claim this, I am signing this object: