Skip to content

Instantly share code, notes, and snippets.

{
"workbench.iconTheme": "vscode-icons",
"editor.fontFamily": "'Sarasa Term SC', Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 16,
"terminal.integrated.fontFamily": "'SourceCodePro+Powerline+Awesome Regular','Sarasa Term SC',MesloLGS NF",
"terminal.integrated.fontSize": 14,
"workbench.colorCustomizations": {
"terminal.background": "#090300",
"terminal.foreground": "#A5A2A2",
"terminalCursor.background": "#A5A2A2",
@ProgramAlgo
ProgramAlgo / ODataJSONDateObjectToTimestamp.java
Created December 25, 2018 08:43
OData JSON Date Object to Timestamp
// OData json date string "/Date(1545727221)" to Timestamp
Pattern pattern = Pattern.compile("(\\d+)");
String onboardingDate = "/Date(1545727221)";
Matcher matcher = pattern.matcher( onboardingDate );
if (matcher.find()) {
String matched = matcher.group();
Timestamp dateToValidate = new Timestamp(Long.parseLong(matched));
}
@ProgramAlgo
ProgramAlgo / LastWeekMondaySunday.js
Last active December 14, 2018 07:03
Last Week Monday and Sunday Moment JavaScript
// http://momentjs.com/docs/#/get-set/day/
const lastMon = moment().day(-6).startOf('day').format('x');
const lastSun = moment().day(0).endOf('day').format('x');
const lastMon2 = moment().startOf('week').days(-6).format('x');
const lastSun2 = moment().startOf('week').format('x');
const arr = [];
function checkArr(val) {
console.log('checkval', val);
const i = arr.indexOf(val);
if (i !== -1) {
arr.splice(i, 1);
} else {
arr.push(val);
}
@ProgramAlgo
ProgramAlgo / settings.json
Last active February 27, 2018 08:32
VS Code setting file
// Place your settings in this file to overwrite the default settings
{
"editor.fontSize": 14,
"editor.fontFamily": "Sarasa Mono Sc, Inziu Iosevka SC, Menlo, Monaco, 'Courier New', monospace",
"editor.tabSize": 2,
"editor.renderControlCharacters": true,
"editor.renderWhitespace": "all",
"extensions.ignoreRecommendations": false,
"files.autoSave": "onFocusChange",
"window.zoomLevel": 0,
@ProgramAlgo
ProgramAlgo / remindbirthday.swift
Created December 25, 2017 03:01
remind birthday one month
func checkDates(birthdays: [Date], today: Date, days: Int) -> Set<Date> {
    let calendar = Calendar.current
    let thisYear = calendar.component(.year, from: today)
    var celebrateList = Set<Date>()
    var datesToCheck: ClosedRange<Date> {
        return today...today.addingTimeInterval(3600*24*Double(days))
    }
    
    for birthday in birthdays {
        var dateCompenents = calendar.dateComponents([.year, .month, .day], from: birthday)
@ProgramAlgo
ProgramAlgo / mail.mustache
Last active May 13, 2016 09:44
MFMailComposeViewController and mustache
{{#messagebodys}}
<p><a href= "{{href}}">{{linktext}}</a></p>
{{/messagebodys}}
@ProgramAlgo
ProgramAlgo / copyFile.swift
Last active April 20, 2016 07:25
swift copy file from BundleDirectory to DocumentDirectory
func copyFile() {
let manager = NSFileManager.defaultManager()
let bundlepath = NSBundle.mainBundle().resourcePath! + "/temp"
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask, true)
let docsDir: AnyObject = dirPaths[0]
do {
@ProgramAlgo
ProgramAlgo / rgb_color.swfit
Last active January 28, 2016 09:28
set navigationBar background color
navigationController!.navigationBar.barTintColor = UIColor(red:8/255, green:64/255 ,blue:164/255 , alpha:1.00)
@ProgramAlgo
ProgramAlgo / MustacheToWebView.swift
Last active January 28, 2016 07:40
Use Mustache.swift for UIWebView with swift
do {
// Load the `product_list.mustache` resource of the main bundle
let template = try Template(named: "product/product_list")
let bundlePath = NSBundle.mainBundle().bundlePath
let data = NSData(contentsOfFile: bundlePath + "/product/product_list.json")
let json: AnyObject = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)
// Convert to Dictionary: