Skip to content

Instantly share code, notes, and snippets.

@egonSchiele
egonSchiele / Timer.hs
Created July 16, 2013 02:00
Drawing timer in Haskell
import Control.Concurrent
import System.Process
import System.Environment
say str = system $ "say '" ++ str ++ "'"
timer :: Int -> IO ()
timer 1 = do
say "one minute left! oh crap!"
threadDelay $ 30 * 1000 * 1000
import Control.Applicative
import Github.Gists
import Github.Users.Followers
import System.Directory
import Control.Monad
import qualified Data.Set as S
import Text.Printf
import System.Process
import System.IO.Unsafe
@egonSchiele
egonSchiele / crazy.rb
Created July 29, 2013 05:10
can't kill this
trap("SIGINT") do
puts "goodbye!"
# exit
end
while true
end
@egonSchiele
egonSchiele / generate_valid_isbn.rb
Created August 15, 2013 20:29
Generate a valid ISBN number in ruby
def generate_valid_isbn
prefix = 978.to_s # must be 978 or 979
registration_group_element = rand(10).to_s
registrant_element = (rand(90000) + 10000).to_s
publication_element = (rand(900) + 100).to_s
_isbn = prefix + registration_group_element + registrant_element + publication_element
check_digit = 0
i = 0
_isbn.each_char do |letter|
i+= 1
@egonSchiele
egonSchiele / pretty_hive.rb
Created September 6, 2013 00:46
Display a bunch of data from a hive table in a pretty HTML table
#!/usr/bin/env ruby
require 'tempfile'
def make_row cols, style=""
"<tr style='#{style}'><td>" + cols.join("</td><td>") + "</td></tr>"
end
if ARGV.empty?
puts %{
Usage: #{$0} [file] where file has col list for a hive table, then a blank line, then some sample rows
% my training data.
% so if x > 3 || x < 7, y = 1, otherwise y = 0.
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
y = [0, 0, 0, 1, 1, 1, 0, 0, 0, 0];
% instead of theta' * x, I'm trying to create
% a non-linear decision boundary.
function result = h(x, theta)
result = sigmoid(theta(1) + theta(2) * x + theta(3) * ((x - theta(4))^2));
end
@egonSchiele
egonSchiele / linear_regression_with_fminunc.m
Created March 9, 2016 23:48
Linear regression with fminunc
x = [1000, 2000, 4000];
y = [200000, 250000, 300000];
% given a theta_0 and theta_1, this function calculates
% their cost. We don't need this function, strictly speaking...
% but it is nice to print out the costs as gradient descent iterates.
% We should see the cost go down every time the values of theta get updated.
function distance = cost(theta)
theta_0 = theta(1);
theta_1 = theta(2);
@egonSchiele
egonSchiele / phan_conditional.diff
Created March 11, 2016 02:15
Add a closure for conditionals to phan
diff --git a/src/Phan/Analysis/PreOrderAnalysisVisitor.php b/src/Phan/Analysis/PreOrderAnalysisVisitor.php
index 8650cd3..feaaee4 100644
--- a/src/Phan/Analysis/PreOrderAnalysisVisitor.php
+++ b/src/Phan/Analysis/PreOrderAnalysisVisitor.php
@@ -508,11 +508,16 @@ class PreOrderAnalysisVisitor extends ScopeVisitor
*/
public function visitIfElem(Node $node) : Context
{
+ $closure_fqsen =
+ FullyQualifiedFunctionName::fromClosureInContext(
@egonSchiele
egonSchiele / hfsslower.d
Created March 10, 2012 19:20
copy of Brenden Gregg's hfsslower.d
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option defaultargs
#pragma D option switchrate=10hz
/* from http://dtrace.org/blogs/brendan/2011/10/10/top-10-dtrace-scripts-for-mac-os-x/ */
dtrace:::BEGIN
{
@egonSchiele
egonSchiele / non_linear_classification.m
Created March 10, 2016 04:10
Non-linear classification example
% my training data.
% so if x > 3 || x < 7, y = 1, otherwise y = 0.
x = 1:100;
y = [0, 0, 0, 1, 1, 1, 1, zeros(1, 93)];
% instead of theta' * x, I'm trying to create
% a non-linear decision boundary.
% So instead of y = theta_0 + theta_1 * x, I use:
function result = h(x, theta)
result = sigmoid(theta(1) + theta(2) * x + theta(3) * ((x - theta(4))^2));