This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def parse filename, content | |
| offset = 0 | |
| begin | |
| FasterCSV.parse(content) do |row| | |
| # do stuff | |
| offset += row.to_s.size | |
| end | |
| rescue FasterCSV::MalformedCSVError => e | |
| @file_offset ||= 0 | |
| @file_offset += offset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Location < ActiveRecord::Base | |
| has_many :foos | |
| acts_as_mappable default_units: :kms | |
| end | |
| class Foo < ActiveRecord::Base | |
| belongs_to :location | |
| acts_as_mappable through: :location | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| file = File.open("some_file.txt", "r") | |
| pos = file.size | |
| file.pos = pos | |
| while pos >= 0 | |
| if file.readchar == "\n" | |
| line = file.readline | |
| # do something with line | |
| end | |
| pos -= 2 | |
| file.pos = pos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(benchmark). | |
| -export([call_n_times/4]). | |
| call_n_times(N, Module, Function, Args) -> | |
| call_n_times([], N, Module, Function, Args). | |
| call_n_times(Data, 0, _, _, _) -> | |
| io:format("average: ~p us~n", [lists:sum(Data) / length(Data)]), | |
| io:format("fastest: ~p us~n", [lists:min(Data)]), | |
| io:format("slowest: ~p us~n", [lists:max(Data)]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(quicksort). | |
| -export([quicksort/2]). | |
| quicksort(List, SpawnFactor) when SpawnFactor > 0 -> | |
| Self = self(), | |
| Child = spawn(fun() -> quicksort(Self, List, SpawnFactor) end), | |
| receive | |
| {Child, SortedList} -> SortedList | |
| end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Vim color file | |
| " Maintainer: David Liang (bmdavll at gmail dot com) | |
| " Last Change: November 28 2008 | |
| " | |
| " wombat256.vim - a modified version of Wombat by Lars Nielsen that also | |
| " works on xterms with 88 or 256 colors. The algorithm for approximating the | |
| " GUI colors with the xterm palette is from desert256.vim by Henry So Jr. | |
| set background=dark |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # encoding: utf-8 | |
| require 'date' | |
| require 'curb' | |
| require 'nokogiri' | |
| begin | |
| curl = Curl::Easy.perform('http://mirror.fem-net.de/CCC/29C3/mp4-h264-HQ/') | |
| html = Nokogiri::HTML.parse(curl.body_str) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Calculates the German income tax from the taxable income ("zu versteuerndes | |
| # Einkommen"). Valid for 2010-2012. | |
| function est (zvE) | |
| if (zvE < 8005) | |
| 0 | |
| elseif (zvE < 13470) | |
| y = (zvE - 8004) / 10000; | |
| (912.17 * y + 1400) * y | |
| elseif (zvE < 52882) | |
| y = (zvE - 13469) / 10000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Maintainer: Helge Rausch <helge@rausch.io> | |
| # This script is licensed under the MIT license. | |
| # https://gist.github.com/tsujigiri/5476281 | |
| # | |
| ## Installation | |
| # | |
| # To install the Leap software, you first need to download the SDK for Linux | |
| # from https://developer.leapmotion.com/downloads/leap-motion/sdk using your | |
| # developer account. Unpack it, place the included .deb files in the same | |
| # directory as this PKGBUILD and run `makepkg`. If all goes well this will |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IO.popen("tail -F -n 0 #{path}") do |file| | |
| while true | |
| line = file.readline | |
| # do stuff with line | |
| end | |
| end |
OlderNewer