Skip to content

Instantly share code, notes, and snippets.

View srghma's full-sized avatar

Serhii Khoma srghma.github.io/how-life-was-created srghma

View GitHub Profile
@nukturnal
nukturnal / audio_length.rb
Created January 18, 2010 22:54
Extracting audio length with Rails and ffmpeg
def self.get_audio_length(filepath)
pipe = "ffmpeg -i "+ filepath.to_s+" 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"
command = `#{pipe}`
if command =~ /([\d][\d]):([\d][\d]):([\d][\d]).([\d]+)/
#convert the result to only secs
duration = ($2.to_i * 60) + $3.to_i
end
#return and array containing the seconds and the human readable time length, ["6453","03:54"]
return "#{duration.to_s},#{$2}:#{$3}".split(",")
end
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=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')
@NicolasT
NicolasT / Primes.hs
Created August 1, 2011 14:14
Simple Haskell implementation of the Paillier homomorphic encryption scheme
{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
-- Stuff taken from the RSA module for now
module Primes where
import Data.Bits
import Data.Int
import Data.Word
import Data.ByteString.Lazy (ByteString)
@EspadaV8
EspadaV8 / gist:1357237
Created November 11, 2011 05:04
Script to import Geonames into PostgreSQL taken from http://forum.geonames.org/gforum/posts/list/15/926.page
#!/bin/bash
#===============================================================================
#
# FILE: getgeo.sh
#
# USAGE: ./getgeo.sh
#
# DESCRIPTION: run the script so that the geodata will be downloaded and inserted into your
# database
#
@m14t
m14t / fix_github_https_repo.sh
Created July 5, 2012 21:57
Convert HTTPS github clones to use SSH
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
@emk
emk / 1_front.html
Created August 22, 2012 15:16
Anki 2 cards with hidden transliterations on the front
<div class="signes">{{Signes H}}</div>
<input type="button" value="Translittération" onclick="document.getElementById('transliteration').className += ' shown'; this.style.display = 'none'; return false;">
<div id="transliteration" class="transliteration">{{Translittération}}</div>
@jewelsea
jewelsea / H2app.java
Created February 14, 2013 19:32
Sample for accessing a local database from JavaFX.
import java.sql.*;
import java.util.logging.*;
import javafx.application.Application;
import javafx.collections.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
@blakerego
blakerego / gist:5388897
Created April 15, 2013 15:23
haml-simple-form-datetime-bootstrap
= simple_form_for([:admin, @announcement]) do |f|
= f.error_notification
- current_profile = Profile.find_by_user_id(@current_user.id)
.form-inputs
= f.input :message, :required => true
= f.hidden_field :profile_id, :value => @current_user.primary_profile.id
= f.fields_for :TvScreen do |tv|
/// STARTS
= tv.input :starts_on, :placeholder => "MM/DD/YYYY", :input_html => {:class => "datepicker date-picker"}, :label => "Announcement starts on"
@ian29
ian29 / import-geonames.sh
Last active July 11, 2018 10:00
downloads, cleans and imports geonames to a postgres database. essentially an automated version of this: https://github.com/colemanm/gazetteer/blob/master/docs/geonames_postgis_import.md
#!/bin/bash
set -e -u
# Download and unzip data
wget http://download.geonames.org/export/dump/allCountries.zip
wget http://download.geonames.org/export/dump/alternateNames.zip
wget http://download.geonames.org/export/dump/countryInfo.txt
unzip allCountries.zip
unzip alternateNames.zip
@bigardone
bigardone / plugin.coffee
Created August 8, 2013 06:58
CoffeeScript jQuery plugin template
# Note that when compiling with coffeescript, the plugin is wrapped in another
# anonymous function. We do not need to pass in undefined as well, since
# coffeescript uses (void 0) instead.
do ($ = jQuery, window, document) ->
# window and document are passed through as local variable rather than global
# as this (slightly) quickens the resolution process and can be more efficiently
# minified (especially when both are regularly referenced in your plugin).
# Create the defaults once