Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
abolibibelot / ohai
Last active January 3, 2016 12:28
Criteo programming ad in lolcode
HAI
BTW this kinda follows the lolcode 1.2 spec http://lolcode.org/1.2_spec.html
I HAZ A ANSWER
I HAZ A INDEX
BTW defining a function
HOW IZ ASK YR QUESTION
VISIBLE QUESTION
GIMME RESPONZ
try unsafe(PVS) of
Res -> Res
catch
A:B -> lager:error("Problem:~p stacktrace:~p",[[A,B], erlang:get_stacktrace()]),
case {A,B} of
{exit,_} -> exit(B);
{error,_} -> error(B);
{exception,_} -> throw(B)
end
end.
@abolibibelot
abolibibelot / gist:6359206
Last active December 21, 2015 20:09
This snippet traps double clicks in a Sublime Text plugin. I kid you not.
trapping_views = {VIEW_BREAKPOINT: dbg.callbacks.on_breakpoints_dblclick,VIEW_STACK: dbg.callbacks.on_stack_dblclick}
class UnityTrapDoubleclickCommand(TextCommand):
def run_(self, args):
print 'on dbl click'
special_handler = trapping_views.get(self.view.name(),None)
print args
if not special_handler is None:
line = self.view.line(self.view.sel()[0])
Catastrophic failure: System.InvalidOperationException: Hashtable.Enumerator: snapshot out of sync.
at System.Collections.Hashtable+Enumerator.FailFast () [0x00000] in <filename unknown>:0
at System.Collections.Hashtable+Enumerator.MoveNext () [0x00000] in <filename unknown>:0
at System.Net.EndPointListener.Close () [0x00000] in <filename unknown>:0
at System.Net.EndPointManager.RemoveEndPoint (System.Net.EndPointListener epl, System.Net.IPEndPoint ep) [0x00000] in <filename unknown>:0
at System.Net.EndPointListener.CheckIfRemove () [0x00000] in <filename unknown>:0
at System.Net.EndPointListener.RemovePrefix (System.Net.ListenerPrefix prefix, System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
at System.Net.EndPointManager.RemovePrefixInternal (System.String prefix, System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
at System.Net.EndPointManager.RemoveListener (System.Net.HttpListener listener) [0x00000] in <filename unknown>:0
at System.Net.HttpListener.Clo
//Works
public async void Write(byte[] buffer)
{
var len = buffer.Length;
Size += len;
await _stream.WriteAsync(buffer, 0, len);
}
var bytes = Encoding.UTF8.GetBytes(item);
blob.Write(bytes);
@abolibibelot
abolibibelot / gist:5859432
Created June 25, 2013 15:31
naive scikitlearn benchmark
fname = '/Users/yann/temp/products.txt'
#vec = CountVectorizer(input='content',analyzer=str.split,tokenizer=None)
features = []
y = []
for line in open(fname,'r'):
c,f = line.split(',',1)
features.append(f)
y.append(c)
print datetime.now(),"splitting data sets"
pmap(Mapper,XS,_) when length(XS) =< 2-> %async not really useful here
[Mapper(X) || X <-XS];
pmap(Mapper,XS,Timeout)->
Myself = self(),
[spawn(fun()-> Myself ! Mapper(X) end) || X <- XS],
map_receive(length(XS),[],Timeout).
map_receive(0,Acc,_) -> Acc;
map_receive(N,Acc,Timeout)->
receive
4> A = integer_to_list(42).
"42"
5> [C+1 || C <- A].
"53"
6> [C+1000 || C <- A].
[1052,1050]
void Main()
{
var chrono = new Stopwatch();
chrono.Start();
Syntouze res = null;
for (var i=0; i < 1000; i++)
res = (from taz in new[]{0,1,2}
from pieds in Enumerable.Range(1,10 - taz)
from gifles in Enumerable.Range(1,10 - pieds - taz)
let touze = new Syntouze{Taz=taz,Pieds=pieds,Gifles=gifles}
void Main()
{
var res = (from taz in new[]{0,1,2}
from pieds in Enumerable.Range(1,10 - taz)
from gifles in Enumerable.Range(1,10 - pieds - taz)
let productivite = gifles * 50 + pieds * 100 + taz * 200
let bugs = gifles * 2 + pieds * 5 + taz * 11
where bugs <= 50
select new []{taz,pieds,gifles,bugs,productivite})
.MaxOf(o => o[4]);