Skip to content

Instantly share code, notes, and snippets.

@LoganBarnett
LoganBarnett / gulpfile.js
Last active August 29, 2015 14:26
Gulpfile for hosting some standard static assets
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var DIST = 'dist';
@LoganBarnett
LoganBarnett / promises_and_partial.js
Created June 25, 2015 22:57
Usage of partial application.
var getMdmCodes = function() {
var requests = [
service.getProductGroupCodes
, service.getProductTypeCodes
, service.getStatusCodes
, service.getCountryCodes
, _.partial(service.getParties, 'shipper')
, _.partial(service.getParties, 'consignee')
, _.partial(service.getTariffPointsForUser, {tariffPointType: 'origin'})
, _.partial(service.getTariffPointsForUser, {tariffPointType: 'destination'})
@LoganBarnett
LoganBarnett / hellplusplus.cpp
Last active August 29, 2015 14:23
Post incremental hell
int foo = 0;
int bar = foo++;
print(foo); // <= ?
print(bar); // <= ?
// 5,000,000 ints of 10
std::vector<int> stuff(5000000, 10);
// do you know what's in the var 'it'? Is it safe to copy lots and lots?
for (std::vector<int>::iterator it = stuff.begin(); it != stuff.end(); it++) {
@LoganBarnett
LoganBarnett / three-adapter.js
Last active August 29, 2015 14:20
Logan's flailing re: a scene adapter using FP
const move = (obj) => {
if(obj.moving) {
const newLocation = new Vector3(
obj.transform.x + obj.speed.x
, obj.transform.y + obj.speed.y
, obj.transform.z + obj.speed.z
);
var newTransform = new Transform(obj.transform, {location: newLocation}) * Time.delta});
return new SceneObj(obj, {transform: newTransform});
}
Maybe<Email, Exception> UpdateEmail(Maybe<Email, Exception> m) {
m = ValidateEmail(m);
m = UpdateUserEmail(m);
m = SendVerificationEmail(m);
return m;
}
@LoganBarnett
LoganBarnett / make_guid.coffee
Last active August 29, 2015 14:08
Coffeescript GUID generator
makeGuid = () ->
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) ->
r = Math.random() * 16 | 0
if c == 'x'
v = r
else
v = r = (r&0x3|0x8)
return v.toString(16)
)
@LoganBarnett
LoganBarnett / .bash_profile
Last active August 29, 2015 14:08
Misc nifty bash profile settings
# standard ls colors
alias ls="ls -G"
# grep highlights your search matches
alias grep="grep --color=auto"
# makes the prompt show exit code, sends an alert (beep), shows the time the prmopt was shown, and the current path. $ is on the next line.
# also colored pink to make easier to spot
export EXIT_STATUS_VAR='$?'
export PS1="\[\e[35m\]\a$(echo $EXIT_STATUS_VAR):\j*\@ \u@\h \w\n\$ \[\e[0m\]"
export PS2=""
@LoganBarnett
LoganBarnett / eye-ten.cs
Last active July 15, 2016 18:38
i is always 10
for (int i = 0; i < 10; i++) {
UniThread.EnqueueAsyncUnityTask(
gameObject.name + i, // name the job after my game object
() => {
var result = EncryptAndSave( texBytes, i );
//var result = BuildLargeMesh();
return result; // if your task doesn't have anything to return, just return null
},
(result) => { Debug.Log ("///////// Here"); Display( result as byte[] ); }, // executes on the main thread, can touch Unity. This argument is optional.
@LoganBarnett
LoganBarnett / CSharpDumpScope.cs
Created August 1, 2013 17:27
An example of silliness if C#'s scoping rules.
if(true) {
var bar = "bazz";
DoSomethingWithBar(bar);
}
var bar = "qux"; // oh noes! You already declared bar even though you can't get to it and it's out of scope.
@LoganBarnett
LoganBarnett / ssh_copy_id
Created May 7, 2013 16:46
Copies your public key to a remote location.
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/id_rsa.pub"
if [ "-i" = "$1" ]; then