Skip to content

Instantly share code, notes, and snippets.

<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
var e=document.getElementById("refreshed");
if(e.value=="no")e.value="yes";
else{e.value="no";location.reload();}
}
@lyonsun
lyonsun / overlay.css
Created December 15, 2014 09:28
create a div <div class="loading"></div>, apply the following style. CREDIT: http://codepen.io/MattIn4D/pen/LiKFC
/* Absolute Center CSS Spinner */
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
@lyonsun
lyonsun / line_end
Created November 21, 2014 05:52
set unix line endings in linux
To fix, open your script with vi or vim and enter in vi command mode (key ESC), then type this:
:set fileformat=unix
Finally save it
:x! or :wq!
@lyonsun
lyonsun / parse_json_file.go
Created October 23, 2014 13:21
get json from external json file using golang
/* credits: https://coderwall.com/p/8pklhg, by Ceane Lamerez - http://ceanelamerez.com */
/* example.json */
// {
// "key": "value",
// "greetings": "Hello World!"
// }
package main
@lyonsun
lyonsun / mamp-phpinfo.log
Created October 14, 2014 12:50
phpinfo() output of my MAMP environment
lyon:magento_dev Lyon$ phpmamp -i
phpinfo()
PHP Version => 5.5.10
System => Darwin lyon.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Build Date => Mar 18 2014 18:10:04
Configure Command => './configure' '--with-mysql=/Applications/MAMP/Library' '--with-gd' '--with-jpeg-dir=/Applications/MAMP/Library' '--with-png-dir=/Applications/MAMP/Library' '--with-zlib' '--with-zlib-dir=/Applications/MAMP/Library' '--with-freetype-dir=/Applications/MAMP/Library' '--prefix=/Applications/MAMP/bin/php/php5.5.10' '--exec-prefix=/Applications/MAMP/bin/php/php5.5.10' '--sysconfdir=/Applications/MAMP/bin/php/php5.5.10/conf' '--with-config-file-path=/Applications/MAMP/bin/php/php5.5.10/conf' '--enable-ftp' '--enable-gd-native-ttf' '--with-bz2=/usr' '--with-ldap' '--with-mysqli=/Applications/MAMP/Library/bin/mysql_config' '--with-t1lib=/Applications/MAMP/Library' '--enable-mbstring=all' '--with-curl=/Applications/MAMP/Library' '--enable-sockets' '--enable-b
@lyonsun
lyonsun / change_button_text.js
Created September 24, 2014 01:56
change button text in jQuery mobile
/**
* Credits: http://stackoverflow.com/a/9438023/861169
*/
// Since jQuery mobile generates HTML around your input type="button" element, and the text that you're seeing isn't actually value of the button, but a text inside of a generated span. You can either traverse the DOM looking for actual span, OR tell jQuery to re-generate button HTML by calling .button("refresh"), like so:
$("#MyButton").val("changed value");
$("#MyButton").button("refresh");
// The latter is recommended, since it will stay compatible with future versions of jQuery mobile, while traversing the DOM might break if jQuery team chooses to change structure of the HTML generated for the button.
@lyonsun
lyonsun / replace_a_line.php
Last active February 24, 2023 18:25
replace a particular line in a text file using php
<?php
// Credits:
// http://stackoverflow.com/questions/3004041/how-to-replace-a-particular-line-in-a-text-file-using-php
// http://stackoverflow.com/users/91914/gnarf
// One approach that you can use on smaller files that can fit into your memory twice:
$data = file('myfile'); // reads an array of lines
function replace_a_line($data) {
@lyonsun
lyonsun / run_cron
Created September 11, 2014 14:41
power shell script to schedule a task that send http get to a url on command line
schtasks /create /tn "MyAppDailyUpdate" /tr "powershell -ExecutionPolicy unrestricted -Command \"(New-Object Net.WebClient).DownloadString(\\\"http://localhost/cron.aspx\\\")\"" /sc DAILY /ru System
@lyonsun
lyonsun / preview.js
Created June 25, 2014 03:01
dummy js script to create a select dropdown list in a new window
$('#preview').bind('click', function(e) {
var minimum = parseInt($('#minimum').val());
var maximum = parseInt($('#maximum').val());
var interval = parseInt($('#interval').val());
var times = Math.floor(maximum/interval);
var html = '';
for (var i = 0; i < times; i++) {
@lyonsun
lyonsun / checkselect.html
Last active August 29, 2015 14:02
check if at least one option is selected in a multiple select element
<select id="mySelect" multiple="multiple">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
</select>
<script type="text/javascript">
$(document).ready(function() {
if (!$("#mySelect option:selected").length)