Skip to content

Instantly share code, notes, and snippets.

@SCdF
SCdF / margintest
Last active December 20, 2015 16:29
<!DOCTYPE html>
<html>
<head>
<title>Margin test</title>
</head>
<body>
<div id="one">
<h1>Lorum ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
@SCdF
SCdF / scratch.erl
Last active January 8, 2016 08:58
doc_by_place in Erlang
% Benchmarking code for REPL nicked and modified to remove module param from here:
% https://erlangcentral.org/wiki/index.php/Measuring_Function_Execution_Time
% Params: FnName, Params, Rounds, eg:
% TC(DeepGet, [DeepGet, [<<"userCtx">>, <<"name">>], Req], 100000).
% TC = fun(TC_F, TC_A, TC_N) when TC_N > 0 -> TC_L = tl([begin {TC_T, _Result} = timer:tc(TC_F, TC_A), TC_T end || _ <- lists:seq(1, TC_N)]), TC_Min = lists:min(TC_L), TC_Max = lists:max(TC_L), TC_Med = lists:nth(round((TC_N - 1) / 2), lists:sort(TC_L)), TC_Avg = round(lists:foldl(fun(TC_X, TC_Sum) -> TC_X + TC_Sum end, 0, TC_L) / (TC_N - 1)), io:format("Range: ~b - ~b mics~nMedian: ~b mics ~nAverage: ~b mics~n", [TC_Min, TC_Max, TC_Med, TC_Avg]), TC_Med end.
% Made "cmd+v futon-ready" with the following disgusting display of black magic
% cat scratch.erl | sed 's/%.*//' | sed 's/"/\\"/'g | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' | pbcopy
fun ({Doc}, {Req}) ->
SafeGetValue = fun(Key, PropListMaybe, Default) ->
@SCdF
SCdF / medic-webapp.sublime-project
Created January 27, 2016 17:04
To remove compiled resources from ST searches etc
{
"folders":
[
{
"path": ".",
"folder_exclude_patterns": ["static/dist"]
}
]
}
@SCdF
SCdF / snippet.txt
Created February 22, 2016 17:09
extending sigs in JS
// NB: all three of these will have the same comment documentation
var minimumSig = function(start, mid, end) = {
var newMid;
if (arguments === 3) {
newMid = mid;
} else if (arguments === 4) {
newMid = arguments[2];
end = arguments[3];
} else {
@SCdF
SCdF / snippet.js
Created February 22, 2016 17:10
Extending a sig
// NB: all three of these will have the same comment documentation
var minimumSig = function(start, mid, end) = {
var newMid;
if (arguments === 3) {
newMid = mid;
} else if (arguments === 4) {
newMid = arguments[2];
end = arguments[3];
} else {
@SCdF
SCdF / send-message.js.patch
Created April 29, 2016 18:55
send-message refactoring
diff --git a/static/js/modules/send-message.js b/static/js/modules/send-message.js
index 7ffd075..3ce2443 100644
--- a/static/js/modules/send-message.js
+++ b/static/js/modules/send-message.js
@@ -21,7 +21,7 @@ var _ = require('underscore'),
};
var validatePhoneNumber = function(data) {
- if (data.everyoneAt) {
+ if (data.doc.everyoneAt) {
@SCdF
SCdF / touch-patientless-reports.js
Last active September 23, 2016 13:20
touch-patientless-reports.js
#!/usr/bin/env /srv/software/medic-core/v1.6.1/x64/bin/node
var http = require('http');
var request = function(options, postData, callback) {
if (!callback) {
callback = postData;
postData = null;
}
@SCdF
SCdF / keybase.md
Created October 5, 2016 09:15
keybase.md

Keybase proof

I hereby claim:

  • I am scdf on github.
  • I am scdf (https://keybase.io/scdf) on keybase.
  • I have a public key ASAKl-URAtBD4HZHO_6e0zYOWs-qZ1wzdZfw64VZF7WibAo

To claim this, I am signing this object:

@SCdF
SCdF / main.rs
Created October 8, 2016 17:37
Hideous knockaround in rust
fn next_prime(given: &Vec<i32>) -> Option<i32> {
fn is_prime(given: &Vec<i32>, i: i32) -> bool {
given.iter().all(|&x| i % x != 0)
}
if let Some(next) = given.iter().last() {
let mut next = next + 1;
while !is_prime(given, next) {
next += 1;
@SCdF
SCdF / random-quality-test.js
Created June 16, 2017 14:32
Attempting to work out which algorithm to use
var randomBytes = require('crypto').randomBytes;
var RANDOM_GENERATORS = {
'randomUInt8Crypto': function() {
return randomBytes(1).readUInt8();
},
'randomUInt8Old': function() {
return 0 | Math.random() * 256;
}
};