This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"id":"surfr","name":"Surfr","src":"surfr.app.js"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var countedJumps = 0; | |
var lastJumpNumberFromWatch = 0; | |
function onJump(height, jumpNumber, maxHeight, prevHeight, prevPrevHeight) { | |
countedJumps++; | |
drawHeight(height, jumpNumber, maxHeight, prevHeight, prevPrevHeight); | |
lastJumpNumberFromWatch = jumpNumber; | |
vibrate(3); | |
} | |
function vibrate(times) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fonts = [ | |
{name: "36", size: 26, bold: false}, | |
{name: "28", size: 22, bold: true}, | |
{name: "28", size: 22, bold: false}, | |
{name: "24", size: 20, bold: true}, | |
{name: "24", size: 20, bold: false}, | |
{name: "18", size: 14, bold: true}, | |
{name: "18", size: 14, bold: false}, | |
{name: "14", size: 11, bold: true}, | |
{name: "14", size: 11, bold: false}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tood: Map more of the existing fonts | |
function setFontPBF(name) { | |
return g.setFontPBF(require("Storage").read(name)); | |
} | |
g.setFontOld=g.setFont; | |
g.setFont=function(name, size) { | |
print(name + " " + size); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserWithPostCount | |
{ | |
public int ID { get; set; } | |
public string Name { get; set; } | |
public int PostCount { get; set; } | |
} | |
public IEnumerable<UserWithPostCount> ReadTopUsers(int offset, int countCategories) | |
{ | |
var cache = _muxer.GetDatabase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void PusblishOutstandingPosts(CancellationToken stoppingToken) | |
{ | |
const string script = @"if tonumber(redis.call('ZADD', @key1, @timestamp, @value)) == 0 then | |
return redis.call('GET', @key2) | |
else | |
return redis.call('INCR', @key2) | |
end"; | |
var prepared = LuaScript.Prepare(script); | |
var cache = _muxer.GetDatabase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable<Category> ReadTopCategories(int offset, int countCategories) | |
{ | |
var cache = _muxer.GetDatabase(); | |
var res = cache.SortedSetRangeByRankWithScores("CategoriesByPostCount", offset, offset + countCategories -1, Order.Descending); | |
var ret = new List<Category>(); | |
foreach(var e in res) | |
{ | |
ret.Add(new Category { CategoryId = e.Element, PostCount = (long)e.Score }); | |
} | |
return ret; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly ConnectionMultiplexer _muxer = ConnectionMultiplexer.Connect("localhost:6379"); | |
public void CreatePost(Post post) | |
{ | |
using var dbContext = new PostServiceContext(GetConnectionString(post.CategoryId)); | |
var transaction = dbContext.Database.BeginTransaction(); | |
dbContext.Post.Add(new Post() { CategoryId = post.CategoryId, Content = post.Content, Title = post.Title, UserId = post.UserId }); | |
dbContext.SaveChanges(); | |
dbContext.Database.ExecuteSqlRaw("Update Category set PostCount = PostCount + 1 where CategoryId = {0}", post.CategoryId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.ComponentModel.DataAnnotations; | |
namespace PostService.Entities | |
{ | |
[Index(nameof(PostId), nameof(CategoryId))] | |
public class Post | |
{ | |
public int PostId { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if tonumber(redis.call('ZADD', KEYS[1], ARGV[1], ARGV[2])) == 1 then | |
return redis.call('INCR', KEYS[2]) | |
else | |
return redis.call('GET', KEYS[2]) | |
end |
NewerOlder