Skip to content

Instantly share code, notes, and snippets.

@shitpoet
shitpoet / create_order.php
Created December 3, 2015 19:09
Programmatically create order, add (variative) products from cart to it, change status to `processing` and empty cart. Wordpress, WooCommerce 2.4.
$address = array(
'first_name' => $customer_name,
'last_name' => '',
'company' => '',
'email' => $customer_email,
'phone' => $customer_phone,
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
@shitpoet
shitpoet / north.rb
Created December 8, 2015 13:30
Script to automatically generate migrations for Ruby on Rails, based on changes in schema.rb file
#!/usr/bin/env ruby
require 'fileutils'
help = view = gen = apply = edit = del = restore = false
letters = ''
ARGV.each do |arg|
if arg[1] == '-'
help ||= arg == '--help'
view ||= arg == '--view'
@shitpoet
shitpoet / lowbat.sh
Created December 17, 2015 19:23
Hibernate on low battery level - should be called from cron as "*/5 * * * * /home/user/bin/lowbat.sh"
#!/bin/bash
CRITICAL=5
bat_info=`acpi -b`
level=`echo $bat_info | grep -o [0-9]*% | sed s/%//`
#echo $level
if [ ! $level ]
then
exit
fi
discharging=`echo $bat_info | grep Discharging`
# support sliding window maximum in linear time
srand(123)
n = 9
k = 3
m = n-1
a = (0..m).to_a
for i in 0..m do
#a[i] = (rand()*10).floor()
@shitpoet
shitpoet / error.js
Created January 17, 2017 04:10
Reimplementation of default uncaught exception handler of nodejs
// reimplementation of default uncaught exception handler of nodejs v7.2 in js
//
// produces the same output as default handler of nodejs
// handles inline source maps with sinlge source (as V8 does)
// does not handle non-inline source maps or maps with multiple sources
//
// shitpoet@gmail.com, public domain
"use strict";
@shitpoet
shitpoet / haml.lua
Created April 7, 2017 19:34
basic HAML lexer for TextAdept
-- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
-- HAML LPeg lexer.
local l = require('lexer')
local token, word_match = l.token, l.word_match
local P, R, S, V = lpeg.P, lpeg.R, lpeg.S, lpeg.V
local M = {_NAME = 'haml'}
-- Whitespace.
@shitpoet
shitpoet / jikl.ahk
Created May 19, 2018 08:58
Autohotkey script to redirect navigation keys to home row
; redirect nav keys to home row
; alt+arrows to jikl and some more
; !r::Reload
; redirect alt+keys saving other mods
Redirect(key) {
if GetKeyState("Shift", "D")
if GetKeyState("Ctrl", "D")
Send +^{%key%}
##.pagedlist_item:has(a[target="_blank"] > p:has-text(/\sby\s/))
##.pagedlist_item:has(a[target="_blank"] > p:has-text(/\sad\s\sby/))
##.pagedlist_item:has(a[target="_blank"] > p:has-text(/\spromoted\s\sby/))
@shitpoet
shitpoet / add-to-recent
Last active January 9, 2019 20:00
Add a file to GNOME's recent files list
#!/bin/bash
f=~/.local/share/recently-used.xbel
s=`cat $f`
t=`echo "$s" | sed 's/<\/xbel>//g'`
target="$@"
dt=`date '+%Y-%m-%dT%H:%M:%SZ'`
mime=`file -b --mime-type "$target"`