Skip to content

Instantly share code, notes, and snippets.

# 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 / 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`
@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 / 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' => '',