Skip to content

Instantly share code, notes, and snippets.

View Kwpolska's full-sized avatar

Chris Warrick Kwpolska

View GitHub Profile
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
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:
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)
class Ship {
public String name;
public int weight;
public Ship(String name_, int weight_) {
name = name_;
weight = weight_;
}
public String toString() {
@Kwpolska
Kwpolska / ext4ize.sh
Created May 8, 2016 11:23
ext3 → ext4 converter
#!/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
#!/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
@Kwpolska
Kwpolska / locale_printer.py
Created May 3, 2016 16:47
Locale Printer
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")
<?php
array(
'before_widget' => '<div class="panel panel-default panel-sidebar %1$s %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<div class="panel-heading"><h3 class="panel-title">',
'after_title' => '</h3></div><div class="panel-body">'
)
?>
<!-- If there is a title, it results in: -->
@Kwpolska
Kwpolska / git-ftp-bridge.py
Last active February 5, 2016 13:04
Git ↔ FTP bridge
#!/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
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)