Skip to content

Instantly share code, notes, and snippets.

@sck
sck / free.c
Created August 23, 2012 18:19
Show free memory on OS X
/*
* free.c - show free memory on OS X
* The api query code was extraced from Apple's vm_stat.c
* To compile: gcc -o free free.c
* Output: <byte count> <human readable bytecount>
*/
#include <stddef.h>
#include <stdlib.h>
> library(forecast)
> train = read.csv("c.csv")
> T<-train[which(train$name == 'btc'), ]
> Train<-T[ with(T, order(ts)),]
> head(Train)
# name ts usd_value volume
# 1 btc 1.558271e+12 7912.8 23649292230
# 15 btc 1.558272e+12 7955.9 23741378790
# 29 btc 1.558272e+12 7940.0 23816540813
# 43 btc 1.558272e+12 7942.9 23891912844
@sck
sck / perceptual_loss.py
Last active May 6, 2018 05:45
perceptual loss: VGG + mse
def perceptual_loss(x):
m_vgg(opt_img_v)
outs = [V(o.features) for o in sfs]
losses = [gram_mse_loss(o, s) for o,s in zip(outs, targ_styles)]
cnt_loss = F.mse_loss(outs[3], targ_vs[3])*1000000
style_loss = sum(losses)
return cnt_loss + style_loss
@sck
sck / makeAnyPdfSearchable.rb
Created June 24, 2012 11:23
Use ScanSnap's 'Scan to Searchable PDF' even with PDFs not created by ScanSnap
#! /usr/bin/env ruby
require 'tmpdir'
def fixed?(fn) fn =~ /\.searchable\.pdf/; end
def searchable_fn(fn)
return fn if fixed?(fn)
"#{File.dirname(fn)}/#{File.basename(fn, File.extname(fn))}.searchable.pdf"
end
fn describe<F: FnOnce()>(message: &str, func: F) {
println!("{}", message);
func();
}
fn it<F: FnOnce()>(message: &str, func: F) {
println!(" - {}", message);
func();
}
@sck
sck / sarcasm.rb
Last active December 22, 2015 18:39
Super awesome recreative assembler. Execute with ruby and pipe into nasm
$pushed = []
def push(*args) $pushed = args; args.map {|r| "push #{r}" } end
def pop_pushed; $pushed.reverse.map {|r| "pop #{r}" } end
puts DATA.read.gsub(/^\s*jmp\s*[^\n]*/, '%error "Dijkstra said: No!"').gsub(/=([^\n]*)/) {|c| (eval $1).join("\n ") }
__END__
BITS 64
section .text
global math
@sck
sck / wasfuntowritebutwouldntreallyuse.cpp
Created August 10, 2013 21:41
A little uneccessary function that detects PIC vs no-pic from looking at its own opcodes generated by the compiler. Will only work with some compilers.
constexpr uchar I_REX_B_41 = 0x41;
constexpr uchar I_REX_W_48 = 0x48;
constexpr uchar I_REX_WXB_4b = 0x4b;
constexpr uchar I_REX_WRXB_4f = 0x4f;
// INTEL: Opcodes
constexpr uchar I_PUSH_BP_55 = 0x55;
constexpr uchar I_LEA_8d = 0x8d;
constexpr uchar I_MOV_r8_rm8_8a = 0x8a;
constexpr uchar I_MOV_r64_r64_8b = 0x8b;
@sck
sck / gist:6187509
Created August 8, 2013 18:48
c&p progress estimation
// calculate time left if we're more than 10% done
NSString *timeString = nil;
float percentLeft = (float)([theCanvas eventCount]-[theCanvas currentPlaybackEvent])/(float)[theCanvas eventCount];
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
if( percentLeft < 0.9f && now-_lastTimeWeEstimated > 5.0 ) {
_lastTimeWeEstimated = now;
NSTimeInterval timeLeft = (now-_exportStartTime)*(percentLeft/(1.0f-percentLeft));
int hours = timeLeft/(60.0*60.0);
timeLeft -= (double)hours*60.0*60.0;
int mins = timeLeft/60.0;
@sck
sck / expand_ecss.js
Last active December 17, 2015 08:41
Minimal alternative over using sass/less
function expand_ecss(s) {
var properties_to_be_prefixed = ["transform",
"transform-origin", "tap-highlight-color", "ruby-position",
"transition-duration", "transition-property", "transition",
"justify-content",
"animation-fill-mode", "align-self", "align-items", "box-sizing",
"appearance", "box-shadow", "animation"]
var specific = {
background: ["linear-gradient"],
display: ["flex"],
@sck
sck / gist:3965569
Created October 27, 2012 18:15
Image character separation
i = Import["http://i.stack.imgur.com/Ta5wf.png"]
ws = WatershedComponents[i];
ColorCombine[{Image[ws, "Bit"], i, i}]
ImageTake[i, Sequence @@ Reverse@Transpose@Last[#]] & /@ ComponentMeasurements[ws, "BoundingBox"]