Skip to content

Instantly share code, notes, and snippets.

package simurrythmia.ui.util;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
### Keybase proof
I hereby claim:
* I am mverzilli on github.
* I am mverzilli (https://keybase.io/mverzilli) on keybase.
* I have a public key whose fingerprint is 1A62 F4E8 C9E1 3F5E 913E 60A4 029B 117E D8E9 4948
To claim this, I am signing this object:
@mverzilli
mverzilli / CoffeeScriptvsJavascriptarraypopulation
Created October 8, 2011 21:43
CoffeeScript vs. Javascript array population
JavaScript:
var data = []
for (var i = 0; i < 84; i++) {
data.push(i * 10 / 84);
}
CoffeeScript:
data = (i * 10 / 84 for i in [0..83])
width = 760
height = 260
xmin = -1.2
xmax = 5
x_scale = d3.scale.linear()
x_scale.domain([xmin, xmax])
.range [0, width]
@mverzilli
mverzilli / gist:2216540
Created March 27, 2012 14:48
Original service method
public User GetUserByEmail(string email)
{
var key = email;
var user = Cache.Cache.Get<User>(key);
if (user == null)
{
try
{
user = builder.BuildFromNewDbs(email);
@mverzilli
mverzilli / gist:2217535
Created March 27, 2012 16:07
Storified service method
public User GetUserByEmail(string email)
{
/*
* I use the email param as a key to get a user from cache,
* so I store the email in a variable called "key".
* If the user is in cache, we're done! If the user isn't in cache,
* I try to get it from the new database.
* If the user isn't in the new database, everything may blow up,
* so I have to be careful just in case it does.
* There's no way for me to know whether the user
@mverzilli
mverzilli / gist:2217613
Created March 27, 2012 16:17
Storified service method
public User GetUserByEmail(string email)
{
/*
* I use the email param as a key to get a user from cache,
* so I store the email in a variable called "key".
* If the user is in cache, we're done! If the user isn't in cache,
* I try to get it from the new database.
* If the user isn't in the new database, everything may blow up,
* so I have to be careful just in case it does.
* There's no way for me to know whether the user
@mverzilli
mverzilli / gist:2217677
Created March 27, 2012 16:25
Service method target story
public User GetUserByEmail(string email)
{
/*
* You give me an email and I'll give you a user.
* By the way, I'll make use of a cache layer so that
* your request doesn't result in performance issues.
* It's not a wonderful world (sorry, Louis Armstrong),
* so in case something goes wrong I'll just write it down
* for someone to take a look at it later.
*/
@mverzilli
mverzilli / gist:3962611
Created October 27, 2012 01:39
Compute columns
@columns = []
ConditionCodeProperty.select('property, format, field_name').select('GROUP_CONCAT(condition_code) as conditions').group('property, format, field_name').where(condition_code: current_user.condition_codes).each do |condition_code_property|
unless Result.is_common(condition_code_property.property)
common = Result.is_extended_common(condition_code_property.property)
column = {
property_name: condition_code_property.property,
value_accessor: condition_code_property.property,
human_name: Result.human_name_for(condition_code_property.property),
field_name: condition_code_property.field_name,
extended: !common,
@mverzilli
mverzilli / inverse_matrix.cr
Created October 18, 2015 21:28
Invert a matrix with Crystal via Lapack bindings
@[Link(framework: "Accelerate")]
lib LibLapack
fun sgetrf_(m: Int32*, n: Int32*, a: Void*, lda: Int32*, ipiv: Int32*, info: Int32*)
fun sgetri_(n: Int32*, a: Void*, lda: Int32*, ipiv: Int32*, work: Void*, lwork: Int32*, info: Int32*)
end
# Matrix A (the one being inverted)
# Matrix [1 2
# 3 4]