Skip to content

Instantly share code, notes, and snippets.

// is there a perfomance difference between this:
var severalTimesAWeek = frequencies.Count(f => f.Frequency > 1.1M);
var sevenTimesAWeek = frequencies.Count(f => f.Frequency <= 1.1M && f.Frequency > 0.78M);
// plus many more of these
// and this:
int severalTimesAWeek = 0;
int sevenTimesAWeek = 0;
foreach (var f in frequencies) {
if (f.Frequency > 1.1M) {
DECLARE @days int
SELECT @days = DATEDIFF(DAY, @startDate, @endDate)
;WITH left_side AS (
SELECT
ROW_NUMBER() OVER(ORDER BY a.UserId, DateUtc) as row_num
, a.UserId
, DateUtc
, u.DateCreated
class MyClass {
public DateTime Date;
public string Name;
}
var list = new List<MyClass> {
new MyClass { Date = new DateTime(2012, 02, 01), Name = "Week 1" },
new MyClass { Date = new DateTime(2012, 02, 06), Name = "Week 2" },
new MyClass { Date = new DateTime(2012, 02, 13), Name = "Week 3" },
};
var groupedByWeek = new List<DateTime> {
new DateTime(2012, 02, 01),
new DateTime(2012, 02, 02),
new DateTime(2012, 02, 06),
new DateTime(2012, 02, 13)
}.
GroupBy(s => s.DayOfYear / 7).
.Select(s => new {Date=s.First(), Amount=s.Count()})
.ToDictionary(s => s.Date, s => s.Amount);
@smoak
smoak / GeoPointConverter.java
Created March 15, 2012 19:17
GeoPointConverter blog post
import com.google.android.maps.GeoPoint;
import com.google.gson.JsonElement;
import com.google.gson.JsonArray;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonParseException;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
@smoak
smoak / gist:2381057
Created April 13, 2012 23:52
grouping stuff
public class User {
public int UserId {get;set;}
// plus some other meta data
}
public class SearchInfo {
// some meta data here
}
public class UserSearch {
Question 1: Given a String write a routine that converts the String to Long without using the built in Java functions that would do this. Describe what (if any) limitations the code has. For example:
Long StringToLong(String s) {
/* code here */
}
void Test() {
Long i = StringToLong("123");
if (i == 123) {
/* success */
@smoak
smoak / Problem2.txt
Created June 28, 2012 22:24
Problem2
Implement insert and delete in a tri-nary tree. Much like a binary tree but with 3 child nodes for each parent instead of two - with the left node being values < parent, middle nodes values == to parent and right node values > parent.
For example, if I added the following nodes to the tree in this order 5, 4, 9, 5, 7, 2, 2 - the tree would look like this:
5
/ | \
4 5 9
/ /
2 7
|
@smoak
smoak / gist:4043663
Created November 9, 2012 04:16
libgdx camera stuff
@Override
public void show() {
map = TiledLoader.createMap(Gdx.files.internal("tiles/tiles3.tmx"));
atlas = new SimpleTileAtlas(map, Gdx.files.internal("tiles/"));
tileMapRenderer = new TileMapRenderer(map, atlas, 64, 64, 5, 5);
font = new BitmapFont();
font.setColor(Color.RED);
batch = new SpriteBatch();
// my world units are tiles
@smoak
smoak / PKGBUILD
Last active December 15, 2015 11:58 — forked from saik0/PKGBUILD
# Maintainer: Jakub Schmidtke <sjakub-at-gmail-dot-com>
# Contributor: Joel Pedraza <joel@joelpedraza.com>
pkgname=android-support
pkgver=r12
pkgrel=1
pkgdesc='Android Support Package'
arch=('any')
url="https://developer.android.com/sdk/compatibility-library.html"
license=('custom')