Skip to content

Instantly share code, notes, and snippets.

View linhmtran168's full-sized avatar
🦖

Linh M. Tran linhmtran168

🦖
View GitHub Profile
@linhmtran168
linhmtran168 / gist:2ec35dc3a78e3538fe58e97810aa1586
Created May 19, 2016 08:15 — forked from nim23/gist:d1c6852c37a3b3329677
IScroll 5 with DOM change detection

IScroll 5 with DOM change detection

When implementing a custom scrollbars there’s a need to detect changes in height of the element to which you are applying the scrollbars to, as the height of the scrollbars need to be adjusted based on the content’s height. We also need to take into account that the content could change and height needs to be recalculated i.e paging on queries could yield 10 results, whilst on the last page it could yield just 5 results, and these changes need to be accounted for by the scrollbar. And the same problem arises when getting content asynchronously, because whilst the content is empty on initial render it gets rendered only after successful fetch of the required data and we should calculate the scrollbar height once the content is available which is hard to determine as the operation is asynchornous.

Different libraries and plugins deal with the problem separately.

@linhmtran168
linhmtran168 / javascript_loader.js
Created March 29, 2016 09:36 — forked from hagenburger/javascript_loader.js
Dynamically load JavaScript files with callback when finished
// Example:
JavaScript.load("/javascripts/something.js");
// With callback (that’s the good thing):
JavaScript.load("http://www.someawesomedomain.com/api.js", function() {
API.use(); // or whatever api.js provides ...
});
@linhmtran168
linhmtran168 / after.sh
Last active March 23, 2016 14:36
Laravel Homestead setup script
#!/bin/sh
# If you would like to do some extra provisioning you may
# add any commands you wish to this file and they will
# be run after the Homestead machine is provisioned.
# Uupdate
sudo apt-get update
# Install some base packages
@linhmtran168
linhmtran168 / parser.awk
Created February 19, 2016 03:00
Awk to parse mecab result
BEGIN {
first_line=1;
idx=1;
max_words=100;
}
{
if (index($4,"名詞") == 1)
if (first_line == 1) {
printf "%s", toupper($1);
@linhmtran168
linhmtran168 / FizzBuzz.scala
Created January 22, 2016 20:35
FizzBuzz Scala
import java.io.IOException
import java.nio.file.{FileAlreadyExistsException, Files, Paths}
import scala.math.BigInt
/**
* Created by linhmtran on 1/23/16.
*/
object FizzBuzz extends App {
try {
#!/bin/sh
#
# unicorn_redmine Startup script for unicorn for redmine
#
# chkconfig: - 86 14
# processname: unicorn_rails
# pidfile: /opt/redmine/tmp/pids/unicorn.pid
# description: Rails application server for Redmine
#
### BEGIN INIT INFO
=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')

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@linhmtran168
linhmtran168 / 0_reuse_code.js
Created January 3, 2014 03:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@linhmtran168
linhmtran168 / pom.xml
Created December 4, 2013 04:50 — forked from codahale/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- none yet -->