Skip to content

Instantly share code, notes, and snippets.

View envp's full-sized avatar

Vaibhav Yenamandra envp

View GitHub Profile
@envp
envp / lastdig.c
Created June 20, 2013 08:36
SPOJ Problem Set (classical) 3442. The last digit Problem code: LASTDIG http://www.spoj.com/problems/LASTDIG/
#include <stdio.h>
#include <math.h>
int main() {
int t, a, b, b2, b4, s, p;
scanf("%d", &t);
typedef double d;
while(t--) {
scanf("%d %d", &a, &b);
a %= 10;
b2 = (b>2)?b%2:b;
--->->>->++++++++++++++++++++++++++++>++>-->+>++
+++++>++>-->++++++++++++++++++>+++++++>+++++++++
++++++++++++>-->++++++++>+++++++++>++++++++++>++++++++>+++++
+>++++++++++++>++++++>+>+++++++>++++++++++>+++++>-->++++++++
+>++++++>++>->++++++++++++>++>+++++++++++++>-->++++++++>>+++
++++++++++>-->++++++++++++++>>+++++++++++>+>+++++++++
@envp
envp / gist:8117414
Created December 24, 2013 20:12
What it's supposed to look like
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'net/http'
class NokoLinkSet < Nokogiri::XML::NodeSet
# Create new LinkSet object from the url and the selector
def initialize(url, selector)
if not ( url.nil? and selector.nil? )
@raw_html = open(url)
README.ext
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v1_8_6/README.EXT?revision=12055
Extending Ruby - Pickaxe
http://ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html
Extending Ruby on O'Reilly
http://onlamp.com/pub/a/onlamp/2004/11/18/extending_ruby.html
Ruby C Extensions - Mark Volkman
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@envp
envp / buggy_breakout.c
Created April 15, 2015 18:55
This works but has a lot of stability issues and this wierd issue: http://a.pomf.se/sfpubq.gif
//
// breakout.c
//
// Computer Science 50
// Problem Set 3
//
// standard libraries
#define _XOPEN_SOURCE
#include <stdio.h>
@envp
envp / linear_equation_solver.rb
Last active December 23, 2015 06:38
A ridiculously simplified linear equation parser + sovler for systems of them, whipped up at work
require 'matrix'
module NumericUnicodeSubscripts
UNICODE_SUBSCRIPTS_0_TO_9 = [
"\u2080",
"\u2081",
"\u2082",
"\u2083",
"\u2084",
"\u2085",
Pending: (Failures listed here are expected and do not affect your suite's status)
1) Distribution::Uniform singleton it should behave like uniform engine .rng should generate sequences with the right mean & variance
# This method is very innacurrate due to the low convergence rate
# ./spec/uniform_spec.rb:8
2) Distribution::Uniform Distribution::Uniform::Ruby_ it should behave like uniform engine .rng should generate sequences with the right mean & variance
# This method is very innacurrate due to the low convergence rate
# ./spec/uniform_spec.rb:8
@envp
envp / goodnes_of_fit.rb
Last active January 20, 2016 10:44
Untested stuff. Does chi-squared tests. Has a lot of ad-hack stuff. This implements a pearson's chi squared test. Others to follow soon
module GoodnessOfFit
# All goodness of fit helpers go here
## Pearson's chi squared test for goodness of fit
# == References
# * http://stattrek.com/chi-square-test/goodness-of-fit.aspx?Tutorial=AP
# * https://en.wikipedia.org/wiki/Degrees_of_freedom_(statistics)#Residuals
#
# The null hypothesis is always that the +candidate+ does belong to
# the +target+ distribution.
@envp
envp / rb_rand_entropy.rb
Last active January 25, 2016 06:05
Finding the entropy for Ruby's random method as a measure of it's randomness
def rb_rand_entropy(num_trials)
a = Array.new(num_trials) {rand(100)}
p = []
0.upto(99) do |i|
p[i] = a.count(i) / num_trials.to_f
end
return p.map {|c| -c * Math.log(c)}.reduce(:+)
end