Skip to content

Instantly share code, notes, and snippets.

View graffic's full-sized avatar

Javier Gonel graffic

View GitHub Profile
use std::rc::Rc;
use rusqlite::{params, Connection, Statement};
use owning_ref::OwningHandle;
struct MyStatements<'a> {
select_all: Statement<'a>,
select_one: Statement<'a>
}
type MyStatementsOwned = OwningHandle<Rc<Connection>, Box<MyStatements<'static>>>;
@graffic
graffic / stats.js
Last active October 7, 2021 08:38
Cookie clicker stats
// Calculates the price per click per second taking into account synergies.
function potato() {
const result = {}
for (const me of Object.values(Game.Objects).sort((a,b) => a.id - b.id)) {
let synergyBoost = 0
if (me.name=='Grandma')
{
for (var i in Game.GrandmaSynergies)
{
@graffic
graffic / mssql_slow_monitor.py
Last active August 19, 2019 12:04
El-cheapo mssql slow query monitor
#!/usr/bin/env python
from datetime import datetime
from functools import wraps
from hashlib import sha1
from time import sleep
import os
import pymssql
import click
from sty import fg, rs
@graffic
graffic / AutofacModule.cs
Created May 24, 2019 10:38
Failed attempt to register all DBSets
public class AutofacModule:Module
{
private static readonly object[] NoParameters = new object[] { };
protected override void Load(ContainerBuilder builder)
{
var dbsetType = typeof(DbSet<>);
var registerMethod = new Func<ContainerBuilder, Func<IComponentContext, object>, IRegistrationBuilder<object, SimpleActivatorData, SingleRegistrationStyle>>(Af.RegistrationExtensions.Register<object>)
.Method.GetGenericMethodDefinition();
foreach (var property in typeof(ApplicationDbContext).GetProperties())
@graffic
graffic / test_something.py
Created April 26, 2019 07:34
Django tests show SQL queries
from django.test import TestCase
class TestSomething(TestCase):
def setUp(self):
from django.conf import settings
settings.DEBUG=True
def test_something(self):
pass
@graffic
graffic / fix_erlang.sh
Created June 23, 2018 09:15
Macports utils
#!/bin/bash
set -x
cd $MACPORTS/var/macports/sources/rsync.macports.org/release/tarballs/ports/
sed -i '' '/libGLU/d' ./lang/erlang/Portfile
portindex
// Run in console or as a snippet in Chrome
(function() {
const parseUs = x => parseFloat(x.replace(",",""));
const parseEu = x => parseFloat(x.replace(/[,.]/g, y => y == "," ? "." : ","))
const parsers = new Map([
[",", parseEu],
[".", parseUs]
]);
const matcher = /^([^\d]?)([\d\,\.]+\d\d)([^\n\d]?)(\nCredit|)/m;
const matchNode = x => matcher.exec(x.innerText);
@graffic
graffic / 0.10.1_full_services_pom.xml
Last active December 9, 2017 10:36
Druid 0.11 & 0.10.1 poms to compile with CDH 5.10.2
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Druid - a distributed column store.
~ Copyright 2012 - 2015 Metamarkets Group Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
@graffic
graffic / steam.md
Last active December 28, 2023 03:09
Downloading steam games from another computer/faster line

Framing the issue

With almost no bandwith at home, I needed a way to download DOOM that didn't involve blocking the home internet line for two days.

Approach

Using steamcmd you can use any computer to download steam games.

Downloading

  1. Install it
  2. Open it and loging with your username and password: login username password
@graffic
graffic / Dockerfile
Created August 17, 2017 07:08
Alpine, java8, druid, mysql docker image
FROM anapsix/alpine-java:8_server-jre
ENV DRUID_VERSION=0.10.0 \
ZOOKEEPER_VERSION=3.4.10 \
PATH=/usr/local/bin:${PATH}
# Prepare the container to install the software
RUN set -ex && \
apk upgrade --update && \
apk add --update curl mariadb mariadb-client supervisor && \