Skip to content

Instantly share code, notes, and snippets.

View ginahagg's full-sized avatar
🎯
Focusing

Gina Hagg ginahagg

🎯
Focusing
  • Samsung Research America
  • Mountain View, CA
View GitHub Profile
@WhatIThinkAbout
WhatIThinkAbout / BernoulliThompsonSocket.py
Last active January 15, 2021 02:59
Thompson sampling on a Bernoulli probabilistic power socket.
class BernoulliThompsonSocket( PowerSocket ):
def __init__( self, q ):
self.α = 1 # the number of times this socket returned a charge
self.β = 1 # the number of times no charge was returned
# pass the true reward value to the base PowerSocket
super().__init__(q)
def charge(self):
-module(assert_timers).
-export([start_trace/0, stop_trace/0]).
-export([no_timers/1, has_timer/1]).
%% @doc use a dbg handler to track active timers; see http://stackoverflow.com/a/4059587/8446
start_trace() ->
ets:new(timer_trace, [public, named_table, bag]),
Fun = fun({'trace', Pid, 'call', {erlang, send_after, [Time, Dest, Msg]}} = _Msg, State) ->
lager:debug("~p erlang:send_after(~p, ~p, ~p)", [Pid, Time, Dest, Msg]),
State;
@honake
honake / adstock.py
Last active November 17, 2022 06:54
Calculate the optimal Ad Stock
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def broadbent_adstock(grp, r):
adstock = np.zeros(len(grp))
adstock[0] = grp[0]
for i in range(1,len(grp)):
adstock[i] = grp[i] + r*adstock[i-1]
return adstock
@stolen
stolen / timetop.erl
Created January 18, 2018 16:08
top processes by scheduled time
-module(timetop).
-export([top/2]).
top(Duration, Count) ->
OldPrio = erlang:process_flag(priority, high),
Result = scheduled_time_top(Duration),
erlang:process_flag(priority, OldPrio),
lists:sublist(Result, Count).
@yang-wei
yang-wei / destructuring.md
Last active February 20, 2024 04:40
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
@pocketkk
pocketkk / Swift - Sort by date.swift
Created July 27, 2014 17:51
Swift - Sort objects by date field
@objc(Note)
class Note: NSManagedObject {
@NSManaged var content: String
@NSManaged var date: NSDate
@NSManaged var business: Business
@NSManaged var coldcall: ColdCall
@NSManaged var contact: Contact
}
@joeljacobson
joeljacobson / CRDT.md
Created February 21, 2014 19:32
CRDT Examples

Bucket Types

Bucket types were added in 2.0 to eliminate the need for each bucket to have it's own custom bucket properties. If buckets share the same custom bucket properies, a bucket type can be created for them.

Creating Bucket Types

To get started, you'll want to create a new bucket type with:

riak-admin bucket-type create  
@pbogden
pbogden / README.md
Last active April 26, 2019 19:23
D3 + OpenLayers

This D3 + OpenLayers example mirrors as closely as possible Mike Bostock's D3 + Leaflet example. See his example for an explanation.

Primary differences:

  1. OpenLayers uses Mercator (EPSG:4326) by default, which appears distorted (for example). It's easy to switch to "Spherical Mercator" (EPSG:900913), but then you need to be careful to convert lon/lat to the OpenLayers default x/y coordinates in meters.

  2. As in this example, the code below uses an OpenLayers Vector Layer in place of Leaflet's overlay pane. Whereas Leaflet requires repositioning only on zoom, OpenLayers needs repositioning for both zoom and pan. This makes it easier to size the SVG with OpenLayers -- it need only fit the viewport, as long as you're willing to wait for clipped features to be drawn after pan events. Fo

@DimitryDushkin
DimitryDushkin / new_gist_file
Created May 7, 2013 12:01
Erlang get current time in milliseconds
-spec get_timestamp() -> integer().
get_timestamp() ->
{Mega, Sec, Micro} = os:timestamp(),
(Mega*1000000 + Sec)*1000 + round(Micro/1000).