Skip to content

Instantly share code, notes, and snippets.

export function getUserByEmail(mysql: MySQL, email: string) {
return await mysql.select(
"SELECT id, email, ... FROM users WHERE email = :email",
{ email: email }
);
}
describe("ForgotPassword", () => {
test("it sends email when reset is requested", async () => {
const users = new UsersInMemory();
const forgotPassword = new ForgotPassword(users);
// ...
});
});
@hansott
hansott / component.jsx
Last active April 12, 2019 14:20
redux-logger for useReducer
import { logger } from "./logger";
import React, { useReducer } from "react";
const reducer = (state, action) => state;
const initialState = {};
export const Component = () => {
const [state, dispatch] = useReducer(logger(reducer), initialState);
return <div></div>;
@hansott
hansott / keybase.md
Created August 1, 2016 08:05
keybase.md

Keybase proof

I hereby claim:

  • I am hansott on github.
  • I am hansott (https://keybase.io/hansott) on keybase.
  • I have a public key ASBaddsO2x5jvRIiL-ZL0phJiTgZq9kLLVljMuEG8Gq4Xwo

To claim this, I am signing this object:

@hansott
hansott / Makefile
Created March 21, 2016 08:40 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@hansott
hansott / subl.sh
Last active September 1, 2015 17:01
Use sublime as "subl" in your terminal
echo 'export PATH="$HOME/bin:$PATH";' >> ~/.bash_profile
mdkir ~/bin
ln -s ~/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl ~/bin/subl
@hansott
hansott / app.js
Created May 21, 2015 07:25
Global socket.io in an application
var http = require('http');
var sockets = require('./sockets');
var server = http.createServer(app);
sockets.connect(server);
sockets.emit('event', { message: 'This is an event!' });
@hansott
hansott / Instructions
Last active August 29, 2015 14:19
Gitlab Web Hook using Node.js
1. `$ npm install gitlabhook`
2. Copy webhook.js in directory
3. Create systemd service, instructions can be found here: https://github.com/rolfn/node-gitlab-hook#installation-hints-for-linux
4. Or test using `node webhook.js`
@hansott
hansott / TimeAgo.swift
Created December 26, 2014 09:02
Time ago function swift ios cocoa
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
} else if (components.year >= 1){
@hansott
hansott / edit.cshtml
Created December 15, 2014 21:48
Disable browser caching in razor templates (ASP.NET MVC)
@{
var random = new Random();
int r = random.Next(1000);
}
<p><img src="@Url.Content("~/images/records/" + Model.id + ".jpg")?time=@r" alt="Album cover" class="img-responsive" /></p>