Skip to content

Instantly share code, notes, and snippets.

View mxriverlynn's full-sized avatar
🏳️‍🌈
coding while trans

River Lynn Bailey mxriverlynn

🏳️‍🌈
coding while trans
View GitHub Profile
@mxriverlynn
mxriverlynn / 1.js
Last active April 15, 2020 14:27
Standard deviation, in JavaScript
var sum = values.reduce(function(sum, value){
return sum + value;
}, 0);
var avg = sum / data.length;
@mxriverlynn
mxriverlynn / webcam.css
Last active March 30, 2020 12:05
webrtc webcam in 20 lines
body {
margin: 0px;
padding: 0px;
}
#player {
width: 100%;
height: 100%;
}
@mxriverlynn
mxriverlynn / 1_overlap.js
Last active January 21, 2020 13:59
checking for date range overlap
// this function takes an array of date ranges in this format:
// [{ start: Date, end: Date}]
// the array is first sorted, and then checked for any overlap
function overlap(dateRanges){
var sortedRanges = dateRanges.sort((previous, current) => {
// get the start date from previous and current
var previousTime = previous.start.getTime();
var currentTime = current.start.getTime();
@mxriverlynn
mxriverlynn / 720p.sh
Created September 8, 2012 16:31
Size an OSX window to 720p (1280x720)
#!/usr/bin/env bash
echo "Setting $1 bounds to 720p"
# 720p is 1280x720.
# Bounds is startX, startY, endX, endY. Adjust size from starting position to account for this
osascript -e "tell application \"$1\" to set the bounds of the first window to {250, 220, 1530, 940}"
# activate the app, to bring it to the front
osascript -e "tell application \"$1\" to activate"
@mxriverlynn
mxriverlynn / 1-layout.html
Created June 21, 2011 03:06
render backbone views with jquery templates
<html>
<head>
<script src="jquery-1.6.1.min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<script src="underscore-min.js"></script>
<script src="backbone-min.js"></script>
<script src="example.js"></script>
<style type="text/css">
fieldset {
// my-repl.js
var repl = require("repl");
var replServer = repl.start({
prompt: "my-app > ",
});
replServer.context.foo = "bar";
@mxriverlynn
mxriverlynn / 1.php
Last active October 28, 2019 13:53
laravel and kendo ui php
<?php
class HomeController extends BaseController {
public function showWelcome()
{
$users = User::all();
return View::make('hello')->with('users', $users);
}
@mxriverlynn
mxriverlynn / mongoid_document_changes_with_embedded.rb
Created June 27, 2011 17:17
get changes to mongoid document, including embedded documents
module Mongoid
module Document
def changes_with_embedded
field_data = get_previous_changes_for_model(self)
embedded_data = get_embedded_document_changes(self)
unless embedded_data.empty?
field_data.merge embedded_data
end
end
@mxriverlynn
mxriverlynn / 1-referencing.js
Created July 19, 2011 13:57
using an event aggregator with backbone
MedicationView = Backbone.View.extend({
events: {
"click #edit": "editMedication"
},
editMedication: function(){
var editView = new AddEditView({model: this.model});
editView.render();
}
});
@mxriverlynn
mxriverlynn / audio-duration.js
Last active April 10, 2019 11:19
File Info With File API
$("#my-audio").on("canplaythrough", function(e){
var seconds = e.currentTarget.duration;
var duration = moment.duration(seconds, "seconds");
var time = "";
var hours = duration.hours();
if (hours > 0) { time = hours + ":" ; }
time = time + duration.minutes() + ":" + duration.seconds();
$("#duration").text(time);