This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foobar(number): | |
return "Number is %d" % number | |
class GenericFoo(object): | |
foo = None | |
def do_things(self): | |
print(self.foo(7)) | |
class CustomFoo(GenericFoo): | |
foo = foobar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
inp = list(range(1, 1001)) | |
needle = random.randrange(1, 1001) | |
p = 0 | |
q = len(inp) | |
pos = (p + q) // 2 | |
while inp[pos] != needle: | |
print(pos) | |
if inp[pos] > needle: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.NullPointerException | |
at org.eclipse.swt.widgets.TabFolder.gtk_switch_page(TabFolder.java:570) | |
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:2009) | |
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4723) | |
at org.eclipse.swt.internal.gtk.OS._gtk_widget_show(Native Method) | |
at org.eclipse.swt.internal.gtk.OS.gtk_widget_show(OS.java:14774) | |
at org.eclipse.swt.widgets.TabFolder.createItem(TabFolder.java:311) | |
at org.eclipse.swt.widgets.TabItem.createWidget(TabItem.java:123) | |
at org.eclipse.swt.widgets.TabItem.<init>(TabItem.java:75) | |
at org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock.createControl(BuildPathsBlock.java:228) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ship { | |
public String name; | |
public int weight; | |
public Ship(String name_, int weight_) { | |
name = name_; | |
weight = weight_; | |
} | |
public String toString() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Convert drive to ext4. | |
# License: CC0. | |
if [ "$1" = "" ]; then | |
echo "Which device?" | |
exit | |
fi | |
tune2fs -O extents,uninit_bg,dir_index $1 | |
fsck -f $1 | |
$EDITOR /etc/fstab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Automatically unzip any .zip files in ~/Downloads to the CWD. | |
Copyright © 2016, Chris Warrick. | |
Licensed under the 3-clause BSD license. | |
""" | |
import logging | |
import os | |
import time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locale | |
import datetime | |
sl = locale.setlocale | |
# Clear the file | |
f = open("NikolaDebug.txt", "w") | |
f.close() | |
def fancy_setlocale(*args, **kwargs): | |
f = open("NikolaDebug.txt", "a") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Git ↔ FTP bridge | |
# Takes incoming HTTP requests (from eg. GitHub or BitBucket webhooks), pulls a git repo, and sends it through FTP. | |
# Requires ncftp. | |
# I know shell=True is unsafe. This was thrown together in five minutes for a private project, and it runs in tmux. I don’t care. | |
# Copyright © 2016, Chris Warrick. | |
# Licensed under WTFPL. | |
from flask import Flask | |
import datetime | |
import subprocess |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
p = subprocess.Popen(['error-prone', 'thing'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
while p.poll() is None: | |
time.sleep(0.5) # prevent 100% CPU usage | |
if p.returncode != 0: | |
stdout, stderr = p.communicate() | |
print("The process failed with code {0}.\nstdout:\n{1}\nstderr:\n{2}".format(p.returncode, stdout, stderr) |