Skip to content

Instantly share code, notes, and snippets.

View amuntasim's full-sized avatar

Muntasim Ahmed amuntasim

View GitHub Profile
@amuntasim
amuntasim / ruby_custom_flatten.rb
Created February 8, 2018 03:49
Custom flatten implementation in ruby
class FlattenTest
def self.custom_flatten(array, result = [])
array.each do |item|
if item.is_a? Array
custom_flatten(item, result)
else
result << item
end
end
result
@amuntasim
amuntasim / gist:d8ec7bcc1ac7447c9026c466cad7dc37
Last active May 2, 2017 14:20
call a javascript method at specific time
var triggered = false;
(function loop() {
var now = new Date();
// here the method will be triggered at 20:28, you can change them as per your need
if (!triggered && now.getHours() === 20 && now.getMinutes() === 28) {
method();
triggered = true;
}
console.log('Now: ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds());
##Create a migration
### rails g migration make_unicode_friendly
class MakeUnicodeFriendly < ActiveRecord::Migration
def change
alter_database_and_tables_charsets "utf8", "utf8_general_ci"
end
private
def alter_database_and_tables_charsets charset = default_charset, collation = default_collation
@amuntasim
amuntasim / gist:5804857
Created June 18, 2013 12:13
simple progress bar using jquery and css only
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>demo</title>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"> </script>
<style type="text/css">
#progressBar {
width: 400px;
height: 22px;
@amuntasim
amuntasim / gist:5697414
Last active December 18, 2015 00:29
How to embed mercury in new action without losing ability to use select fields or any other form fields. This form is the part of a gem 'HowTo', so edit this page as per your requirements
<!-- This section is important as it redirect to editor mode and handle form submition-->
<script type="text/javascript">
<% if rich_text_enabled && params[:rich_text_enabled].nil? %>
location.href = "<%= "/editor" + request.path + "?rich_text_enabled=1"%>"
<% end %>
jQuery(window).on('mercury:ready', function () {
$('#how_to_content_submit').on('click', function () {