Skip to content

Instantly share code, notes, and snippets.

@davelnewton
davelnewton / Exceptions.java
Last active November 27, 2016 14:53
Refactoring some Java
package com.davelnewton.exceptions;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import static java.lang.Math.abs;
@davelnewton
davelnewton / personalize.js
Created October 14, 2016 14:45 — forked from pamelafox/personalize.js
Javascript grammatical personalization library
/**
* A function that takes a template and grammatical options ('gender', 'person', 'name') and returns the computed string.
* See below for examples.
*
* See wikipedia for more on grammar:
* http://en.wikipedia.org/wiki/English_personal_pronouns
* http://en.wikipedia.org/wiki/Grammatical_conjugation
*/
function personalize(template, options) {
var GENDERS = ['neutral', 'female', 'male'];
const sinon = require('sinon')
function Example() {}
Example.prototype.someFunc1 = function () { return 42; }
Example.prototype.func = function (fn) { return fn(); }
const example = new Example()
console.log(example.func(example.someFunc1))
// >> 42
@davelnewton
davelnewton / dateFormat.js
Last active August 16, 2016 20:46
Date Formatting
function pluralize(dur, s) {
var ret = false;
if (dur > 0) {
ret = dur + ' ' + s;
if (dur > 1) {
ret += 's';
}
}
@davelnewton
davelnewton / createID.java
Last active August 14, 2016 17:38
Refactored
public static String createId() {
// Test by mocking `checkConfigs()` and make
// sure `generateRandomId()` is called
if (!checkConfigs()) {
return generateRandomId();
}
HttpURLConnection connection = accessProv();
try {
// Test in two ways:
package mygradeloops.java;
public class MyGradeLoopsJava {
public static void main(String[] args) {
for (int x = 1; x <= 20; x++) {
System.out.println("Please enter a number: ");
System.read.in(20);
System.out.println "Thank you.";
if (x == 10) continue;
System.out.println "Halfway there! Keep up the good work!";"
require 'memory_profiler'
report = MemoryProfiler.report do
h = {}
prng = Random.new
10000.times {
n1 = prng.rand(200)
n2 = prng.rand(200)
h[[n1, n2]] = prng.rand(200)
@davelnewton
davelnewton / 01-styles.less
Created August 5, 2015 20:55
Change UI element font size
@atom-ui-font-size: 10px;
html, body, .tree-view, .status-bar, .tab-bar .tab {
font-size: @atom-ui-font-size;
}
@davelnewton
davelnewton / gist:5d66db2b9d7b594e8212
Created July 11, 2015 19:56
Can't Dupe Date Issue
> yesterday = DateTime.yesterday()
=> Fri, 10 Jul 2015
> yesterday.beginning_of_week
=> Sun, 05 Jul 2015
> (yesterday.beginning_of_week - 1.days).beginning_of_week
=> Sun, 28 Jun 2015
@davelnewton
davelnewton / 00_see_blog_post.text
Last active August 29, 2015 14:22
CoffeeScript IIFEs
For the blog post at:
http://buckybits.blogspot.com/2015/06/coffeescript-iifes.html