Skip to content

Instantly share code, notes, and snippets.

@slashmili
slashmili / influx_reporter.ex
Last active September 14, 2021 12:43
Telemetry Metrics Reporter for Fluxter & InfluxDB
defmodule Metrics.InfluxReporter do
@moduledoc """
A reporter that writes the events in the influx_writer
This Reporter ignores the metric type and simply writes the report to influxdb
This GenServer could be used in a Supervisor like:
children = [
{Metrics.InfluxReporter, metrics: metrics(), influx_writer: &MyApp.Fluxter.write/3}
]

Keybase proof

I hereby claim:

  • I am slashmili on github.
  • I am slashmili (https://keybase.io/slashmili) on keybase.
  • I have a public key whose fingerprint is D045 5F33 140B A5B3 D2C8 6CDF 04A0 6367 E4E2 4559

To claim this, I am signing this object:

@slashmili
slashmili / sync_call_on_async.ex
Created December 14, 2016 10:09
Sample GenServer that provides sync call over async function
defmodule SyncCallonAsync do
use GenServer
def start_link do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
def init(_) do
{:ok, %{pending: []}}
end
@slashmili
slashmili / meoow.rb
Last active August 29, 2015 14:14
RTanque-feb-2015
require 'time'
class Meoow < RTanque::Bot::Brain
NAME = 'Meoow'
include RTanque::Bot::BrainHelper
CORNERS = [:NW, :NE, :SE, :SW]
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.0
SWITCH_CORNER_TICK_RANGE = (600..1000)
def tick!
class Meeow < RTanque::Bot::Brain
NAME = 'meeow'
include RTanque::Bot::BrainHelper
@health = 100.00
def tick!
command.heading = sensors.heading + Math::PI/rand
target = sensors.radar.first
if target and target[:name] != NAME
command.turret_heading = target[:heading]
command.speed = 3
@slashmili
slashmili / fatpacker.rb
Created October 31, 2012 09:12
pack your dependencies onto your script file
module FatPacker
end
=begin
doctest: FatPacker
>> FatPacker.xyz
=> ''
=end
@slashmili
slashmili / instagram-unshredder.py
Created April 10, 2012 15:42
Instagram Engineering Challenge: The Unshredder
#find out more http://instagram-engineering.tumblr.com/post/12651721845/instagram-engineering-challenge-the-unshredder
from PIL import Image
from collections import defaultdict
import operator
def unshred(file_name, NUMBER_OF_COLUMNS, diff, num_check_points=0):
"""
@params diff base on this value we decide if two pixels are beside each other or not
@params num_check_points how many times we check pixels across shreds
"""
@slashmili
slashmili / lets_go_sleep.py
Created March 16, 2012 14:11
Milad's Dream
import dream
import time
import threading
class Milad ( threading.Thread ):
def run ( self ):
try :
#don't fear ! if you want wake up just want
#after that time.Wakeup exception will be happen
time.sleep(dream.ONE_YEAR)
[a2billing]
include => a2billing_callingcard
include => a2billing_monitoring
include => a2billing_voucher
[a2billing_callingcard]
; CallingCard application
exten => _X.,1,NoOp(A2Billing Start)
CREATE OR REPLACE FUNCTION hex2dec(text)
RETURNS bigint LANGUAGE SQL AS
$$
SELECT sum(digit * 16 ^ (length($1)-pos)) ::bigint
FROM (SELECT case
when digit between '0' and '9' then ascii(digit) - 48
when digit between 'A' and 'F' then ascii(digit) - 55
end,
pos as i
FROM (SELECT substring(c from x for 1), x