Skip to content

Instantly share code, notes, and snippets.

@chausen
chausen / gist:cceb2397b8cd7d6c3b2ca27442148ee2
Created December 31, 2017 16:24
React Clock List with Add
class Clock extends React.Component {
constructor(props) {
super(props);
this.state = {date: new Date()};
}
componentDidMount() {
this.timerID = setInterval(
() => this.tick(),
1000
@chausen
chausen / gist:e2c548b6b9e80fe943c2b1d1d2089d2e
Created March 11, 2018 17:27
Regex phone number formatting in C#
using System;
using System.Text.RegularExpressions;
public class Kata
{
public static string CreatePhoneNumber(int[] numbers) =>
new Regex("(...)(...)(....)").Replace(String.Concat(numbers), "($1) $2-$3");
}
public class Kata
{
public static string CreatePhoneNumber(int[] numbers)
{
return long.Parse(string.Concat(numbers)).ToString("(000) 000-0000");
}
}
def reverse_word_order(text):
newText = ""
position = 0
for t in text:
if t == " ":
newText = text[position:text.find(t, position)] + " " + newText
position = text.find(t, position) + 1
newText = text[position:] + " " + newText
@chausen
chausen / debug-stdin.py
Last active March 24, 2021 02:56
Using pdb to debug a python file when using input redirection
import sys
s = input()
# pdb uses stdin to be interactive; this switches stdin to be the teletype interface
# (terminal and keyboard) after getting the redirected input
sys.stdin = open("/dev/tty")
breakpoint()